Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Unified Diff: webkit/plugins/ppapi/quota_file_io.h

Issue 7433006: Pepper quota support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_io_impl.cc ('k') | webkit/plugins/ppapi/quota_file_io.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ec090a443f53c80964dd37479c39e8dcfc9d44c7
--- /dev/null
+++ b/webkit/plugins/ppapi/quota_file_io.h
@@ -0,0 +1,102 @@
+// 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 <deque>
+
+#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);
+ ~QuotaFileIO();
+
+ // Performs write or setlength operation with quota checks.
+ // Returns true when the operation is successfully dispatched.
+ // |callback| will be dispatched when the operation completes.
+ // Otherwise it returns false and |callback| will not be dispatched.
+ // |callback| will not be dispatched either when this instance is
+ // destroyed before the operation completes.
+ // SetLength/WillSetLength cannot be called while there're any inflight
+ // operations. For Write/WillWrite it is guaranteed that |callback| are
+ // always dispatched in the same order as Write being called.
+ bool Write(int64_t offset,
+ const char* buffer,
+ int32_t bytes_to_write,
+ WriteCallback* callback);
+ bool WillWrite(int64_t offset,
+ int32_t bytes_to_write,
+ WriteCallback* callback);
+
+ bool SetLength(int64_t length, StatusCallback* 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(WriteOperation* op, int64_t written_offset_end);
+ void DidSetLength(base::PlatformFileError error, 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();
+
+ // 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::deque<PendingOperationBase*> pending_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_;
+
+ // For parallel writes bookkeeping.
+ int64_t max_written_offset_;
+ int inflight_operations_;
+
+ base::ScopedCallbackFactory<QuotaFileIO> callback_factory_;
+ DISALLOW_COPY_AND_ASSIGN(QuotaFileIO);
+};
+
+} // namespace ppapi
+} // namespace webkit
+
+#endif // WEBKIT_PLUGINS_PPAPI_QUOTA_FILE_IO_H_
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_io_impl.cc ('k') | webkit/plugins/ppapi/quota_file_io.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698