| 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 <deque> |
| 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 ~QuotaFileIO(); |
| 35 |
| 36 // Performs write or setlength operation with quota checks. |
| 37 // Returns true when the operation is successfully dispatched. |
| 38 // |callback| will be dispatched when the operation completes. |
| 39 // Otherwise it returns false and |callback| will not be dispatched. |
| 40 // |callback| will not be dispatched either when this instance is |
| 41 // destroyed before the operation completes. |
| 42 // SetLength/WillSetLength cannot be called while there're any inflight |
| 43 // operations. For Write/WillWrite it is guaranteed that |callback| are |
| 44 // always dispatched in the same order as Write being called. |
| 45 bool Write(int64_t offset, |
| 46 const char* buffer, |
| 47 int32_t bytes_to_write, |
| 48 WriteCallback* callback); |
| 49 bool WillWrite(int64_t offset, |
| 50 int32_t bytes_to_write, |
| 51 WriteCallback* callback); |
| 52 |
| 53 bool SetLength(int64_t length, StatusCallback* callback); |
| 54 bool WillSetLength(int64_t length, StatusCallback* callback); |
| 55 |
| 56 private: |
| 57 class PendingOperationBase; |
| 58 class WriteOperation; |
| 59 class SetLengthOperation; |
| 60 |
| 61 bool CheckIfExceedsQuota(int64_t new_file_size) const; |
| 62 void WillUpdate(); |
| 63 void DidWrite(WriteOperation* op, int64_t written_offset_end); |
| 64 void DidSetLength(base::PlatformFileError error, int64_t new_file_size); |
| 65 |
| 66 bool RegisterOperationForQuotaChecks(PendingOperationBase* op); |
| 67 void DidQueryInfoForQuota(base::PlatformFileError error_code, |
| 68 const base::PlatformFileInfo& file_info); |
| 69 void DidQueryAvailableSpace(int64_t avail_space); |
| 70 void DidQueryForQuotaCheck(); |
| 71 |
| 72 // The plugin instance that owns this (via PPB_FileIO_Impl). |
| 73 PluginInstance* instance_; |
| 74 |
| 75 // The file information associated to this instance. |
| 76 base::PlatformFile file_; |
| 77 GURL file_url_; |
| 78 quota::StorageType storage_type_; |
| 79 |
| 80 // Operations waiting for a quota check to finish. |
| 81 std::deque<PendingOperationBase*> pending_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 // For parallel writes bookkeeping. |
| 92 int64_t max_written_offset_; |
| 93 int inflight_operations_; |
| 94 |
| 95 base::ScopedCallbackFactory<QuotaFileIO> callback_factory_; |
| 96 DISALLOW_COPY_AND_ASSIGN(QuotaFileIO); |
| 97 }; |
| 98 |
| 99 } // namespace ppapi |
| 100 } // namespace webkit |
| 101 |
| 102 #endif // WEBKIT_PLUGINS_PPAPI_QUOTA_FILE_IO_H_ |
| OLD | NEW |