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

Side by Side Diff: ppapi/proxy/filesystem_provider_resource.h

Issue 1093383002: [WIP] Provided file system from NACL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved several modules to chromeos folder. Created 5 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
« no previous file with comments | « ppapi/ppapi_sources.gypi ('k') | ppapi/proxy/filesystem_provider_resource.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 #ifndef FILESYSTEM_PROVIDER_RESOURCE_H
5 #define FILESYSTEM_PROVIDER_RESOURCE_H
6
7 #include <chrono>
8 #include <map>
9
10 #include "ppapi/proxy/connection.h"
11 #include "ppapi/proxy/plugin_resource.h"
12 #include "ppapi/proxy/ppapi_proxy_export.h"
13 #include "ppapi/shared_impl/resource.h"
14 #include "ppapi/thunk/ppb_filesystem_provider_api.h"
15
16 namespace ppapi {
17 namespace proxy {
18
19 namespace filesystem_provider_internal{
20 struct OperationTranslator;
21 } // namespace
22 class PPAPI_PROXY_EXPORT FilesystemProviderResource
23 :public PluginResource,
24 public NON_EXPORTED_BASE(thunk::PPB_FilesystemProvider_API) {
25 private:
26 // Waiting room for shared memory
27 // This is used when sending read file responses to the browser
28 class ShmChannelController{
29 typedef base::Callback<bool(scoped_ptr<base::ListValue>, const char* data,
30 uint32_t data_size)>
31 FlushResponseCallback;
32 public:
33 ShmChannelController( uint32_t size, FlushResponseCallback callback );
34 ~ShmChannelController();
35 // This will flush send the re
36 bool EnqueueResponse(scoped_ptr<base::ListValue> response,
37 const char* data, uint32_t data_size);
38 bool PushNextResponse();
39 bool AckLastPushedResponse();
40 private:
41 uint32_t size();
42 uint32_t max_size;
43 ScopedVector<base::ListValue> replies;
44 bool ready;
45 FlushResponseCallback callback;
46 };
47 // All the information we need about the filesystem is stored here
48 struct ProvidedFilesystemInfo{
49 ProvidedFilesystemInfo();
50 ~ProvidedFilesystemInfo();
51 std::string filesystem_id;
52 std::string display_name;
53 bool writable;
54 int32_t opened_files_limit;
55 };
56 // Shared memory container
57 struct ShmBuffer {
58 ShmBuffer(uint32_t read_size,
59 uint32_t write_size, scoped_ptr<base::SharedMemory> shm);
60 ~ShmBuffer();
61 uint32_t read_size;
62 uint32_t write_size;
63 scoped_ptr<base::SharedMemory> shm;
64 };
65 // An interface used for statistics and ill intended
66 // notifications from the plugin implementation.This will filter out
67 // operation responses that don't have an operation request from the browser.
68 class RequestManager{
69 private:
70 // Current Requests typedefs
71 typedef std::pair<PP_OperationType_Dev,
72 std::chrono::time_point<std::chrono::system_clock>>
73 OperationStartTimePair;
74 typedef std::map<int32_t, OperationStartTimePair >
75 ListOfRequests;
76 typedef ListOfRequests::iterator ListOfRequestsIterator;
77
78 public:
79 RequestManager();
80 ~RequestManager();
81 // Adds a request
82 void AddRequest( int32_t request_id, PP_OperationType_Dev operation );
83 // Removes a request. This is successful only if the request previously
84 // existed. The out_time_span contains the time in seconds of the operation
85 bool HasRequest(int32_t request_id);
86 bool RemoveRequest(int32_t request_id, int* out_time_span);
87
88 private:
89 ListOfRequests requests_;
90 };
91 public:
92 FilesystemProviderResource(
93 Connection connection,
94 PP_Instance instance );
95 virtual ~FilesystemProviderResource();
96 // PluginResource overrides:
97 virtual thunk::PPB_FilesystemProvider_API*
98 AsPPB_FilesystemProvider_API() override;
99 void OnReplyReceived(
100 const ResourceMessageReplyParams &params,
101 const IPC::Message &msg) override;
102 // PPB_FilesystemProvider_API overrides
103 // The below functions will be called from the instance module
104 // to notify the browser or to request certain actions from the browser
105 virtual int32_t Mount(
106 struct PP_Var filesystem_id,
107 struct PP_Var display_name,
108 PP_Bool writable,
109 int32_t opened_files_limit,
110 scoped_refptr<TrackedCallback> callback) override;
111 virtual int32_t Unmount(
112 struct PP_Var filesystemId,
113 scoped_refptr<TrackedCallback> callback) override;
114 virtual int32_t Notify(PP_Var notify_options) override;
115
116 virtual int32_t SendSuccessResponse(
117 PP_OperationType_Dev operation_type,
118 int32_t request_id) override;
119 virtual int32_t SendErrorResponse(
120 PP_OperationType_Dev operation_type,
121 int32_t error,
122 int32_t request_id) override;
123
124 virtual int32_t SendMetadataSuccessResponse(
125 struct PP_Var metadata,
126 int32_t request_id) override;
127 virtual int32_t SendReadDirectorySuccessResponse(
128 struct PP_Var entries,
129 PP_Bool has_more,
130 int32_t request_id) override;
131 virtual int32_t SendReadFileSuccessResponse(
132 uint32_t data_size,
133 const void* data,
134 PP_Bool has_more,
135 int32_t request_id) override;
136 virtual int32_t GetNextRequest(
137 PP_FilesystemRequest *request,
138 scoped_refptr<TrackedCallback> callback)override;
139 virtual int32_t ReleaseRequestBuffer(int32_t request_id)override;
140
141
142 private:
143 // Message Handlers for the browser messages
144 void OnPluginMsgMountReply(const ResourceMessageReplyParams& params);
145 void OnPluginMsgUnmountReply(const ResourceMessageReplyParams& params);
146 // Handles the file system operations
147 // requested by the browser
148 void OnPluginMsgOperationRequest(
149 const ResourceMessageParams& params,
150 const PP_OperationType_Dev& operation,
151 const base::ListValue& operationArgs);
152 void OnPluginMsgBuffersReady(const ResourceMessageParams& params,
153 uint32_t buffer_length, uint32_t write_buffer_size);
154 void OnPluginMsgReadAck(
155 const ResourceMessageReplyParams& params);
156
157 // Remember a request in the provided container address
158 bool WriteRequest();
159 // Send Read response to browser
160 bool FlushReadResponse(scoped_ptr<base::ListValue> response,
161 const char *data,
162 uint32_t data_size);
163 void SendWriteAck();
164 // The filesystem information
165 ProvidedFilesystemInfo filesystem_info_;
166 // Flag for the state of the filesystem
167 bool mounted_;
168 // User callbacks
169 scoped_refptr<TrackedCallback> mount_callback_;
170 scoped_refptr<TrackedCallback> unmount_callback_;
171 scoped_refptr<TrackedCallback> get_next_request_callback_;
172 // Data containers for the above callback
173 struct PP_FilesystemRequest* get_next_request_callback_data_;
174 // Keep received requests until consumed
175 // by calling GetNextRequest
176 std::deque<scoped_refptr<filesystem_provider_internal::OperationTranslator>>
177 received_requests_;
178 // Received requests that are buffered from when GetNextRequest
179 // is called until ReleaseRequestBuffer is called.
180 typedef
181 std::map< int32_t,
182 scoped_refptr<filesystem_provider_internal::OperationTranslator> >
183 ListOfRequests;
184 ListOfRequests pending_process_requests_;
185 // Shared memory buffer
186 scoped_ptr<ShmBuffer> read_write_buffer_;
187 // A RequestManager that controls access to the shared memory write
188 scoped_ptr<FilesystemProviderResource::RequestManager> request_manager_;
189 // Cacher for replys that content for the shared mem buffer
190 scoped_ptr<ShmChannelController> read_channel_controller_;
191 DISALLOW_COPY_AND_ASSIGN( FilesystemProviderResource );
192 };
193
194 namespace filesystem_provider_internal{
195
196 struct OperationTranslator : public base::RefCounted<OperationTranslator>{
197 virtual ~OperationTranslator();
198 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()=0;
199 };
200 struct AbortOperationTranslator : public OperationTranslator{
201 virtual ~AbortOperationTranslator()override;
202 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
203 static
204 scoped_refptr< AbortOperationTranslator > PopulateFromRequest(
205 const base::ListValue& request );
206 // The identifier of the file system related to this operation.
207 std::string file_system_id;
208 // The unique identifier of this request.
209 int request_id;
210 // An ID of the request to be aborted.
211 int operation_request_id;
212 private:
213 AbortOperationTranslator();
214 DISALLOW_COPY_AND_ASSIGN(AbortOperationTranslator);
215 };
216
217 struct CloseFileOperationTranslator : public OperationTranslator{
218 ~CloseFileOperationTranslator()override;
219 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
220 // Creates a CloseFileRequestedOptions object from a base::Value, or NULL on
221 // failure.
222 static
223 scoped_refptr<CloseFileOperationTranslator> PopulateFromRequest(
224 const base::ListValue& request);
225 // The identifier of the file system related to this operation.
226 std::string file_system_id;
227 // The unique identifier of this request.
228 int request_id;
229 // A request ID used to open the file.
230 int open_request_id;
231 private:
232 CloseFileOperationTranslator();
233 DISALLOW_COPY_AND_ASSIGN(CloseFileOperationTranslator);
234 };
235
236 struct CopyEntryOperationTranslator : public OperationTranslator{
237 ~CopyEntryOperationTranslator() override;
238 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
239 static scoped_refptr<CopyEntryOperationTranslator> PopulateFromRequest(
240 const base::ListValue& request);
241 // The identifier of the file system related to this operation.
242 std::string file_system_id;
243 // The unique identifier of this request.
244 int request_id;
245 // The source path of the entry to be copied.
246 std::string source_path;
247 // The destination path for the copy operation.
248 std::string target_path;
249 private:
250 CopyEntryOperationTranslator();
251 DISALLOW_COPY_AND_ASSIGN(CopyEntryOperationTranslator);
252 };
253
254 struct CreateDirectoryOperationTranslator : public OperationTranslator {
255 ~CreateDirectoryOperationTranslator()override;
256 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
257 static scoped_refptr<CreateDirectoryOperationTranslator> PopulateFromRequest(
258 const base::ListValue& request );
259 // The identifier of the file system related to this operation.
260 std::string file_system_id;
261 // The unique identifier of this request.
262 int request_id;
263 // The path of the directory to be created.
264 std::string directory_path;
265 // Whether the operation is recursive (for directories only).
266 bool recursive;
267 private:
268 CreateDirectoryOperationTranslator();
269 DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperationTranslator);
270 };
271
272 struct CreateFileOperationTranslator : public OperationTranslator{
273 ~CreateFileOperationTranslator() override;
274 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
275 static scoped_refptr<CreateFileOperationTranslator> PopulateFromRequest(
276 const base::ListValue &request );
277 // The identifier of the file system related to this operation.
278 std::string file_system_id;
279 // The unique identifier of this request.
280 int request_id;
281 // The path of the file to be created.
282 std::string file_path;
283 private:
284 CreateFileOperationTranslator();
285 DISALLOW_COPY_AND_ASSIGN(CreateFileOperationTranslator);
286 };
287
288 struct DeleteEntryOperationTranslator : public OperationTranslator{
289 ~DeleteEntryOperationTranslator()override;
290 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
291 static scoped_refptr<DeleteEntryOperationTranslator> PopulateFromRequest(
292 const base::ListValue& request );
293 // The identifier of the file system related to this operation.
294 std::string file_system_id;
295 // The unique identifier of this request.
296 int request_id;
297 // The path of the entry to be deleted.
298 std::string entry_path;
299 // Whether the operation is recursive (for directories only).
300 bool recursive;
301 private:
302 DeleteEntryOperationTranslator();
303 DISALLOW_COPY_AND_ASSIGN(DeleteEntryOperationTranslator);
304 };
305
306 struct GetMetadataOperationTranslator:public OperationTranslator{
307 ~GetMetadataOperationTranslator()override;
308 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
309 static scoped_refptr<GetMetadataOperationTranslator> PopulateFromRequest(
310 const base::ListValue& request );
311 std::string file_system_id;
312 // The unique identifier of this request.
313 int request_id;
314 // The path of the entry to fetch metadata about.
315 std::string entry_path;
316 // Set to <code>true</code> if the thumbnail is requested.
317 bool thumbnail;
318 private:
319 GetMetadataOperationTranslator();
320 DISALLOW_COPY_AND_ASSIGN( GetMetadataOperationTranslator );
321 };
322
323 struct MoveOperationTranslator : public OperationTranslator {
324 ~MoveOperationTranslator()override;
325 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
326 static scoped_refptr<MoveOperationTranslator> PopulateFromRequest(
327 const base::ListValue& request );
328 // The identifier of the file system related to this operation.
329 std::string file_system_id;
330 // The unique identifier of this request.
331 int request_id;
332 // The source path of the entry to be moved into a new place.
333 std::string source_path;
334 // The destination path for the copy operation.
335 std::string target_path;
336 private:
337 MoveOperationTranslator();
338 DISALLOW_COPY_AND_ASSIGN(MoveOperationTranslator);
339 };
340
341 struct OpenFileOperationTranslator : public OperationTranslator {
342 ~OpenFileOperationTranslator() override;
343 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
344 static scoped_refptr<OpenFileOperationTranslator> PopulateFromRequest(
345 const base::ListValue& request);
346 // The identifier of the file system related to this operation.
347 std::string file_system_id;
348 // A request ID which will be used by consecutive read/write and close
349 // requests.
350 int request_id;
351 // The path of the file to be opened.
352 std::string file_path;
353 // Whether the file will be used for reading or writing.
354 PP_OpenFileMode_Dev mode;
355 private:
356 OpenFileOperationTranslator();
357 DISALLOW_COPY_AND_ASSIGN(OpenFileOperationTranslator);
358 };
359
360 struct ReadDirectoryOperationTranslator : public OperationTranslator {
361 ~ReadDirectoryOperationTranslator() override;
362 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
363 static scoped_refptr<ReadDirectoryOperationTranslator> PopulateFromRequest(
364 const base::ListValue& value);
365 // The identifier of the file system related to this operation.
366 std::string file_system_id;
367 // The unique identifier of this request.
368 int request_id;
369 // The path of the directory which contents are requested.
370 std::string directory_path;
371 private:
372 ReadDirectoryOperationTranslator();
373 DISALLOW_COPY_AND_ASSIGN(ReadDirectoryOperationTranslator);
374 };
375
376 struct ReadFileOperationTranslator : public OperationTranslator {
377 ~ReadFileOperationTranslator() override;
378 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
379 static scoped_refptr<ReadFileOperationTranslator> PopulateFromRequest(
380 const base::ListValue& value);
381 // The identifier of the file system related to this operation.
382 std::string file_system_id;
383 // The unique identifier of this request.
384 int request_id;
385 // A request ID used to open the file.
386 int open_request_id;
387 // Position in the file (in bytes) to start reading from.
388 double offset;
389 // Number of bytes to be returned.
390 double length;
391 private:
392 ReadFileOperationTranslator();
393 DISALLOW_COPY_AND_ASSIGN(ReadFileOperationTranslator);
394 };
395
396 struct TruncateOperationTranslator : public OperationTranslator {
397 ~TruncateOperationTranslator() override;
398 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
399 static scoped_refptr<TruncateOperationTranslator> PopulateFromRequest(
400 const base::ListValue& request);
401 // The identifier of the file system related to this operation.
402 std::string file_system_id;
403 // The unique identifier of this request.
404 int request_id;
405 // The path of the file to be truncated.
406 std::string file_path;
407 // Number of bytes to be retained after the operation completes.
408 double length;
409 private:
410 TruncateOperationTranslator();
411 DISALLOW_COPY_AND_ASSIGN(TruncateOperationTranslator);
412 };
413
414 struct UnmountOperationTranslator : public OperationTranslator {
415 ~UnmountOperationTranslator() override;
416 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
417 static scoped_refptr<UnmountOperationTranslator> PopulateFromRequest(
418 const base::ListValue& request);
419 // The identifier of the file system to be unmounted.
420 std::string file_system_id;
421 int request_id;
422 private:
423 UnmountOperationTranslator();
424 DISALLOW_COPY_AND_ASSIGN(UnmountOperationTranslator);
425 };
426
427 struct WriteFileOperationTranslator : public OperationTranslator {
428 ~WriteFileOperationTranslator() override;
429 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
430 static scoped_refptr<WriteFileOperationTranslator> PopulateFromRequest(
431 const base::ListValue& request,
432 char* memory_address);
433 // The identifier of the file system related to this operation.
434 std::string file_system_id;
435 // The unique identifier of this request.
436 int request_id;
437 // A request ID used to open the file.
438 int open_request_id;
439 // Position in the file (in bytes) to start writing the bytes from.
440 double offset;
441 // The size of the buffer
442 double size;
443 // Buffer for the file chunk
444 std::vector<char> data;
445 private:
446 WriteFileOperationTranslator();
447 DISALLOW_COPY_AND_ASSIGN(WriteFileOperationTranslator);
448 };
449
450 struct AddWatcherOperationTranslator : public OperationTranslator {
451 ~AddWatcherOperationTranslator();
452 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
453 static scoped_refptr<AddWatcherOperationTranslator> PopulateFromRequest(
454 const base::ListValue& request);
455 std::string file_system_id;
456 int request_id;
457 std::string entry_path;
458 bool recursive;
459 private:
460 AddWatcherOperationTranslator();
461 DISALLOW_COPY_AND_ASSIGN(AddWatcherOperationTranslator);
462 };
463
464
465 struct RemoveWatcherOperationTranslator : public OperationTranslator {
466 ~RemoveWatcherOperationTranslator();
467 virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
468 static scoped_refptr<RemoveWatcherOperationTranslator> PopulateFromRequest(
469 const base::ListValue& request);
470 std::string file_system_id;
471 int request_id;
472 std::string entry_path;
473 bool recursive;
474 private:
475 RemoveWatcherOperationTranslator();
476 DISALLOW_COPY_AND_ASSIGN(RemoveWatcherOperationTranslator);
477 };
478
479 struct PluginToBrowserTranslator{
480 ~PluginToBrowserTranslator() {}
481 static scoped_ptr<base::ListValue> GenerateMountMessage(
482 std::string filesystem_id,
483 std::string display_name,
484 bool writable,
485 int32_t opened_files_limit);
486 static scoped_ptr<base::ListValue> GenerateNotifyMessage(
487 PP_Var notification_options);
488
489 static scoped_ptr<base::ListValue> GenerateSuccessResponse(
490 PP_OperationType_Dev operation_type,
491 const std::string& filesystem_id,
492 int32_t request_id,
493 int time_span);
494
495 static scoped_ptr<base::ListValue> GenerateFailureResponse(
496 PP_OperationType_Dev operation_type,
497 int32_t error,
498 const std::string& filesystem_id,
499 int32_t request_id,
500 int time_span);
501 static scoped_ptr<base::ListValue> GenerateMetadataResponse(
502 struct PP_Var metadata,
503 int32_t request_id,
504 const std::string& filesystem_id,
505 int time_span);
506 static scoped_ptr<base::ListValue> GenerateReadDirectoryResponse(
507 struct PP_Var entries,
508 PP_Bool has_more, int32_t request_id, const std::string& filesystem_id,
509 int time_span);
510 static scoped_ptr<base::ListValue> GenerateReadFileSuccessResponse(
511 uint32_t data_size, bool has_more, int32_t request_id,
512 int time_span, const std::string& filesystem_id);
513 private:
514 static scoped_ptr<base::DictionaryValue> GenerateMetadataListFromPPVar(
515 PP_Var metadata);
516 PluginToBrowserTranslator(){}
517 DISALLOW_COPY_AND_ASSIGN(PluginToBrowserTranslator);
518
519 };
520
521 }// namespace
522 }// namespace proxy
523 }// namespace ppapi
524
525 #endif // FILESYSTEM_PROVIDER_RESOURCE_H
526
OLDNEW
« no previous file with comments | « ppapi/ppapi_sources.gypi ('k') | ppapi/proxy/filesystem_provider_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698