Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_FILEAPI_SANDBOX_FILE_WRITER_H_ | |
| 6 #define WEBKIT_FILEAPI_SANDBOX_FILE_WRITER_H_ | |
| 7 | |
| 8 #include "base/file_path.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/platform_file.h" | |
| 11 #include "googleurl/src/gurl.h" | |
| 12 #include "webkit/fileapi/file_system_types.h" | |
| 13 #include "webkit/fileapi/file_writer.h" | |
| 14 #include "webkit/quota/quota_types.h" | |
| 15 | |
| 16 namespace fileapi { | |
| 17 | |
| 18 class FileSystemContext; | |
| 19 class FileSystemQuotaUtil; | |
| 20 class LocalFileWriter; | |
| 21 | |
| 22 class SandboxFileWriter : public FileWriter { | |
|
ericu
2012/05/16 00:23:17
Side note: FileWriter is a really confusing name f
kinuko
2012/05/16 04:10:12
Right, but we also have duplicated FileReader, Fil
ericu
2012/05/17 00:04:13
That's a great list of names to fix. I think it's
kinuko
2012/05/17 04:45:26
Filed a new bug. Either we change the name immedia
| |
| 23 public: | |
| 24 SandboxFileWriter(FileSystemContext* file_system_context, | |
| 25 const GURL& url, | |
| 26 int64 initial_offset); | |
| 27 virtual ~SandboxFileWriter(); | |
| 28 | |
| 29 // FileWriter overrides. | |
| 30 virtual int Write(net::IOBuffer* buf, int buf_len, | |
| 31 const net::CompletionCallback& callback) OVERRIDE; | |
| 32 virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE; | |
| 33 | |
| 34 // Used only by tests. | |
| 35 void set_default_quota(int64 quota) { | |
| 36 default_quota_ = quota; | |
| 37 } | |
| 38 | |
| 39 private: | |
| 40 // Performs quota calculation and calls local_file_writer_->Write(). | |
| 41 int WriteInternal(net::IOBuffer* buf, int buf_len, | |
| 42 const net::CompletionCallback& callback); | |
| 43 | |
| 44 // Callbacks that are chained for the first write. This eventually calls | |
| 45 // WriteInternal. | |
| 46 void DidGetFileInfo(const net::CompletionCallback& callback, | |
| 47 base::PlatformFileError file_error, | |
| 48 const base::PlatformFileInfo& file_info, | |
| 49 const FilePath& platform_path); | |
| 50 void DidGetUsageAndQuota(const net::CompletionCallback& callback, | |
| 51 quota::QuotaStatusCode status, | |
| 52 int64 usage, int64 quota); | |
| 53 void DidInitializeForWrite(net::IOBuffer* buf, int buf_len, | |
| 54 const net::CompletionCallback& callback, | |
| 55 int init_status); | |
| 56 | |
| 57 void DidWrite(const net::CompletionCallback& callback, int write_response); | |
| 58 | |
| 59 // Stops the in-flight operation, calls |cancel_callback_| and returns true | |
| 60 // if there's a pending cancel request. | |
| 61 bool CancelIfRequested(); | |
| 62 | |
| 63 FileSystemQuotaUtil* quota_util() const; | |
| 64 | |
| 65 scoped_refptr<FileSystemContext> file_system_context_; | |
| 66 const GURL url_; | |
| 67 int64 initial_offset_; | |
| 68 scoped_ptr<LocalFileWriter> local_file_writer_; | |
| 69 net::CompletionCallback cancel_callback_; | |
| 70 | |
| 71 GURL origin_; | |
| 72 FileSystemType file_system_type_; | |
| 73 FilePath virtual_path_; | |
| 74 | |
| 75 FilePath file_path_; | |
| 76 int64 file_size_; | |
| 77 int64 total_bytes_written_; | |
| 78 int64 allowed_bytes_to_write_; | |
| 79 bool has_pending_operation_; | |
| 80 | |
| 81 int64 default_quota_; | |
| 82 | |
| 83 base::WeakPtrFactory<SandboxFileWriter> weak_factory_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(SandboxFileWriter); | |
| 86 }; | |
| 87 | |
| 88 } // namespace fileapi | |
| 89 | |
| 90 #endif // WEBKIT_FILEAPI_SANDBOX_FILE_WRITER_H_ | |
| OLD | NEW |