OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 WEBKIT_BROWSER_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_ |
6 #define WEBKIT_BROWSER_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_ |
7 | 7 |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
12 #include "webkit/browser/fileapi/file_stream_writer.h" | 12 #include "storage/browser/fileapi/file_stream_writer.h" |
13 #include "webkit/browser/fileapi/file_system_url.h" | 13 #include "storage/browser/fileapi/file_system_url.h" |
14 #include "webkit/browser/fileapi/task_runner_bound_observer_list.h" | 14 #include "storage/browser/fileapi/task_runner_bound_observer_list.h" |
15 #include "webkit/browser/webkit_storage_browser_export.h" | 15 #include "storage/common/storage_export.h" |
16 #include "webkit/common/blob/shareable_file_reference.h" | 16 #include "storage/common/blob/shareable_file_reference.h" |
17 #include "webkit/common/fileapi/file_system_types.h" | 17 #include "storage/common/fileapi/file_system_types.h" |
18 #include "webkit/common/quota/quota_types.h" | 18 #include "storage/common/quota/quota_types.h" |
19 | 19 |
20 namespace fileapi { | 20 namespace storage { |
21 | 21 |
22 class FileSystemContext; | 22 class FileSystemContext; |
23 class FileSystemQuotaUtil; | 23 class FileSystemQuotaUtil; |
24 class FileStreamWriter; | 24 class FileStreamWriter; |
25 | 25 |
26 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE SandboxFileStreamWriter | 26 class STORAGE_EXPORT_PRIVATE SandboxFileStreamWriter |
27 : public NON_EXPORTED_BASE(FileStreamWriter) { | 27 : public NON_EXPORTED_BASE(FileStreamWriter) { |
28 public: | 28 public: |
29 SandboxFileStreamWriter(FileSystemContext* file_system_context, | 29 SandboxFileStreamWriter(FileSystemContext* file_system_context, |
30 const FileSystemURL& url, | 30 const FileSystemURL& url, |
31 int64 initial_offset, | 31 int64 initial_offset, |
32 const UpdateObserverList& observers); | 32 const UpdateObserverList& observers); |
33 virtual ~SandboxFileStreamWriter(); | 33 virtual ~SandboxFileStreamWriter(); |
34 | 34 |
35 // FileStreamWriter overrides. | 35 // FileStreamWriter overrides. |
36 virtual int Write(net::IOBuffer* buf, int buf_len, | 36 virtual int Write(net::IOBuffer* buf, |
| 37 int buf_len, |
37 const net::CompletionCallback& callback) OVERRIDE; | 38 const net::CompletionCallback& callback) OVERRIDE; |
38 virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE; | 39 virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE; |
39 virtual int Flush(const net::CompletionCallback& callback) OVERRIDE; | 40 virtual int Flush(const net::CompletionCallback& callback) OVERRIDE; |
40 | 41 |
41 // Used only by tests. | 42 // Used only by tests. |
42 void set_default_quota(int64 quota) { | 43 void set_default_quota(int64 quota) { default_quota_ = quota; } |
43 default_quota_ = quota; | |
44 } | |
45 | 44 |
46 private: | 45 private: |
47 // Performs quota calculation and calls local_file_writer_->Write(). | 46 // Performs quota calculation and calls local_file_writer_->Write(). |
48 int WriteInternal(net::IOBuffer* buf, int buf_len, | 47 int WriteInternal(net::IOBuffer* buf, |
| 48 int buf_len, |
49 const net::CompletionCallback& callback); | 49 const net::CompletionCallback& callback); |
50 | 50 |
51 // Callbacks that are chained for the first write. This eventually calls | 51 // Callbacks that are chained for the first write. This eventually calls |
52 // WriteInternal. | 52 // WriteInternal. |
53 void DidCreateSnapshotFile( | 53 void DidCreateSnapshotFile( |
54 const net::CompletionCallback& callback, | 54 const net::CompletionCallback& callback, |
55 base::File::Error file_error, | 55 base::File::Error file_error, |
56 const base::File::Info& file_info, | 56 const base::File::Info& file_info, |
57 const base::FilePath& platform_path, | 57 const base::FilePath& platform_path, |
58 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | 58 const scoped_refptr<storage::ShareableFileReference>& file_ref); |
59 void DidGetUsageAndQuota(const net::CompletionCallback& callback, | 59 void DidGetUsageAndQuota(const net::CompletionCallback& callback, |
60 quota::QuotaStatusCode status, | 60 quota::QuotaStatusCode status, |
61 int64 usage, int64 quota); | 61 int64 usage, |
62 void DidInitializeForWrite(net::IOBuffer* buf, int buf_len, | 62 int64 quota); |
| 63 void DidInitializeForWrite(net::IOBuffer* buf, |
| 64 int buf_len, |
63 const net::CompletionCallback& callback, | 65 const net::CompletionCallback& callback, |
64 int init_status); | 66 int init_status); |
65 | 67 |
66 void DidWrite(const net::CompletionCallback& callback, int write_response); | 68 void DidWrite(const net::CompletionCallback& callback, int write_response); |
67 | 69 |
68 // Stops the in-flight operation, calls |cancel_callback_| and returns true | 70 // Stops the in-flight operation, calls |cancel_callback_| and returns true |
69 // if there's a pending cancel request. | 71 // if there's a pending cancel request. |
70 bool CancelIfRequested(); | 72 bool CancelIfRequested(); |
71 | 73 |
72 scoped_refptr<FileSystemContext> file_system_context_; | 74 scoped_refptr<FileSystemContext> file_system_context_; |
(...skipping 10 matching lines...) Expand all Loading... |
83 int64 allowed_bytes_to_write_; | 85 int64 allowed_bytes_to_write_; |
84 bool has_pending_operation_; | 86 bool has_pending_operation_; |
85 | 87 |
86 int64 default_quota_; | 88 int64 default_quota_; |
87 | 89 |
88 base::WeakPtrFactory<SandboxFileStreamWriter> weak_factory_; | 90 base::WeakPtrFactory<SandboxFileStreamWriter> weak_factory_; |
89 | 91 |
90 DISALLOW_COPY_AND_ASSIGN(SandboxFileStreamWriter); | 92 DISALLOW_COPY_AND_ASSIGN(SandboxFileStreamWriter); |
91 }; | 93 }; |
92 | 94 |
93 } // namespace fileapi | 95 } // namespace storage |
94 | 96 |
95 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_ | 97 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_FILE_STREAM_WRITER_H_ |
OLD | NEW |