Chromium Code Reviews| Index: webkit/plugins/ppapi/quota_file_io.h |
| diff --git a/webkit/plugins/ppapi/quota_file_io.h b/webkit/plugins/ppapi/quota_file_io.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5b89bce513350bee5eb47bfcbfc298b544895875 |
| --- /dev/null |
| +++ b/webkit/plugins/ppapi/quota_file_io.h |
| @@ -0,0 +1,101 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef WEBKIT_PLUGINS_PPAPI_QUOTA_FILE_IO_H_ |
| +#define WEBKIT_PLUGINS_PPAPI_QUOTA_FILE_IO_H_ |
| + |
| +#include <queue> |
| + |
| +#include "base/file_util_proxy.h" |
| +#include "base/memory/scoped_callback_factory.h" |
| +#include "base/platform_file.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "ppapi/c/pp_file_info.h" |
| +#include "webkit/quota/quota_types.h" |
| + |
| +namespace webkit { |
| +namespace ppapi { |
| + |
| +class PluginInstance; |
| + |
| +// This class is created per PPB_FileIO_Impl instance and provides |
| +// write operations for quota-managed files (i.e. files of |
| +// PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}). |
| +class QuotaFileIO { |
| + public: |
| + typedef base::FileUtilProxy::WriteCallback WriteCallback; |
| + typedef base::FileUtilProxy::StatusCallback StatusCallback; |
| + |
| + QuotaFileIO(PluginInstance* instance, |
| + base::PlatformFile file, |
| + const GURL& path_url, |
| + PP_FileSystemType type); |
| + virtual ~QuotaFileIO(); |
|
yzshen1
2011/07/26 19:26:44
virtual is not necessary.
kinuko
2011/07/27 09:33:14
Done.
|
| + |
| + bool Write(int64_t offset, |
| + const char* buffer, |
| + int32_t bytes_to_write, |
| + WriteCallback* callback); |
| + bool SetLength(int64_t length, StatusCallback* callback); |
| + bool WillWrite(int64_t offset, |
| + int32_t bytes_to_write, |
| + WriteCallback* callback); |
| + bool WillSetLength(int64_t length, StatusCallback* callback); |
| + |
| + private: |
| + class PendingOperationBase; |
| + class WriteOperation; |
| + class SetLengthOperation; |
| + |
| + bool CheckIfExceedsQuota(int64_t new_file_size) const; |
| + void WillUpdate(); |
| + void DidWrite(int64_t written_offset_end); |
| + void DidSetLength(int64_t new_file_size); |
| + |
| + bool RegisterOperationForQuotaChecks(PendingOperationBase* op); |
| + void DidQueryInfoForQuota(base::PlatformFileError error_code, |
| + const base::PlatformFileInfo& file_info); |
| + void DidQueryAvailableSpace(int64_t avail_space); |
| + void DidQueryForQuotaCheck(); |
| + |
| + // For internal bookkeeping. All live pending operations are registered |
| + // so that we can abort/delete them in destructor. |
| + void RegisterOperation(PendingOperationBase* op); |
| + void UnregisterOperation(PendingOperationBase* op); |
| + |
| + // The plugin instance that owns this (via PPB_FileIO_Impl). |
| + PluginInstance* instance_; |
| + |
| + // The file information associated to this instance. |
| + base::PlatformFile file_; |
| + GURL file_url_; |
| + quota::StorageType storage_type_; |
| + |
| + // Operations waiting for a quota check to finish. |
| + std::queue<PendingOperationBase*> pending_operations_; |
| + |
| + // All registered operations including pending ones. Kept separately |
| + // from pending operations so that we can make sure we delete them when |
| + // this instance goes away. |
| + std::set<PendingOperationBase*> registered_operations_; |
| + |
| + // Valid only while there're pending quota checks. |
| + int64_t cached_file_size_; |
| + int64_t cached_available_space_; |
| + |
| + // Quota-related queries and errors occured during inflight quota checks. |
| + int outstanding_quota_queries_; |
| + int outstanding_errors_; |
| + |
| + bool did_notify_will_update_; |
| + int64_t max_written_offset_; |
| + |
| + base::ScopedCallbackFactory<QuotaFileIO> callback_factory_; |
| + DISALLOW_COPY_AND_ASSIGN(QuotaFileIO); |
| +}; |
| + |
| +} // namespace ppapi |
| +} // namespace webkit |
| + |
| +#endif // WEBKIT_PLUGINS_PPAPI_QUOTA_FILE_IO_H_ |