Commit 68698531 authored by Zhuoyu Qian's avatar Zhuoyu Qian Committed by Commit Bot

Rename enum class file_error::ErrorCode to FileErrorCode

This CL rename the enum class to FileErrorCode and move it out of the
namespace file_error.

Change-Id: I39ee10e35bbdcf0b3b0efdda159e21b255e477b1
Reviewed-on: https://chromium-review.googlesource.com/c/1328628Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609619}
parent 57d5d1dc
...@@ -72,33 +72,33 @@ const char kTypeMismatchErrorMessage[] = ...@@ -72,33 +72,33 @@ const char kTypeMismatchErrorMessage[] =
namespace { namespace {
DOMExceptionCode ErrorCodeToExceptionCode(ErrorCode code) { DOMExceptionCode ErrorCodeToExceptionCode(FileErrorCode code) {
switch (code) { switch (code) {
case ErrorCode::kOK: case FileErrorCode::kOK:
return DOMExceptionCode::kNoError; return DOMExceptionCode::kNoError;
case ErrorCode::kNotFoundErr: case FileErrorCode::kNotFoundErr:
return DOMExceptionCode::kNotFoundError; return DOMExceptionCode::kNotFoundError;
case ErrorCode::kSecurityErr: case FileErrorCode::kSecurityErr:
return DOMExceptionCode::kSecurityError; return DOMExceptionCode::kSecurityError;
case ErrorCode::kAbortErr: case FileErrorCode::kAbortErr:
return DOMExceptionCode::kAbortError; return DOMExceptionCode::kAbortError;
case ErrorCode::kNotReadableErr: case FileErrorCode::kNotReadableErr:
return DOMExceptionCode::kNotReadableError; return DOMExceptionCode::kNotReadableError;
case ErrorCode::kEncodingErr: case FileErrorCode::kEncodingErr:
return DOMExceptionCode::kEncodingError; return DOMExceptionCode::kEncodingError;
case ErrorCode::kNoModificationAllowedErr: case FileErrorCode::kNoModificationAllowedErr:
return DOMExceptionCode::kNoModificationAllowedError; return DOMExceptionCode::kNoModificationAllowedError;
case ErrorCode::kInvalidStateErr: case FileErrorCode::kInvalidStateErr:
return DOMExceptionCode::kInvalidStateError; return DOMExceptionCode::kInvalidStateError;
case ErrorCode::kSyntaxErr: case FileErrorCode::kSyntaxErr:
return DOMExceptionCode::kSyntaxError; return DOMExceptionCode::kSyntaxError;
case ErrorCode::kInvalidModificationErr: case FileErrorCode::kInvalidModificationErr:
return DOMExceptionCode::kInvalidModificationError; return DOMExceptionCode::kInvalidModificationError;
case ErrorCode::kQuotaExceededErr: case FileErrorCode::kQuotaExceededErr:
return DOMExceptionCode::kQuotaExceededError; return DOMExceptionCode::kQuotaExceededError;
case ErrorCode::kTypeMismatchErr: case FileErrorCode::kTypeMismatchErr:
return DOMExceptionCode::kTypeMismatchError; return DOMExceptionCode::kTypeMismatchError;
case ErrorCode::kPathExistsErr: case FileErrorCode::kPathExistsErr:
return DOMExceptionCode::kPathExistsError; return DOMExceptionCode::kPathExistsError;
default: default:
NOTREACHED(); NOTREACHED();
...@@ -106,35 +106,35 @@ DOMExceptionCode ErrorCodeToExceptionCode(ErrorCode code) { ...@@ -106,35 +106,35 @@ DOMExceptionCode ErrorCodeToExceptionCode(ErrorCode code) {
} }
} }
const char* ErrorCodeToMessage(ErrorCode code) { const char* ErrorCodeToMessage(FileErrorCode code) {
// Note that some of these do not set message. If message is 0 then the // Note that some of these do not set message. If message is 0 then the
// default message is used. // default message is used.
switch (code) { switch (code) {
case ErrorCode::kOK: case FileErrorCode::kOK:
return nullptr; return nullptr;
case ErrorCode::kSecurityErr: case FileErrorCode::kSecurityErr:
return kSecurityErrorMessage; return kSecurityErrorMessage;
case ErrorCode::kNotFoundErr: case FileErrorCode::kNotFoundErr:
return kNotFoundErrorMessage; return kNotFoundErrorMessage;
case ErrorCode::kAbortErr: case FileErrorCode::kAbortErr:
return kAbortErrorMessage; return kAbortErrorMessage;
case ErrorCode::kNotReadableErr: case FileErrorCode::kNotReadableErr:
return kNotReadableErrorMessage; return kNotReadableErrorMessage;
case ErrorCode::kEncodingErr: case FileErrorCode::kEncodingErr:
return kEncodingErrorMessage; return kEncodingErrorMessage;
case ErrorCode::kNoModificationAllowedErr: case FileErrorCode::kNoModificationAllowedErr:
return kNoModificationAllowedErrorMessage; return kNoModificationAllowedErrorMessage;
case ErrorCode::kInvalidStateErr: case FileErrorCode::kInvalidStateErr:
return kInvalidStateErrorMessage; return kInvalidStateErrorMessage;
case ErrorCode::kSyntaxErr: case FileErrorCode::kSyntaxErr:
return kSyntaxErrorMessage; return kSyntaxErrorMessage;
case ErrorCode::kInvalidModificationErr: case FileErrorCode::kInvalidModificationErr:
return nullptr; return nullptr;
case ErrorCode::kQuotaExceededErr: case FileErrorCode::kQuotaExceededErr:
return kQuotaExceededErrorMessage; return kQuotaExceededErrorMessage;
case ErrorCode::kTypeMismatchErr: case FileErrorCode::kTypeMismatchErr:
return nullptr; return nullptr;
case ErrorCode::kPathExistsErr: case FileErrorCode::kPathExistsErr:
return kPathExistsErrorMessage; return kPathExistsErrorMessage;
default: default:
NOTREACHED(); NOTREACHED();
...@@ -229,14 +229,14 @@ const char* FileErrorToMessage(base::File::Error code) { ...@@ -229,14 +229,14 @@ const char* FileErrorToMessage(base::File::Error code) {
} // namespace } // namespace
void ThrowDOMException(ExceptionState& exception_state, void ThrowDOMException(ExceptionState& exception_state,
ErrorCode code, FileErrorCode code,
String message) { String message) {
if (code == ErrorCode::kOK) if (code == FileErrorCode::kOK)
return; return;
// SecurityError is special-cased, as we want to route those exceptions // SecurityError is special-cased, as we want to route those exceptions
// through ExceptionState::ThrowSecurityError. // through ExceptionState::ThrowSecurityError.
if (code == ErrorCode::kSecurityErr) { if (code == FileErrorCode::kSecurityErr) {
exception_state.ThrowSecurityError(kSecurityErrorMessage); exception_state.ThrowSecurityError(kSecurityErrorMessage);
return; return;
} }
...@@ -268,8 +268,8 @@ void ThrowDOMException(ExceptionState& exception_state, ...@@ -268,8 +268,8 @@ void ThrowDOMException(ExceptionState& exception_state,
exception_state.ThrowDOMException(FileErrorToExceptionCode(error), message); exception_state.ThrowDOMException(FileErrorToExceptionCode(error), message);
} }
DOMException* CreateDOMException(ErrorCode code) { DOMException* CreateDOMException(FileErrorCode code) {
DCHECK_NE(code, ErrorCode::kOK); DCHECK_NE(code, FileErrorCode::kOK);
return DOMException::Create(ErrorCodeToExceptionCode(code), return DOMException::Create(ErrorCodeToExceptionCode(code),
ErrorCodeToMessage(code)); ErrorCodeToMessage(code));
} }
......
...@@ -40,9 +40,7 @@ namespace blink { ...@@ -40,9 +40,7 @@ namespace blink {
class DOMException; class DOMException;
class ExceptionState; class ExceptionState;
namespace file_error { enum class FileErrorCode {
enum class ErrorCode {
kOK = 0, kOK = 0,
kNotFoundErr = 1, kNotFoundErr = 1,
kSecurityErr = 2, kSecurityErr = 2,
...@@ -58,6 +56,8 @@ enum class ErrorCode { ...@@ -58,6 +56,8 @@ enum class ErrorCode {
kPathExistsErr = 12, kPathExistsErr = 12,
}; };
namespace file_error {
CORE_EXPORT extern const char kAbortErrorMessage[]; CORE_EXPORT extern const char kAbortErrorMessage[];
CORE_EXPORT extern const char kEncodingErrorMessage[]; CORE_EXPORT extern const char kEncodingErrorMessage[];
CORE_EXPORT extern const char kInvalidStateErrorMessage[]; CORE_EXPORT extern const char kInvalidStateErrorMessage[];
...@@ -71,12 +71,12 @@ CORE_EXPORT extern const char kSyntaxErrorMessage[]; ...@@ -71,12 +71,12 @@ CORE_EXPORT extern const char kSyntaxErrorMessage[];
CORE_EXPORT extern const char kTypeMismatchErrorMessage[]; CORE_EXPORT extern const char kTypeMismatchErrorMessage[];
CORE_EXPORT void ThrowDOMException(ExceptionState&, CORE_EXPORT void ThrowDOMException(ExceptionState&,
ErrorCode, FileErrorCode,
String message = String()); String message = String());
CORE_EXPORT void ThrowDOMException(ExceptionState& exception_state, CORE_EXPORT void ThrowDOMException(ExceptionState& exception_state,
base::File::Error error, base::File::Error error,
String message = String()); String message = String());
CORE_EXPORT DOMException* CreateDOMException(ErrorCode); CORE_EXPORT DOMException* CreateDOMException(FileErrorCode);
CORE_EXPORT DOMException* CreateDOMException(base::File::Error); CORE_EXPORT DOMException* CreateDOMException(base::File::Error);
} // namespace file_error } // namespace file_error
......
...@@ -338,7 +338,7 @@ void FileReader::abort() { ...@@ -338,7 +338,7 @@ void FileReader::abort() {
base::AutoReset<bool> firing_events(&still_firing_events_, true); base::AutoReset<bool> firing_events(&still_firing_events_, true);
// Setting error implicitly makes |result| return null. // Setting error implicitly makes |result| return null.
error_ = file_error::CreateDOMException(file_error::ErrorCode::kAbortErr); error_ = file_error::CreateDOMException(FileErrorCode::kAbortErr);
// Unregister the reader. // Unregister the reader.
ThrottlingController::FinishReaderType final_step = ThrottlingController::FinishReaderType final_step =
...@@ -432,7 +432,7 @@ void FileReader::DidFinishLoading() { ...@@ -432,7 +432,7 @@ void FileReader::DidFinishLoading() {
ThrottlingController::FinishReader(GetExecutionContext(), this, final_step); ThrottlingController::FinishReader(GetExecutionContext(), this, final_step);
} }
void FileReader::DidFail(file_error::ErrorCode error_code) { void FileReader::DidFail(FileErrorCode error_code) {
if (loading_state_ == kLoadingStateAborted) if (loading_state_ == kLoadingStateAborted)
return; return;
......
...@@ -43,13 +43,10 @@ ...@@ -43,13 +43,10 @@
namespace blink { namespace blink {
namespace file_error {
enum class ErrorCode;
}
class Blob; class Blob;
class ExceptionState; class ExceptionState;
class ExecutionContext; class ExecutionContext;
enum class FileErrorCode;
class StringOrArrayBuffer; class StringOrArrayBuffer;
class CORE_EXPORT FileReader final : public EventTargetWithInlineData, class CORE_EXPORT FileReader final : public EventTargetWithInlineData,
...@@ -93,7 +90,7 @@ class CORE_EXPORT FileReader final : public EventTargetWithInlineData, ...@@ -93,7 +90,7 @@ class CORE_EXPORT FileReader final : public EventTargetWithInlineData,
void DidStartLoading() override; void DidStartLoading() override;
void DidReceiveData() override; void DidReceiveData() override;
void DidFinishLoading() override; void DidFinishLoading() override;
void DidFail(file_error::ErrorCode) override; void DidFail(FileErrorCode) override;
DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart, kLoadstart); DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart, kLoadstart);
DEFINE_ATTRIBUTE_EVENT_LISTENER(progress, kProgress); DEFINE_ATTRIBUTE_EVENT_LISTENER(progress, kProgress);
......
...@@ -100,8 +100,7 @@ void FileReaderLoader::Start(scoped_refptr<BlobDataHandle> blob_data) { ...@@ -100,8 +100,7 @@ void FileReaderLoader::Start(scoped_refptr<BlobDataHandle> blob_data) {
mojo::ScopedDataPipeProducerHandle producer_handle; mojo::ScopedDataPipeProducerHandle producer_handle;
MojoResult rv = CreateDataPipe(&options, &producer_handle, &consumer_handle_); MojoResult rv = CreateDataPipe(&options, &producer_handle, &consumer_handle_);
if (rv != MOJO_RESULT_OK) { if (rv != MOJO_RESULT_OK) {
Failed(file_error::ErrorCode::kNotReadableErr, Failed(FileErrorCode::kNotReadableErr, FailureType::kMojoPipeCreation);
FailureType::kMojoPipeCreation);
return; return;
} }
...@@ -116,7 +115,7 @@ void FileReaderLoader::Start(scoped_refptr<BlobDataHandle> blob_data) { ...@@ -116,7 +115,7 @@ void FileReaderLoader::Start(scoped_refptr<BlobDataHandle> blob_data) {
if (received_on_complete_) if (received_on_complete_)
return; return;
if (!received_all_data_) { if (!received_all_data_) {
Failed(file_error::ErrorCode::kNotReadableErr, Failed(FileErrorCode::kNotReadableErr,
FailureType::kSyncDataNotAllLoaded); FailureType::kSyncDataNotAllLoaded);
return; return;
} }
...@@ -124,14 +123,14 @@ void FileReaderLoader::Start(scoped_refptr<BlobDataHandle> blob_data) { ...@@ -124,14 +123,14 @@ void FileReaderLoader::Start(scoped_refptr<BlobDataHandle> blob_data) {
// Wait for OnComplete // Wait for OnComplete
binding_.WaitForIncomingMethodCall(); binding_.WaitForIncomingMethodCall();
if (!received_on_complete_) { if (!received_on_complete_) {
Failed(file_error::ErrorCode::kNotReadableErr, Failed(FileErrorCode::kNotReadableErr,
FailureType::kSyncOnCompleteNotReceived); FailureType::kSyncOnCompleteNotReceived);
} }
} }
} }
void FileReaderLoader::Cancel() { void FileReaderLoader::Cancel() {
error_code_ = file_error::ErrorCode::kAbortErr; error_code_ = FileErrorCode::kAbortErr;
Cleanup(); Cleanup();
} }
...@@ -141,7 +140,7 @@ DOMArrayBuffer* FileReaderLoader::ArrayBufferResult() { ...@@ -141,7 +140,7 @@ DOMArrayBuffer* FileReaderLoader::ArrayBufferResult() {
return array_buffer_result_; return array_buffer_result_;
// If the loading is not started or an error occurs, return an empty result. // If the loading is not started or an error occurs, return an empty result.
if (!raw_data_ || error_code_ != file_error::ErrorCode::kOK) if (!raw_data_ || error_code_ != FileErrorCode::kOK)
return nullptr; return nullptr;
DOMArrayBuffer* result = DOMArrayBuffer::Create(raw_data_->ToArrayBuffer()); DOMArrayBuffer* result = DOMArrayBuffer::Create(raw_data_->ToArrayBuffer());
...@@ -158,7 +157,7 @@ String FileReaderLoader::StringResult() { ...@@ -158,7 +157,7 @@ String FileReaderLoader::StringResult() {
DCHECK_NE(read_type_, kReadAsArrayBuffer); DCHECK_NE(read_type_, kReadAsArrayBuffer);
DCHECK_NE(read_type_, kReadByClient); DCHECK_NE(read_type_, kReadByClient);
if (!raw_data_ || (error_code_ != file_error::ErrorCode::kOK) || if (!raw_data_ || (error_code_ != FileErrorCode::kOK) ||
is_raw_data_converted_) { is_raw_data_converted_) {
return string_result_; return string_result_;
} }
...@@ -201,7 +200,7 @@ void FileReaderLoader::Cleanup() { ...@@ -201,7 +200,7 @@ void FileReaderLoader::Cleanup() {
consumer_handle_.reset(); consumer_handle_.reset();
// If we get any error, we do not need to keep a buffer around. // If we get any error, we do not need to keep a buffer around.
if (error_code_ != file_error::ErrorCode::kOK) { if (error_code_ != FileErrorCode::kOK) {
raw_data_.reset(); raw_data_.reset();
string_result_ = ""; string_result_ = "";
is_raw_data_converted_ = true; is_raw_data_converted_ = true;
...@@ -211,13 +210,12 @@ void FileReaderLoader::Cleanup() { ...@@ -211,13 +210,12 @@ void FileReaderLoader::Cleanup() {
} }
} }
void FileReaderLoader::Failed(file_error::ErrorCode error_code, void FileReaderLoader::Failed(FileErrorCode error_code, FailureType type) {
FailureType type) {
DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, failure_histogram, DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, failure_histogram,
("Storage.Blob.FileReaderLoader.FailureType", ("Storage.Blob.FileReaderLoader.FailureType",
static_cast<int>(FailureType::kCount))); static_cast<int>(FailureType::kCount)));
// If an error was already reported, don't report this error again. // If an error was already reported, don't report this error again.
if (error_code_ != file_error::ErrorCode::kOK) if (error_code_ != FileErrorCode::kOK)
return; return;
error_code_ = error_code; error_code_ = error_code;
failure_histogram.Count(static_cast<int>(type)); failure_histogram.Count(static_cast<int>(type));
...@@ -236,14 +234,13 @@ void FileReaderLoader::OnStartLoading(uint64_t total_bytes) { ...@@ -236,14 +234,13 @@ void FileReaderLoader::OnStartLoading(uint64_t total_bytes) {
// so to call ArrayBuffer's create function. // so to call ArrayBuffer's create function.
// FIXME: Support reading more than the current size limit of ArrayBuffer. // FIXME: Support reading more than the current size limit of ArrayBuffer.
if (total_bytes > std::numeric_limits<unsigned>::max()) { if (total_bytes > std::numeric_limits<unsigned>::max()) {
Failed(file_error::ErrorCode::kNotReadableErr, Failed(FileErrorCode::kNotReadableErr, FailureType::kTotalBytesTooLarge);
FailureType::kTotalBytesTooLarge);
return; return;
} }
raw_data_ = std::make_unique<ArrayBufferBuilder>(total_bytes); raw_data_ = std::make_unique<ArrayBufferBuilder>(total_bytes);
if (!raw_data_->IsValid()) { if (!raw_data_->IsValid()) {
Failed(file_error::ErrorCode::kNotReadableErr, Failed(FileErrorCode::kNotReadableErr,
FailureType::kArrayBufferBuilderCreation); FailureType::kArrayBufferBuilderCreation);
return; return;
} }
...@@ -258,7 +255,7 @@ void FileReaderLoader::OnReceivedData(const char* data, unsigned data_length) { ...@@ -258,7 +255,7 @@ void FileReaderLoader::OnReceivedData(const char* data, unsigned data_length) {
DCHECK(data); DCHECK(data);
// Bail out if we already encountered an error. // Bail out if we already encountered an error.
if (error_code_ != file_error::ErrorCode::kOK) if (error_code_ != FileErrorCode::kOK)
return; return;
if (read_type_ == kReadByClient) { if (read_type_ == kReadByClient) {
...@@ -273,7 +270,7 @@ void FileReaderLoader::OnReceivedData(const char* data, unsigned data_length) { ...@@ -273,7 +270,7 @@ void FileReaderLoader::OnReceivedData(const char* data, unsigned data_length) {
if (!bytes_appended) { if (!bytes_appended) {
raw_data_.reset(); raw_data_.reset();
bytes_loaded_ = 0; bytes_loaded_ = 0;
Failed(file_error::ErrorCode::kNotReadableErr, Failed(FileErrorCode::kNotReadableErr,
FailureType::kArrayBufferBuilderAppend); FailureType::kArrayBufferBuilderAppend);
return; return;
} }
...@@ -329,15 +326,13 @@ void FileReaderLoader::OnComplete(int32_t status, uint64_t data_length) { ...@@ -329,15 +326,13 @@ void FileReaderLoader::OnComplete(int32_t status, uint64_t data_length) {
if (status != net::OK) { if (status != net::OK) {
net_error_ = status; net_error_ = status;
file_reader_loader_read_errors_histogram.Sample(std::max(0, -net_error_)); file_reader_loader_read_errors_histogram.Sample(std::max(0, -net_error_));
Failed(status == net::ERR_FILE_NOT_FOUND Failed(status == net::ERR_FILE_NOT_FOUND ? FileErrorCode::kNotFoundErr
? file_error::ErrorCode::kNotFoundErr : FileErrorCode::kNotReadableErr,
: file_error::ErrorCode::kNotReadableErr,
FailureType::kBackendReadError); FailureType::kBackendReadError);
return; return;
} }
if (data_length != total_bytes_) { if (data_length != total_bytes_) {
Failed(file_error::ErrorCode::kNotReadableErr, Failed(FileErrorCode::kNotReadableErr, FailureType::kReadSizesIncorrect);
FailureType::kReadSizesIncorrect);
return; return;
} }
...@@ -349,7 +344,7 @@ void FileReaderLoader::OnComplete(int32_t status, uint64_t data_length) { ...@@ -349,7 +344,7 @@ void FileReaderLoader::OnComplete(int32_t status, uint64_t data_length) {
void FileReaderLoader::OnDataPipeReadable(MojoResult result) { void FileReaderLoader::OnDataPipeReadable(MojoResult result) {
if (result != MOJO_RESULT_OK) { if (result != MOJO_RESULT_OK) {
if (!received_all_data_) { if (!received_all_data_) {
Failed(file_error::ErrorCode::kNotReadableErr, Failed(FileErrorCode::kNotReadableErr,
FailureType::kDataPipeNotReadableWithBytesLeft); FailureType::kDataPipeNotReadableWithBytesLeft);
} }
return; return;
...@@ -371,13 +366,13 @@ void FileReaderLoader::OnDataPipeReadable(MojoResult result) { ...@@ -371,13 +366,13 @@ void FileReaderLoader::OnDataPipeReadable(MojoResult result) {
if (result == MOJO_RESULT_FAILED_PRECONDITION) { if (result == MOJO_RESULT_FAILED_PRECONDITION) {
// Pipe closed. // Pipe closed.
if (!received_all_data_) { if (!received_all_data_) {
Failed(file_error::ErrorCode::kNotReadableErr, Failed(FileErrorCode::kNotReadableErr,
FailureType::kMojoPipeClosedEarly); FailureType::kMojoPipeClosedEarly);
} }
return; return;
} }
if (result != MOJO_RESULT_OK) { if (result != MOJO_RESULT_OK) {
Failed(file_error::ErrorCode::kNotReadableErr, Failed(FileErrorCode::kNotReadableErr,
FailureType::kMojoPipeUnexpectedReadError); FailureType::kMojoPipeUnexpectedReadError);
return; return;
} }
......
...@@ -97,7 +97,7 @@ class CORE_EXPORT FileReaderLoader : public mojom::blink::BlobReaderClient { ...@@ -97,7 +97,7 @@ class CORE_EXPORT FileReaderLoader : public mojom::blink::BlobReaderClient {
// After OnCalculatedSize() is called: Returns the size of the resource. // After OnCalculatedSize() is called: Returns the size of the resource.
base::Optional<uint64_t> TotalBytes() const { return total_bytes_; } base::Optional<uint64_t> TotalBytes() const { return total_bytes_; }
file_error::ErrorCode GetErrorCode() const { return error_code_; } FileErrorCode GetErrorCode() const { return error_code_; }
int32_t GetNetError() const { return net_error_; } int32_t GetNetError() const { return net_error_; }
...@@ -128,7 +128,7 @@ class CORE_EXPORT FileReaderLoader : public mojom::blink::BlobReaderClient { ...@@ -128,7 +128,7 @@ class CORE_EXPORT FileReaderLoader : public mojom::blink::BlobReaderClient {
}; };
void Cleanup(); void Cleanup();
void Failed(file_error::ErrorCode, FailureType type); void Failed(FileErrorCode, FailureType type);
void OnStartLoading(uint64_t total_bytes); void OnStartLoading(uint64_t total_bytes);
void OnReceivedData(const char* data, unsigned data_length); void OnReceivedData(const char* data, unsigned data_length);
...@@ -172,7 +172,7 @@ class CORE_EXPORT FileReaderLoader : public mojom::blink::BlobReaderClient { ...@@ -172,7 +172,7 @@ class CORE_EXPORT FileReaderLoader : public mojom::blink::BlobReaderClient {
int64_t memory_usage_reported_to_v8_ = 0; int64_t memory_usage_reported_to_v8_ = 0;
int32_t net_error_ = 0; // net::OK int32_t net_error_ = 0; // net::OK
file_error::ErrorCode error_code_ = file_error::ErrorCode::kOK; FileErrorCode error_code_ = FileErrorCode::kOK;
mojo::ScopedDataPipeConsumerHandle consumer_handle_; mojo::ScopedDataPipeConsumerHandle consumer_handle_;
mojo::SimpleWatcher handle_watcher_; mojo::SimpleWatcher handle_watcher_;
......
...@@ -36,9 +36,7 @@ ...@@ -36,9 +36,7 @@
namespace blink { namespace blink {
namespace file_error { enum class FileErrorCode;
enum class ErrorCode;
}
class CORE_EXPORT FileReaderLoaderClient { class CORE_EXPORT FileReaderLoaderClient {
public: public:
...@@ -54,7 +52,7 @@ class CORE_EXPORT FileReaderLoaderClient { ...@@ -54,7 +52,7 @@ class CORE_EXPORT FileReaderLoaderClient {
NOTREACHED(); NOTREACHED();
} }
virtual void DidFinishLoading() = 0; virtual void DidFinishLoading() = 0;
virtual void DidFail(file_error::ErrorCode) = 0; virtual void DidFail(FileErrorCode) = 0;
}; };
} // namespace blink } // namespace blink
......
...@@ -116,7 +116,7 @@ void FileReaderSync::StartLoading(FileReaderLoader& loader, ...@@ -116,7 +116,7 @@ void FileReaderSync::StartLoading(FileReaderLoader& loader,
const Blob& blob, const Blob& blob,
ExceptionState& exception_state) { ExceptionState& exception_state) {
loader.Start(blob.GetBlobDataHandle()); loader.Start(blob.GetBlobDataHandle());
if (loader.GetErrorCode() != file_error::ErrorCode::kOK) if (loader.GetErrorCode() != FileErrorCode::kOK)
file_error::ThrowDOMException(exception_state, loader.GetErrorCode()); file_error::ThrowDOMException(exception_state, loader.GetErrorCode());
} }
......
...@@ -291,7 +291,7 @@ void ImageBitmapFactories::ImageBitmapLoader::DidFinishLoading() { ...@@ -291,7 +291,7 @@ void ImageBitmapFactories::ImageBitmapLoader::DidFinishLoading() {
ScheduleAsyncImageBitmapDecoding(array_buffer); ScheduleAsyncImageBitmapDecoding(array_buffer);
} }
void ImageBitmapFactories::ImageBitmapLoader::DidFail(file_error::ErrorCode) { void ImageBitmapFactories::ImageBitmapLoader::DidFail(FileErrorCode) {
RejectPromise(kUndecodableImageBitmapRejectionReason); RejectPromise(kUndecodableImageBitmapRejectionReason);
} }
......
...@@ -145,7 +145,7 @@ class ImageBitmapFactories final ...@@ -145,7 +145,7 @@ class ImageBitmapFactories final
void DidStartLoading() override {} void DidStartLoading() override {}
void DidReceiveData() override {} void DidReceiveData() override {}
void DidFinishLoading() override; void DidFinishLoading() override;
void DidFail(file_error::ErrorCode) override; void DidFail(FileErrorCode) override;
std::unique_ptr<FileReaderLoader> loader_; std::unique_ptr<FileReaderLoader> loader_;
Member<ImageBitmapFactories> factory_; Member<ImageBitmapFactories> factory_;
......
...@@ -186,7 +186,7 @@ class InspectorFileReaderLoaderClient final : public FileReaderLoaderClient { ...@@ -186,7 +186,7 @@ class InspectorFileReaderLoaderClient final : public FileReaderLoaderClient {
void DidFinishLoading() override { Done(raw_data_); } void DidFinishLoading() override { Done(raw_data_); }
void DidFail(file_error::ErrorCode) override { Done(nullptr); } void DidFail(FileErrorCode) override { Done(nullptr); }
private: private:
void Done(scoped_refptr<SharedBuffer> output) { void Done(scoped_refptr<SharedBuffer> output) {
......
...@@ -239,9 +239,7 @@ class XMLHttpRequest::BlobLoader final ...@@ -239,9 +239,7 @@ class XMLHttpRequest::BlobLoader final
xhr_->DidReceiveData(data, length); xhr_->DidReceiveData(data, length);
} }
void DidFinishLoading() override { xhr_->DidFinishLoadingFromBlob(); } void DidFinishLoading() override { xhr_->DidFinishLoadingFromBlob(); }
void DidFail(file_error::ErrorCode error) override { void DidFail(FileErrorCode error) override { xhr_->DidFailLoadingFromBlob(); }
xhr_->DidFailLoadingFromBlob();
}
void Cancel() { loader_->Cancel(); } void Cancel() { loader_->Cancel(); }
......
...@@ -395,7 +395,7 @@ class CachedResponseFileReaderLoaderClient final ...@@ -395,7 +395,7 @@ class CachedResponseFileReaderLoaderClient final
dispose(); dispose();
} }
void DidFail(file_error::ErrorCode error) override { void DidFail(FileErrorCode error) override {
callback_->sendFailure(ProtocolResponse::Error(String::Format( callback_->sendFailure(ProtocolResponse::Error(String::Format(
"Unable to read the cached response, error code: %d", error))); "Unable to read the cached response, error code: %d", error)));
dispose(); dispose();
......
...@@ -84,11 +84,11 @@ void FileWriter::write(Blob* data, ExceptionState& exception_state) { ...@@ -84,11 +84,11 @@ void FileWriter::write(Blob* data, ExceptionState& exception_state) {
DCHECK(data); DCHECK(data);
DCHECK_EQ(truncate_length_, -1); DCHECK_EQ(truncate_length_, -1);
if (ready_state_ == kWriting) { if (ready_state_ == kWriting) {
SetError(file_error::ErrorCode::kInvalidStateErr, exception_state); SetError(FileErrorCode::kInvalidStateErr, exception_state);
return; return;
} }
if (recursion_depth_ > kMaxRecursionDepth) { if (recursion_depth_ > kMaxRecursionDepth) {
SetError(file_error::ErrorCode::kSecurityErr, exception_state); SetError(FileErrorCode::kSecurityErr, exception_state);
return; return;
} }
...@@ -112,7 +112,7 @@ void FileWriter::seek(long long position, ExceptionState& exception_state) { ...@@ -112,7 +112,7 @@ void FileWriter::seek(long long position, ExceptionState& exception_state) {
if (!GetExecutionContext()) if (!GetExecutionContext())
return; return;
if (ready_state_ == kWriting) { if (ready_state_ == kWriting) {
SetError(file_error::ErrorCode::kInvalidStateErr, exception_state); SetError(FileErrorCode::kInvalidStateErr, exception_state);
return; return;
} }
...@@ -126,11 +126,11 @@ void FileWriter::truncate(long long position, ExceptionState& exception_state) { ...@@ -126,11 +126,11 @@ void FileWriter::truncate(long long position, ExceptionState& exception_state) {
return; return;
DCHECK_EQ(truncate_length_, -1); DCHECK_EQ(truncate_length_, -1);
if (ready_state_ == kWriting || position < 0) { if (ready_state_ == kWriting || position < 0) {
SetError(file_error::ErrorCode::kInvalidStateErr, exception_state); SetError(FileErrorCode::kInvalidStateErr, exception_state);
return; return;
} }
if (recursion_depth_ > kMaxRecursionDepth) { if (recursion_depth_ > kMaxRecursionDepth) {
SetError(file_error::ErrorCode::kSecurityErr, exception_state); SetError(FileErrorCode::kSecurityErr, exception_state);
return; return;
} }
...@@ -318,9 +318,9 @@ void FileWriter::FireEvent(const AtomicString& type) { ...@@ -318,9 +318,9 @@ void FileWriter::FireEvent(const AtomicString& type) {
DCHECK_GE(recursion_depth_, 0); DCHECK_GE(recursion_depth_, 0);
} }
void FileWriter::SetError(file_error::ErrorCode error_code, void FileWriter::SetError(FileErrorCode error_code,
ExceptionState& exception_state) { ExceptionState& exception_state) {
DCHECK_NE(error_code, file_error::ErrorCode::kOK); DCHECK_NE(error_code, FileErrorCode::kOK);
file_error::ThrowDOMException(exception_state, error_code); file_error::ThrowDOMException(exception_state, error_code);
error_ = file_error::CreateDOMException(error_code); error_ = file_error::CreateDOMException(error_code);
} }
......
...@@ -40,14 +40,11 @@ ...@@ -40,14 +40,11 @@
namespace blink { namespace blink {
namespace file_error {
enum class ErrorCode;
}
class Blob; class Blob;
class DOMException; class DOMException;
class ExceptionState; class ExceptionState;
class ExecutionContext; class ExecutionContext;
enum class FileErrorCode;
class FileWriter final : public EventTargetWithInlineData, class FileWriter final : public EventTargetWithInlineData,
public FileWriterBase, public FileWriterBase,
...@@ -119,7 +116,7 @@ class FileWriter final : public EventTargetWithInlineData, ...@@ -119,7 +116,7 @@ class FileWriter final : public EventTargetWithInlineData,
void FireEvent(const AtomicString& type); void FireEvent(const AtomicString& type);
void SetError(file_error::ErrorCode, ExceptionState&); void SetError(FileErrorCode, ExceptionState&);
void Dispose(); void Dispose();
......
...@@ -106,7 +106,7 @@ void IDBRequestLoader::DidFinishLoading() { ...@@ -106,7 +106,7 @@ void IDBRequestLoader::DidFinishLoading() {
StartNextValue(); StartNextValue();
} }
void IDBRequestLoader::DidFail(file_error::ErrorCode) { void IDBRequestLoader::DidFail(FileErrorCode) {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
DCHECK(started_) DCHECK(started_)
<< "FileReaderLoader called DidFail() before it was Start()ed"; << "FileReaderLoader called DidFail() before it was Start()ed";
......
...@@ -52,7 +52,7 @@ class IDBRequestLoader : public FileReaderLoaderClient { ...@@ -52,7 +52,7 @@ class IDBRequestLoader : public FileReaderLoaderClient {
void DidStartLoading() override; void DidStartLoading() override;
void DidReceiveDataForClient(const char* data, unsigned data_length) override; void DidReceiveDataForClient(const char* data, unsigned data_length) override;
void DidFinishLoading() override; void DidFinishLoading() override;
void DidFail(file_error::ErrorCode) override; void DidFail(FileErrorCode) override;
private: private:
// Starts unwrapping the next wrapped IDBValue. // Starts unwrapping the next wrapped IDBValue.
......
...@@ -137,7 +137,7 @@ class PresentationConnection::BlobLoader final ...@@ -137,7 +137,7 @@ class PresentationConnection::BlobLoader final
presentation_connection_->DidFinishLoadingBlob( presentation_connection_->DidFinishLoadingBlob(
loader_->ArrayBufferResult()); loader_->ArrayBufferResult());
} }
void DidFail(file_error::ErrorCode error_code) override { void DidFail(FileErrorCode error_code) override {
presentation_connection_->DidFailLoadingBlob(error_code); presentation_connection_->DidFailLoadingBlob(error_code);
} }
...@@ -609,8 +609,7 @@ void PresentationConnection::DidFinishLoadingBlob(DOMArrayBuffer* buffer) { ...@@ -609,8 +609,7 @@ void PresentationConnection::DidFinishLoadingBlob(DOMArrayBuffer* buffer) {
HandleMessageQueue(); HandleMessageQueue();
} }
void PresentationConnection::DidFailLoadingBlob( void PresentationConnection::DidFailLoadingBlob(FileErrorCode error_code) {
file_error::ErrorCode error_code) {
DCHECK(!messages_.IsEmpty()); DCHECK(!messages_.IsEmpty());
DCHECK_EQ(messages_.front()->type, kMessageTypeBlob); DCHECK_EQ(messages_.front()->type, kMessageTypeBlob);
// FIXME: generate error message? // FIXME: generate error message?
......
...@@ -22,12 +22,9 @@ class AtomicString; ...@@ -22,12 +22,9 @@ class AtomicString;
namespace blink { namespace blink {
namespace file_error {
enum class ErrorCode;
}
class DOMArrayBuffer; class DOMArrayBuffer;
class DOMArrayBufferView; class DOMArrayBufferView;
enum class FileErrorCode;
class PresentationController; class PresentationController;
class PresentationReceiver; class PresentationReceiver;
class PresentationRequest; class PresentationRequest;
...@@ -134,7 +131,7 @@ class PresentationConnection : public EventTargetWithInlineData, ...@@ -134,7 +131,7 @@ class PresentationConnection : public EventTargetWithInlineData,
// Callbacks invoked from BlobLoader. // Callbacks invoked from BlobLoader.
void DidFinishLoadingBlob(DOMArrayBuffer*); void DidFinishLoadingBlob(DOMArrayBuffer*);
void DidFailLoadingBlob(file_error::ErrorCode); void DidFailLoadingBlob(FileErrorCode);
void SendMessageToTargetConnection( void SendMessageToTargetConnection(
mojom::blink::PresentationConnectionMessagePtr); mojom::blink::PresentationConnectionMessagePtr);
......
...@@ -89,7 +89,7 @@ class WebSocketChannelImpl::BlobLoader final ...@@ -89,7 +89,7 @@ class WebSocketChannelImpl::BlobLoader final
void DidStartLoading() override {} void DidStartLoading() override {}
void DidReceiveData() override {} void DidReceiveData() override {}
void DidFinishLoading() override; void DidFinishLoading() override;
void DidFail(file_error::ErrorCode) override; void DidFail(FileErrorCode) override;
void Trace(blink::Visitor* visitor) { visitor->Trace(channel_); } void Trace(blink::Visitor* visitor) { visitor->Trace(channel_); }
...@@ -140,8 +140,7 @@ void WebSocketChannelImpl::BlobLoader::DidFinishLoading() { ...@@ -140,8 +140,7 @@ void WebSocketChannelImpl::BlobLoader::DidFinishLoading() {
loader_ = nullptr; loader_ = nullptr;
} }
void WebSocketChannelImpl::BlobLoader::DidFail( void WebSocketChannelImpl::BlobLoader::DidFail(FileErrorCode error_code) {
file_error::ErrorCode error_code) {
channel_->DidFailLoadingBlob(error_code); channel_->DidFailLoadingBlob(error_code);
loader_ = nullptr; loader_ = nullptr;
} }
...@@ -767,10 +766,9 @@ void WebSocketChannelImpl::DidFinishLoadingBlob(DOMArrayBuffer* buffer) { ...@@ -767,10 +766,9 @@ void WebSocketChannelImpl::DidFinishLoadingBlob(DOMArrayBuffer* buffer) {
ProcessSendQueue(); ProcessSendQueue();
} }
void WebSocketChannelImpl::DidFailLoadingBlob( void WebSocketChannelImpl::DidFailLoadingBlob(FileErrorCode error_code) {
file_error::ErrorCode error_code) {
blob_loader_.Clear(); blob_loader_.Clear();
if (error_code == file_error::ErrorCode::kAbortErr) { if (error_code == FileErrorCode::kAbortErr) {
// The error is caused by cancel(). // The error is caused by cancel().
return; return;
} }
......
...@@ -54,11 +54,8 @@ ...@@ -54,11 +54,8 @@
namespace blink { namespace blink {
namespace file_error {
enum class ErrorCode;
}
class BaseFetchContext; class BaseFetchContext;
enum class FileErrorCode;
class WebSocketChannelClient; class WebSocketChannelClient;
class WebSocketHandshakeThrottle; class WebSocketHandshakeThrottle;
...@@ -180,7 +177,7 @@ class MODULES_EXPORT WebSocketChannelImpl final ...@@ -180,7 +177,7 @@ class MODULES_EXPORT WebSocketChannelImpl final
// Methods for BlobLoader. // Methods for BlobLoader.
void DidFinishLoadingBlob(DOMArrayBuffer*); void DidFinishLoadingBlob(DOMArrayBuffer*);
void DidFailLoadingBlob(file_error::ErrorCode); void DidFailLoadingBlob(FileErrorCode);
void TearDownFailedConnection(); void TearDownFailedConnection();
bool ShouldDisallowConnection(const KURL&); bool ShouldDisallowConnection(const KURL&);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment