| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_ | 5 #ifndef CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_ |
| 6 #define CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_ | 6 #define CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 9 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 10 #include "third_party/WebKit/public/platform/WebFileWriter.h" | 12 #include "third_party/WebKit/public/platform/WebFileWriter.h" |
| 11 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 12 | 14 |
| 13 namespace blink { | 15 namespace blink { |
| 14 class WebFileWriterClient; | 16 class WebFileWriterClient; |
| 15 class WebURL; | 17 class WebURL; |
| 16 } | 18 } |
| 17 | 19 |
| 18 namespace content { | 20 namespace content { |
| 19 | 21 |
| 20 class CONTENT_EXPORT WebFileWriterBase | 22 class CONTENT_EXPORT WebFileWriterBase |
| 21 : public NON_EXPORTED_BASE(blink::WebFileWriter) { | 23 : public NON_EXPORTED_BASE(blink::WebFileWriter) { |
| 22 public: | 24 public: |
| 23 WebFileWriterBase(const GURL& path, blink::WebFileWriterClient* client); | 25 WebFileWriterBase(const GURL& path, blink::WebFileWriterClient* client); |
| 24 ~WebFileWriterBase() override; | 26 ~WebFileWriterBase() override; |
| 25 | 27 |
| 26 // WebFileWriter implementation | 28 // WebFileWriter implementation |
| 27 void truncate(long long length) override; | 29 void truncate(long long length) override; |
| 28 void write(long long position, const blink::WebString& id) override; | 30 void write(long long position, const blink::WebString& id) override; |
| 29 void cancel() override; | 31 void cancel() override; |
| 30 | 32 |
| 31 protected: | 33 protected: |
| 32 // This calls DidSucceed() or DidFail() based on the value of |error_code|. | 34 // This calls DidSucceed() or DidFail() based on the value of |error_code|. |
| 33 void DidFinish(base::File::Error error_code); | 35 void DidFinish(base::File::Error error_code); |
| 34 | 36 |
| 35 void DidWrite(int64 bytes, bool complete); | 37 void DidWrite(int64_t bytes, bool complete); |
| 36 void DidSucceed(); | 38 void DidSucceed(); |
| 37 void DidFail(base::File::Error error_code); | 39 void DidFail(base::File::Error error_code); |
| 38 | 40 |
| 39 // Derived classes must provide these methods to asynchronously perform | 41 // Derived classes must provide these methods to asynchronously perform |
| 40 // the requested operation, and they must call the appropiate DidSomething | 42 // the requested operation, and they must call the appropiate DidSomething |
| 41 // method upon completion and as progress is made in the Write case. | 43 // method upon completion and as progress is made in the Write case. |
| 42 virtual void DoTruncate(const GURL& path, int64 offset) = 0; | 44 virtual void DoTruncate(const GURL& path, int64_t offset) = 0; |
| 43 virtual void DoWrite(const GURL& path, | 45 virtual void DoWrite(const GURL& path, |
| 44 const std::string& blob_id, | 46 const std::string& blob_id, |
| 45 int64 offset) = 0; | 47 int64_t offset) = 0; |
| 46 virtual void DoCancel() = 0; | 48 virtual void DoCancel() = 0; |
| 47 | 49 |
| 48 private: | 50 private: |
| 49 enum OperationType { | 51 enum OperationType { |
| 50 kOperationNone, | 52 kOperationNone, |
| 51 kOperationWrite, | 53 kOperationWrite, |
| 52 kOperationTruncate | 54 kOperationTruncate |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 enum CancelState { | 57 enum CancelState { |
| 56 kCancelNotInProgress, | 58 kCancelNotInProgress, |
| 57 kCancelSent, | 59 kCancelSent, |
| 58 kCancelReceivedWriteResponse, | 60 kCancelReceivedWriteResponse, |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 void FinishCancel(); | 63 void FinishCancel(); |
| 62 | 64 |
| 63 GURL path_; | 65 GURL path_; |
| 64 blink::WebFileWriterClient* client_; | 66 blink::WebFileWriterClient* client_; |
| 65 OperationType operation_; | 67 OperationType operation_; |
| 66 CancelState cancel_state_; | 68 CancelState cancel_state_; |
| 67 }; | 69 }; |
| 68 | 70 |
| 69 } // namespace content | 71 } // namespace content |
| 70 | 72 |
| 71 #endif // CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_ | 73 #endif // CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_ |
| OLD | NEW |