Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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_PLUGINS_PPAPI_QUOTA_FILE_IO_H_ | |
| 6 #define WEBKIT_PLUGINS_PPAPI_QUOTA_FILE_IO_H_ | |
| 7 | |
| 8 #include <queue> | |
| 9 | |
| 10 #include "base/file_util_proxy.h" | |
| 11 #include "base/memory/scoped_callback_factory.h" | |
| 12 #include "base/platform_file.h" | |
| 13 #include "googleurl/src/gurl.h" | |
| 14 #include "ppapi/c/pp_file_info.h" | |
| 15 #include "webkit/quota/quota_types.h" | |
| 16 | |
| 17 namespace webkit { | |
| 18 namespace ppapi { | |
| 19 | |
| 20 class PluginInstance; | |
| 21 | |
| 22 // This class is created per PPB_FileIO_Impl instance and provides | |
| 23 // write operations for quota-managed files (i.e. files of | |
| 24 // PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}). | |
| 25 class QuotaFileIO { | |
| 26 public: | |
| 27 typedef base::FileUtilProxy::WriteCallback WriteCallback; | |
| 28 typedef base::FileUtilProxy::StatusCallback StatusCallback; | |
| 29 | |
| 30 QuotaFileIO(PluginInstance* instance, | |
| 31 base::PlatformFile file, | |
| 32 const GURL& path_url, | |
| 33 PP_FileSystemType type); | |
| 34 virtual ~QuotaFileIO(); | |
|
yzshen1
2011/07/26 19:26:44
virtual is not necessary.
kinuko
2011/07/27 09:33:14
Done.
| |
| 35 | |
| 36 bool Write(int64_t offset, | |
| 37 const char* buffer, | |
| 38 int32_t bytes_to_write, | |
| 39 WriteCallback* callback); | |
| 40 bool SetLength(int64_t length, StatusCallback* callback); | |
| 41 bool WillWrite(int64_t offset, | |
| 42 int32_t bytes_to_write, | |
| 43 WriteCallback* callback); | |
| 44 bool WillSetLength(int64_t length, StatusCallback* callback); | |
| 45 | |
| 46 private: | |
| 47 class PendingOperationBase; | |
| 48 class WriteOperation; | |
| 49 class SetLengthOperation; | |
| 50 | |
| 51 bool CheckIfExceedsQuota(int64_t new_file_size) const; | |
| 52 void WillUpdate(); | |
| 53 void DidWrite(int64_t written_offset_end); | |
| 54 void DidSetLength(int64_t new_file_size); | |
| 55 | |
| 56 bool RegisterOperationForQuotaChecks(PendingOperationBase* op); | |
| 57 void DidQueryInfoForQuota(base::PlatformFileError error_code, | |
| 58 const base::PlatformFileInfo& file_info); | |
| 59 void DidQueryAvailableSpace(int64_t avail_space); | |
| 60 void DidQueryForQuotaCheck(); | |
| 61 | |
| 62 // For internal bookkeeping. All live pending operations are registered | |
| 63 // so that we can abort/delete them in destructor. | |
| 64 void RegisterOperation(PendingOperationBase* op); | |
| 65 void UnregisterOperation(PendingOperationBase* op); | |
| 66 | |
| 67 // The plugin instance that owns this (via PPB_FileIO_Impl). | |
| 68 PluginInstance* instance_; | |
| 69 | |
| 70 // The file information associated to this instance. | |
| 71 base::PlatformFile file_; | |
| 72 GURL file_url_; | |
| 73 quota::StorageType storage_type_; | |
| 74 | |
| 75 // Operations waiting for a quota check to finish. | |
| 76 std::queue<PendingOperationBase*> pending_operations_; | |
| 77 | |
| 78 // All registered operations including pending ones. Kept separately | |
| 79 // from pending operations so that we can make sure we delete them when | |
| 80 // this instance goes away. | |
| 81 std::set<PendingOperationBase*> registered_operations_; | |
| 82 | |
| 83 // Valid only while there're pending quota checks. | |
| 84 int64_t cached_file_size_; | |
| 85 int64_t cached_available_space_; | |
| 86 | |
| 87 // Quota-related queries and errors occured during inflight quota checks. | |
| 88 int outstanding_quota_queries_; | |
| 89 int outstanding_errors_; | |
| 90 | |
| 91 bool did_notify_will_update_; | |
| 92 int64_t max_written_offset_; | |
| 93 | |
| 94 base::ScopedCallbackFactory<QuotaFileIO> callback_factory_; | |
| 95 DISALLOW_COPY_AND_ASSIGN(QuotaFileIO); | |
| 96 }; | |
| 97 | |
| 98 } // namespace ppapi | |
| 99 } // namespace webkit | |
| 100 | |
| 101 #endif // WEBKIT_PLUGINS_PPAPI_QUOTA_FILE_IO_H_ | |
| OLD | NEW |