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

Side by Side Diff: webkit/plugins/ppapi/ppb_file_io_impl.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_
6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ 6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_
7 7
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h"
11 #include "base/file_path.h" 12 #include "base/file_path.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_callback_factory.h" 14 #include "base/memory/scoped_callback_factory.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/platform_file.h" 16 #include "base/platform_file.h"
16 #include "ppapi/c/pp_file_info.h" 17 #include "ppapi/c/pp_file_info.h"
17 #include "ppapi/c/pp_time.h" 18 #include "ppapi/c/pp_time.h"
18 #include "ppapi/thunk/ppb_file_io_api.h" 19 #include "ppapi/thunk/ppb_file_io_api.h"
19 #include "webkit/plugins/ppapi/callbacks.h" 20 #include "webkit/plugins/ppapi/callbacks.h"
20 #include "webkit/plugins/ppapi/plugin_delegate.h" 21 #include "webkit/plugins/ppapi/plugin_delegate.h"
21 #include "webkit/plugins/ppapi/resource.h" 22 #include "webkit/plugins/ppapi/resource.h"
22 23
23 struct PP_CompletionCallback; 24 struct PP_CompletionCallback;
24 struct PPB_FileIO; 25 struct PPB_FileIO;
25 struct PPB_FileIOTrusted; 26 struct PPB_FileIOTrusted;
26 27
27 namespace webkit { 28 namespace webkit {
28 namespace ppapi { 29 namespace ppapi {
29 30
30 class PluginModule; 31 class PluginModule;
31 class PPB_FileRef_Impl; 32 class PPB_FileRef_Impl;
32 33
33 class PPB_FileIO_Impl : public Resource, 34 class PPB_FileIO_Impl : public Resource,
michaeln 2011/07/19 23:54:58 I'm kinda wondering if for the TEMP and PERSISTENT
kinuko 2011/07/20 13:39:35 I suspected we may want to do that. Not sure if w
34 public ::ppapi::thunk::PPB_FileIO_API { 35 public ::ppapi::thunk::PPB_FileIO_API {
35 public: 36 public:
36 explicit PPB_FileIO_Impl(PluginInstance* instance); 37 explicit PPB_FileIO_Impl(PluginInstance* instance);
37 virtual ~PPB_FileIO_Impl(); 38 virtual ~PPB_FileIO_Impl();
38 39
39 // ResourceObjectBase overrides. 40 // ResourceObjectBase overrides.
40 virtual ::ppapi::thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE; 41 virtual ::ppapi::thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE;
41 42
42 // PPB_FileIO_API implementation. 43 // PPB_FileIO_API implementation.
43 virtual int32_t Open(PP_Resource file_ref, 44 virtual int32_t Open(PP_Resource file_ref,
44 int32_t open_flags, 45 int32_t open_flags,
45 PP_CompletionCallback callback) OVERRIDE; 46 PP_CompletionCallback callback) OVERRIDE;
46 virtual int32_t Query(PP_FileInfo* info, 47 virtual int32_t Query(PP_FileInfo* info,
47 PP_CompletionCallback callback) OVERRIDE; 48 PP_CompletionCallback callback) OVERRIDE;
48 virtual int32_t Touch(PP_Time last_access_time, 49 virtual int32_t Touch(PP_Time last_access_time,
49 PP_Time last_modified_time, 50 PP_Time last_modified_time,
50 PP_CompletionCallback callback) OVERRIDE; 51 PP_CompletionCallback callback) OVERRIDE;
51 virtual int32_t Read(int64_t offset, 52 virtual int32_t Read(int64_t offset,
52 char* buffer, 53 char* buffer,
53 int32_t bytes_to_read, 54 int32_t bytes_to_read,
54 PP_CompletionCallback callback) OVERRIDE; 55 PP_CompletionCallback callback) OVERRIDE;
55 virtual int32_t Write(int64_t offset, 56 virtual int32_t Write(int64_t offset,
56 const char* buffer, 57 const char* buffer,
57 int32_t bytes_to_write, 58 int32_t bytes_to_write,
58 PP_CompletionCallback callback) OVERRIDE; 59 PP_CompletionCallback callback) OVERRIDE;
59 virtual int32_t SetLength(int64_t length, 60 virtual int32_t SetLength(int64_t length,
60 PP_CompletionCallback callback) OVERRIDE; 61 PP_CompletionCallback callback) OVERRIDE;
61 virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE; 62 virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE;
62 virtual void Close() OVERRIDE; 63 virtual void Close() OVERRIDE;
63 virtual int32_t GetOSFileDescriptor() OVERRIDE; 64 virtual int32_t GetOSFileDescriptor() OVERRIDE;
michaeln 2011/07/19 23:54:58 How is this used i wonder... will do some grepping
64 virtual int32_t WillWrite(int64_t offset, 65 virtual int32_t WillWrite(int64_t offset,
65 int32_t bytes_to_write, 66 int32_t bytes_to_write,
66 PP_CompletionCallback callback) OVERRIDE; 67 PP_CompletionCallback callback) OVERRIDE;
67 virtual int32_t WillSetLength(int64_t length, 68 virtual int32_t WillSetLength(int64_t length,
michaeln 2011/07/19 23:54:58 What are WillWrite() and WillSetLength() about...
brettw 2011/07/20 04:08:06 The proxy gets the OS file descriptor to duplicate
68 PP_CompletionCallback callback) OVERRIDE; 69 PP_CompletionCallback callback) OVERRIDE;
69 70
70 private: 71 private:
71 struct CallbackEntry { 72 struct CallbackEntry {
72 CallbackEntry(); 73 CallbackEntry();
73 CallbackEntry(const CallbackEntry& entry); 74 CallbackEntry(const CallbackEntry& entry);
74 ~CallbackEntry(); 75 ~CallbackEntry();
75 76
76 scoped_refptr<TrackedCompletionCallback> callback; 77 scoped_refptr<TrackedCompletionCallback> callback;
77 // Pointer back to the caller's read buffer; only used by |Read()|. 78 // Pointer back to the caller's read buffer; only used by |Read()|.
78 // Not owned. 79 // Not owned.
79 char* read_buffer; 80 char* read_buffer;
80 }; 81 };
81 82
83 struct PendingWrite {
84 int64_t offset;
85 const char* buffer;
86 int32_t bytes_to_write;
87 };
88
82 enum OperationType { 89 enum OperationType {
83 // If there are pending reads, any other kind of async operation is not 90 // If there are pending reads, any other kind of async operation is not
84 // allowed. 91 // allowed.
85 OPERATION_READ, 92 OPERATION_READ,
86 // If there are pending writes, any other kind of async operation is not 93 // If there are pending writes, any other kind of async operation is not
87 // allowed. 94 // allowed.
88 OPERATION_WRITE, 95 OPERATION_WRITE,
89 // If there is a pending operation that is neither read nor write, no 96 // If there is a pending operation that is neither read nor write, no
90 // further async operation is allowed. 97 // further async operation is allowed.
91 OPERATION_EXCLUSIVE, 98 OPERATION_EXCLUSIVE,
(...skipping 16 matching lines...) Expand all
108 // that |PP_OK_COMPLETIONPENDING| will be returned. 115 // that |PP_OK_COMPLETIONPENDING| will be returned.
109 // |read_buffer| is only used by read operations. 116 // |read_buffer| is only used by read operations.
110 void RegisterCallback(OperationType op, 117 void RegisterCallback(OperationType op,
111 PP_CompletionCallback callback, 118 PP_CompletionCallback callback,
112 char* rend_buffer); 119 char* rend_buffer);
113 120
114 void RunAndRemoveFirstPendingCallback(int32_t result); 121 void RunAndRemoveFirstPendingCallback(int32_t result);
115 122
116 void StatusCallback(base::PlatformFileError error_code); 123 void StatusCallback(base::PlatformFileError error_code);
117 void AsyncOpenFileCallback(base::PlatformFileError error_code, 124 void AsyncOpenFileCallback(base::PlatformFileError error_code,
118 base::PassPlatformFile file); 125 base::PassPlatformFile file,
126 int64 file_size);
michaeln 2011/07/19 22:01:45 Seems that this class mostly uses int64_t in place
kinuko 2011/07/20 13:39:35 Done.
119 void QueryInfoCallback(base::PlatformFileError error_code, 127 void QueryInfoCallback(base::PlatformFileError error_code,
120 const base::PlatformFileInfo& file_info); 128 const base::PlatformFileInfo& file_info);
121 void ReadCallback(base::PlatformFileError error_code, 129 void ReadCallback(base::PlatformFileError error_code,
122 const char* data, int bytes_read); 130 const char* data, int bytes_read);
123 void WriteCallback(base::PlatformFileError error_code, int bytes_written); 131 void WriteCallback(base::PlatformFileError error_code, int bytes_written);
132 void SetLengthCallback(base::PlatformFileError error_code);
133
134 void DidCheckQuotaForWrite(bool success);
135 void DidCheckQuotaForSetLength(bool success);
124 136
125 base::ScopedCallbackFactory<PPB_FileIO_Impl> callback_factory_; 137 base::ScopedCallbackFactory<PPB_FileIO_Impl> callback_factory_;
126 138
127 base::PlatformFile file_; 139 base::PlatformFile file_;
128 PP_FileSystemType file_system_type_; 140 PP_FileSystemType file_system_type_;
129 141
142 // They are valid only for files of
143 // PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}.
144 GURL origin_url_;
145 int64 file_size_;
146
130 std::queue<CallbackEntry> callbacks_; 147 std::queue<CallbackEntry> callbacks_;
131 OperationType pending_op_; 148 OperationType pending_op_;
132 149
133 // Output buffer pointer for |Query()|; only non-null when a callback is 150 // Output buffer pointer for |Query()|; only non-null when a callback is
134 // pending for it. 151 // pending for it.
135 PP_FileInfo* info_; 152 PP_FileInfo* info_;
136 153
154 std::queue<PendingWrite> pending_writes_;
yzshen1 2011/07/19 17:41:55 |pending_writes_| and |pending_write_callbacks_| l
michaeln 2011/07/19 22:01:45 Maybe... pending_quota_checks_ pending_writes_
kinuko 2011/07/20 13:39:35 Done.
155 std::queue<PendingWrite> pending_write_callbacks_;
156 int64_t pending_setlength_length_;
157
137 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Impl); 158 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Impl);
138 }; 159 };
139 160
140 } // namespace ppapi 161 } // namespace ppapi
141 } // namespace webkit 162 } // namespace webkit
142 163
143 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ 164 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698