Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / child / fileapi / webfilewriter_base.h
blob7371e6364eb056bba2770ba2b3782940af7d9743
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_
6 #define CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_
8 #include "base/files/file.h"
9 #include "content/common/content_export.h"
10 #include "third_party/WebKit/public/platform/WebFileWriter.h"
11 #include "url/gurl.h"
13 namespace blink {
14 class WebFileWriterClient;
15 class WebURL;
18 namespace content {
20 class CONTENT_EXPORT WebFileWriterBase
21 : public NON_EXPORTED_BASE(blink::WebFileWriter) {
22 public:
23 WebFileWriterBase(const GURL& path, blink::WebFileWriterClient* client);
24 virtual ~WebFileWriterBase();
26 // WebFileWriter implementation
27 virtual void truncate(long long length);
28 virtual void write(long long position, const blink::WebString& id);
29 virtual void cancel();
31 protected:
32 // This calls DidSucceed() or DidFail() based on the value of |error_code|.
33 void DidFinish(base::File::Error error_code);
35 void DidWrite(int64 bytes, bool complete);
36 void DidSucceed();
37 void DidFail(base::File::Error error_code);
39 // Derived classes must provide these methods to asynchronously perform
40 // the requested operation, and they must call the appropiate DidSomething
41 // method upon completion and as progress is made in the Write case.
42 virtual void DoTruncate(const GURL& path, int64 offset) = 0;
43 virtual void DoWrite(const GURL& path,
44 const std::string& blob_id,
45 int64 offset) = 0;
46 virtual void DoCancel() = 0;
48 private:
49 enum OperationType {
50 kOperationNone,
51 kOperationWrite,
52 kOperationTruncate
55 enum CancelState {
56 kCancelNotInProgress,
57 kCancelSent,
58 kCancelReceivedWriteResponse,
61 void FinishCancel();
63 GURL path_;
64 blink::WebFileWriterClient* client_;
65 OperationType operation_;
66 CancelState cancel_state_;
69 } // namespace content
71 #endif // CONTENT_CHILD_FILEAPI_WEBFILEWRITER_BASE_H_