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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/ppapi_sources.gypi ('k') | ppapi/proxy/filesystem_provider_resource.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/filesystem_provider_resource.h
diff --git a/ppapi/proxy/filesystem_provider_resource.h b/ppapi/proxy/filesystem_provider_resource.h
new file mode 100644
index 0000000000000000000000000000000000000000..4b886ce4e5c5095d583cc88937f43c31f63bc4e2
--- /dev/null
+++ b/ppapi/proxy/filesystem_provider_resource.h
@@ -0,0 +1,526 @@
+// Copyright 2015 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 FILESYSTEM_PROVIDER_RESOURCE_H
+#define FILESYSTEM_PROVIDER_RESOURCE_H
+
+#include <chrono>
+#include <map>
+
+#include "ppapi/proxy/connection.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/ppapi_proxy_export.h"
+#include "ppapi/shared_impl/resource.h"
+#include "ppapi/thunk/ppb_filesystem_provider_api.h"
+
+namespace ppapi {
+namespace proxy {
+
+namespace filesystem_provider_internal{
+struct OperationTranslator;
+} // namespace
+class PPAPI_PROXY_EXPORT FilesystemProviderResource
+ :public PluginResource,
+ public NON_EXPORTED_BASE(thunk::PPB_FilesystemProvider_API) {
+ private:
+ // Waiting room for shared memory
+ // This is used when sending read file responses to the browser
+ class ShmChannelController{
+ typedef base::Callback<bool(scoped_ptr<base::ListValue>, const char* data,
+ uint32_t data_size)>
+ FlushResponseCallback;
+ public:
+ ShmChannelController( uint32_t size, FlushResponseCallback callback );
+ ~ShmChannelController();
+ // This will flush send the re
+ bool EnqueueResponse(scoped_ptr<base::ListValue> response,
+ const char* data, uint32_t data_size);
+ bool PushNextResponse();
+ bool AckLastPushedResponse();
+ private:
+ uint32_t size();
+ uint32_t max_size;
+ ScopedVector<base::ListValue> replies;
+ bool ready;
+ FlushResponseCallback callback;
+ };
+ // All the information we need about the filesystem is stored here
+ struct ProvidedFilesystemInfo{
+ ProvidedFilesystemInfo();
+ ~ProvidedFilesystemInfo();
+ std::string filesystem_id;
+ std::string display_name;
+ bool writable;
+ int32_t opened_files_limit;
+ };
+ // Shared memory container
+ struct ShmBuffer {
+ ShmBuffer(uint32_t read_size,
+ uint32_t write_size, scoped_ptr<base::SharedMemory> shm);
+ ~ShmBuffer();
+ uint32_t read_size;
+ uint32_t write_size;
+ scoped_ptr<base::SharedMemory> shm;
+ };
+ // An interface used for statistics and ill intended
+ // notifications from the plugin implementation.This will filter out
+ // operation responses that don't have an operation request from the browser.
+ class RequestManager{
+ private:
+ // Current Requests typedefs
+ typedef std::pair<PP_OperationType_Dev,
+ std::chrono::time_point<std::chrono::system_clock>>
+ OperationStartTimePair;
+ typedef std::map<int32_t, OperationStartTimePair >
+ ListOfRequests;
+ typedef ListOfRequests::iterator ListOfRequestsIterator;
+
+ public:
+ RequestManager();
+ ~RequestManager();
+ // Adds a request
+ void AddRequest( int32_t request_id, PP_OperationType_Dev operation );
+ // Removes a request. This is successful only if the request previously
+ // existed. The out_time_span contains the time in seconds of the operation
+ bool HasRequest(int32_t request_id);
+ bool RemoveRequest(int32_t request_id, int* out_time_span);
+
+ private:
+ ListOfRequests requests_;
+ };
+ public:
+ FilesystemProviderResource(
+ Connection connection,
+ PP_Instance instance );
+ virtual ~FilesystemProviderResource();
+ // PluginResource overrides:
+ virtual thunk::PPB_FilesystemProvider_API*
+ AsPPB_FilesystemProvider_API() override;
+ void OnReplyReceived(
+ const ResourceMessageReplyParams &params,
+ const IPC::Message &msg) override;
+ // PPB_FilesystemProvider_API overrides
+ // The below functions will be called from the instance module
+ // to notify the browser or to request certain actions from the browser
+ virtual int32_t Mount(
+ struct PP_Var filesystem_id,
+ struct PP_Var display_name,
+ PP_Bool writable,
+ int32_t opened_files_limit,
+ scoped_refptr<TrackedCallback> callback) override;
+ virtual int32_t Unmount(
+ struct PP_Var filesystemId,
+ scoped_refptr<TrackedCallback> callback) override;
+ virtual int32_t Notify(PP_Var notify_options) override;
+
+ virtual int32_t SendSuccessResponse(
+ PP_OperationType_Dev operation_type,
+ int32_t request_id) override;
+ virtual int32_t SendErrorResponse(
+ PP_OperationType_Dev operation_type,
+ int32_t error,
+ int32_t request_id) override;
+
+ virtual int32_t SendMetadataSuccessResponse(
+ struct PP_Var metadata,
+ int32_t request_id) override;
+ virtual int32_t SendReadDirectorySuccessResponse(
+ struct PP_Var entries,
+ PP_Bool has_more,
+ int32_t request_id) override;
+ virtual int32_t SendReadFileSuccessResponse(
+ uint32_t data_size,
+ const void* data,
+ PP_Bool has_more,
+ int32_t request_id) override;
+ virtual int32_t GetNextRequest(
+ PP_FilesystemRequest *request,
+ scoped_refptr<TrackedCallback> callback)override;
+ virtual int32_t ReleaseRequestBuffer(int32_t request_id)override;
+
+
+ private:
+ // Message Handlers for the browser messages
+ void OnPluginMsgMountReply(const ResourceMessageReplyParams& params);
+ void OnPluginMsgUnmountReply(const ResourceMessageReplyParams& params);
+ // Handles the file system operations
+ // requested by the browser
+ void OnPluginMsgOperationRequest(
+ const ResourceMessageParams& params,
+ const PP_OperationType_Dev& operation,
+ const base::ListValue& operationArgs);
+ void OnPluginMsgBuffersReady(const ResourceMessageParams& params,
+ uint32_t buffer_length, uint32_t write_buffer_size);
+ void OnPluginMsgReadAck(
+ const ResourceMessageReplyParams& params);
+
+ // Remember a request in the provided container address
+ bool WriteRequest();
+ // Send Read response to browser
+ bool FlushReadResponse(scoped_ptr<base::ListValue> response,
+ const char *data,
+ uint32_t data_size);
+ void SendWriteAck();
+ // The filesystem information
+ ProvidedFilesystemInfo filesystem_info_;
+ // Flag for the state of the filesystem
+ bool mounted_;
+ // User callbacks
+ scoped_refptr<TrackedCallback> mount_callback_;
+ scoped_refptr<TrackedCallback> unmount_callback_;
+ scoped_refptr<TrackedCallback> get_next_request_callback_;
+ // Data containers for the above callback
+ struct PP_FilesystemRequest* get_next_request_callback_data_;
+ // Keep received requests until consumed
+ // by calling GetNextRequest
+ std::deque<scoped_refptr<filesystem_provider_internal::OperationTranslator>>
+ received_requests_;
+ // Received requests that are buffered from when GetNextRequest
+ // is called until ReleaseRequestBuffer is called.
+ typedef
+ std::map< int32_t,
+ scoped_refptr<filesystem_provider_internal::OperationTranslator> >
+ ListOfRequests;
+ ListOfRequests pending_process_requests_;
+ // Shared memory buffer
+ scoped_ptr<ShmBuffer> read_write_buffer_;
+ // A RequestManager that controls access to the shared memory write
+ scoped_ptr<FilesystemProviderResource::RequestManager> request_manager_;
+ // Cacher for replys that content for the shared mem buffer
+ scoped_ptr<ShmChannelController> read_channel_controller_;
+ DISALLOW_COPY_AND_ASSIGN( FilesystemProviderResource );
+};
+
+namespace filesystem_provider_internal{
+
+struct OperationTranslator : public base::RefCounted<OperationTranslator>{
+ virtual ~OperationTranslator();
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()=0;
+};
+struct AbortOperationTranslator : public OperationTranslator{
+ virtual ~AbortOperationTranslator()override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
+ static
+ scoped_refptr< AbortOperationTranslator > PopulateFromRequest(
+ const base::ListValue& request );
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // An ID of the request to be aborted.
+ int operation_request_id;
+ private:
+ AbortOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(AbortOperationTranslator);
+};
+
+struct CloseFileOperationTranslator : public OperationTranslator{
+ ~CloseFileOperationTranslator()override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
+ // Creates a CloseFileRequestedOptions object from a base::Value, or NULL on
+ // failure.
+ static
+ scoped_refptr<CloseFileOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request);
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // A request ID used to open the file.
+ int open_request_id;
+ private:
+ CloseFileOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(CloseFileOperationTranslator);
+};
+
+struct CopyEntryOperationTranslator : public OperationTranslator{
+ ~CopyEntryOperationTranslator() override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
+ static scoped_refptr<CopyEntryOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request);
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // The source path of the entry to be copied.
+ std::string source_path;
+ // The destination path for the copy operation.
+ std::string target_path;
+ private:
+ CopyEntryOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(CopyEntryOperationTranslator);
+};
+
+struct CreateDirectoryOperationTranslator : public OperationTranslator {
+ ~CreateDirectoryOperationTranslator()override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
+ static scoped_refptr<CreateDirectoryOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request );
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // The path of the directory to be created.
+ std::string directory_path;
+ // Whether the operation is recursive (for directories only).
+ bool recursive;
+ private:
+ CreateDirectoryOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperationTranslator);
+};
+
+struct CreateFileOperationTranslator : public OperationTranslator{
+ ~CreateFileOperationTranslator() override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
+ static scoped_refptr<CreateFileOperationTranslator> PopulateFromRequest(
+ const base::ListValue &request );
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // The path of the file to be created.
+ std::string file_path;
+ private:
+ CreateFileOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(CreateFileOperationTranslator);
+};
+
+struct DeleteEntryOperationTranslator : public OperationTranslator{
+ ~DeleteEntryOperationTranslator()override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
+ static scoped_refptr<DeleteEntryOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request );
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // The path of the entry to be deleted.
+ std::string entry_path;
+ // Whether the operation is recursive (for directories only).
+ bool recursive;
+ private:
+ DeleteEntryOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(DeleteEntryOperationTranslator);
+};
+
+struct GetMetadataOperationTranslator:public OperationTranslator{
+ ~GetMetadataOperationTranslator()override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
+ static scoped_refptr<GetMetadataOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request );
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // The path of the entry to fetch metadata about.
+ std::string entry_path;
+ // Set to <code>true</code> if the thumbnail is requested.
+ bool thumbnail;
+private:
+ GetMetadataOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN( GetMetadataOperationTranslator );
+};
+
+struct MoveOperationTranslator : public OperationTranslator {
+ ~MoveOperationTranslator()override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
+ static scoped_refptr<MoveOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request );
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // The source path of the entry to be moved into a new place.
+ std::string source_path;
+ // The destination path for the copy operation.
+ std::string target_path;
+ private:
+ MoveOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(MoveOperationTranslator);
+};
+
+struct OpenFileOperationTranslator : public OperationTranslator {
+ ~OpenFileOperationTranslator() override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest()override;
+ static scoped_refptr<OpenFileOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request);
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // A request ID which will be used by consecutive read/write and close
+ // requests.
+ int request_id;
+ // The path of the file to be opened.
+ std::string file_path;
+ // Whether the file will be used for reading or writing.
+ PP_OpenFileMode_Dev mode;
+ private:
+ OpenFileOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(OpenFileOperationTranslator);
+};
+
+struct ReadDirectoryOperationTranslator : public OperationTranslator {
+ ~ReadDirectoryOperationTranslator() override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
+ static scoped_refptr<ReadDirectoryOperationTranslator> PopulateFromRequest(
+ const base::ListValue& value);
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // The path of the directory which contents are requested.
+ std::string directory_path;
+ private:
+ ReadDirectoryOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(ReadDirectoryOperationTranslator);
+};
+
+struct ReadFileOperationTranslator : public OperationTranslator {
+ ~ReadFileOperationTranslator() override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
+ static scoped_refptr<ReadFileOperationTranslator> PopulateFromRequest(
+ const base::ListValue& value);
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // A request ID used to open the file.
+ int open_request_id;
+ // Position in the file (in bytes) to start reading from.
+ double offset;
+ // Number of bytes to be returned.
+ double length;
+ private:
+ ReadFileOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(ReadFileOperationTranslator);
+};
+
+struct TruncateOperationTranslator : public OperationTranslator {
+ ~TruncateOperationTranslator() override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
+ static scoped_refptr<TruncateOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request);
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // The path of the file to be truncated.
+ std::string file_path;
+ // Number of bytes to be retained after the operation completes.
+ double length;
+ private:
+ TruncateOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(TruncateOperationTranslator);
+};
+
+struct UnmountOperationTranslator : public OperationTranslator {
+ ~UnmountOperationTranslator() override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
+ static scoped_refptr<UnmountOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request);
+ // The identifier of the file system to be unmounted.
+ std::string file_system_id;
+ int request_id;
+ private:
+ UnmountOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(UnmountOperationTranslator);
+};
+
+struct WriteFileOperationTranslator : public OperationTranslator {
+ ~WriteFileOperationTranslator() override;
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
+ static scoped_refptr<WriteFileOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request,
+ char* memory_address);
+ // The identifier of the file system related to this operation.
+ std::string file_system_id;
+ // The unique identifier of this request.
+ int request_id;
+ // A request ID used to open the file.
+ int open_request_id;
+ // Position in the file (in bytes) to start writing the bytes from.
+ double offset;
+ // The size of the buffer
+ double size;
+ // Buffer for the file chunk
+ std::vector<char> data;
+ private:
+ WriteFileOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(WriteFileOperationTranslator);
+};
+
+struct AddWatcherOperationTranslator : public OperationTranslator {
+ ~AddWatcherOperationTranslator();
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
+ static scoped_refptr<AddWatcherOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request);
+ std::string file_system_id;
+ int request_id;
+ std::string entry_path;
+ bool recursive;
+ private:
+ AddWatcherOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(AddWatcherOperationTranslator);
+};
+
+
+struct RemoveWatcherOperationTranslator : public OperationTranslator {
+ ~RemoveWatcherOperationTranslator();
+ virtual scoped_ptr<PP_FilesystemRequest> ToFilesystemRequest() override;
+ static scoped_refptr<RemoveWatcherOperationTranslator> PopulateFromRequest(
+ const base::ListValue& request);
+ std::string file_system_id;
+ int request_id;
+ std::string entry_path;
+ bool recursive;
+ private:
+ RemoveWatcherOperationTranslator();
+ DISALLOW_COPY_AND_ASSIGN(RemoveWatcherOperationTranslator);
+};
+
+struct PluginToBrowserTranslator{
+ ~PluginToBrowserTranslator() {}
+ static scoped_ptr<base::ListValue> GenerateMountMessage(
+ std::string filesystem_id,
+ std::string display_name,
+ bool writable,
+ int32_t opened_files_limit);
+ static scoped_ptr<base::ListValue> GenerateNotifyMessage(
+ PP_Var notification_options);
+
+ static scoped_ptr<base::ListValue> GenerateSuccessResponse(
+ PP_OperationType_Dev operation_type,
+ const std::string& filesystem_id,
+ int32_t request_id,
+ int time_span);
+
+ static scoped_ptr<base::ListValue> GenerateFailureResponse(
+ PP_OperationType_Dev operation_type,
+ int32_t error,
+ const std::string& filesystem_id,
+ int32_t request_id,
+ int time_span);
+ static scoped_ptr<base::ListValue> GenerateMetadataResponse(
+ struct PP_Var metadata,
+ int32_t request_id,
+ const std::string& filesystem_id,
+ int time_span);
+ static scoped_ptr<base::ListValue> GenerateReadDirectoryResponse(
+ struct PP_Var entries,
+ PP_Bool has_more, int32_t request_id, const std::string& filesystem_id,
+ int time_span);
+ static scoped_ptr<base::ListValue> GenerateReadFileSuccessResponse(
+ uint32_t data_size, bool has_more, int32_t request_id,
+ int time_span, const std::string& filesystem_id);
+ private:
+ static scoped_ptr<base::DictionaryValue> GenerateMetadataListFromPPVar(
+ PP_Var metadata);
+ PluginToBrowserTranslator(){}
+ DISALLOW_COPY_AND_ASSIGN(PluginToBrowserTranslator);
+
+};
+
+}// namespace
+}// namespace proxy
+}// namespace ppapi
+
+#endif // FILESYSTEM_PROVIDER_RESOURCE_H
+
« 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