Index: content/browser/renderer_host/pepper/pepper_filesystem_provider_backend_chromeos.h |
diff --git a/content/browser/renderer_host/pepper/pepper_filesystem_provider_backend_chromeos.h b/content/browser/renderer_host/pepper/pepper_filesystem_provider_backend_chromeos.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..adf6aca6c8bc42a508828642d69ab3795b8ecbc1 |
--- /dev/null |
+++ b/content/browser/renderer_host/pepper/pepper_filesystem_provider_backend_chromeos.h |
@@ -0,0 +1,185 @@ |
+// 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 PEPPER_FILESYSTEM_PROVIDER_HOST_H |
+#define PEPPER_FILESYSTEM_PROVIDER_HOST_H |
+ |
+#include <chrono> |
+#include <queue> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/callback.h" |
+#include "base/memory/weak_ptr.h" |
+#include "chrome/browser/chromeos/file_system_provider/file_system_plugin/plugineventrouter.h" |
+#include "content/browser/renderer_host/pepper/pepper_filesystem_provider_host.h" |
+#include "content/common/content_export.h" |
+#include "ppapi/c/dev/ppb_filesystemprovider_dev.h" |
+#include "ppapi/c/pp_file_info.h" |
+#include "ppapi/host/host_message_context.h" |
+ |
+namespace content { |
+ |
+class CONTENT_EXPORT PepperFilesystemProviderBackendChromeOS |
+ : public PepperFilesystemProviderBackend |
+ , public chromeos::PluginEventRouter::PluginEventRouterClient { |
+ public: |
+ |
+ struct ProvidedFilesystemInfo{ |
+ ProvidedFilesystemInfo(); |
+ std::string filesystem_id; |
+ std::string display_name; |
+ std::string plugin_name; |
+ bool writable; |
+ int32_t opened_files_limit; |
+ }; |
+ struct ShmBuffer { |
+ ShmBuffer(uint32_t size, scoped_ptr<base::SharedMemory> shm); |
+ ~ShmBuffer(); |
+ uint32_t size; |
+ scoped_ptr<base::SharedMemory> shm; |
+ }; |
+ // Waiting room for shared memory |
+ class ShmChannelSynchronizer{ |
+ public: |
+ typedef base::Callback<bool(scoped_ptr<base::ListValue>)> |
+ FlushRequestCallback; |
+ ShmChannelSynchronizer( uint32_t size, FlushRequestCallback callback ); |
+ ~ShmChannelSynchronizer(); |
+ // This will discard the request if no room is found |
+ bool EnqueueRequest(scoped_ptr<base::ListValue> response); |
+ bool PushNextRequest(); |
+ bool AckLastPushedRequest(); |
+ private: |
+ uint32_t size(); |
+ uint32_t max_size; |
+ ScopedVector<base::ListValue> replies; |
+ bool ready; |
+ FlushRequestCallback callback; |
+ }; |
+ public: |
+ // Creates a new PepperFilesystemProviderBackendChromeOS |
+ PepperFilesystemProviderBackendChromeOS(content::BrowserPpapiHost *host, |
+ PP_Instance, PP_Resource); |
+ ~PepperFilesystemProviderBackendChromeOS()override; |
+ |
+ private: |
+ typedef base::Callback< |
+ void(PP_OperationType_Dev, scoped_ptr<base::ListValue> event_args)> |
+ DispatchEventImplCallback; |
+ typedef std::map< |
+ std::string,std::pair< DispatchEventImplCallback, PP_OperationType_Dev>> |
+ ListOfHandlers; |
+ typedef ListOfHandlers::iterator ListOfHandlersIterator; |
+ |
+ // Handles the mount requests from plugins |
+ int32_t SendMountRequest( |
+ ppapi::host::HostMessageContext *context, |
+ const base::ListValue& |
+ /*std::string fsid, |
+ std::string display_name, |
+ bool writable, |
+ int32_t opened_files_limit*/)override; |
+ // Handles unmount requests from plugins |
+ int32_t SendUnmountRequest( |
+ ppapi::host::HostMessageContext* context, |
+ std::string fsid )override; |
+ // Handles plugin notifications. These are responses to browser request |
+ int32_t OnPluginResponse(ppapi::host::HostMessageContext *context, |
+ const base::ListValue &)override; |
+ int32_t OnPluginWriteAck(ppapi::host::HostMessageContext *context)override; |
+ // Helper Functions that register desired events with |
+ // the PluginEventRouter |
+ void RegisterFilesystemEventListeners(); |
+ void UnregisterFilesystemEventListeners(); |
+ |
+ // The next 2 functions are for the mount logic |
+ static base::File::Error RegisterFilesystemOnUI( |
+ ProvidedFilesystemInfo filesystem_info); |
+ void MountReplyOnIO( |
+ ppapi::host::ReplyMessageContext reply_msg, |
+ ProvidedFilesystemInfo filesystem_info, |
+ base::File::Error err ); |
+ // The next 2 functions are for the unmount logic |
+ static base::File::Error UnregisterFilesystemOnUI( |
+ ProvidedFilesystemInfo filesystem_info); |
+ void UnmountReplyOnIO( |
+ ppapi::host::ReplyMessageContext reply_msg, |
+ base::File::Error err ); |
+ |
+ // PluginEventRouterClient interface |
+ void OnDispatchEvent( |
+ std::string event_name, |
+ scoped_ptr<base::ListValue> event_args)override; |
+ |
+ // Dispatchers of messages to plugin |
+ void SendOperationRequestToPlugin( |
+ PP_OperationType_Dev operation_type, |
+ scoped_ptr<base::ListValue>event_args ); |
+ void SendWriteRequestToPlugin( |
+ PP_OperationType_Dev operation_type, |
+ scoped_ptr<base::ListValue> event_args ); |
+ |
+ // Composes success messages that are expected |
+ // by the filesystem backend |
+ static int32_t OnGeneralSuccessResponse(int operation, |
+ ProvidedFilesystemInfo filesystem_info, |
+ scoped_ptr<base::ListValue> event_args); |
+ // Composes error messages that are expected |
+ // by the filesystem backend |
+ static int32_t OnGeneralErrorResponse( |
+ ProvidedFilesystemInfo filesystem_info, |
+ scoped_ptr<base::ListValue> event_args); |
+ |
+ bool FlushRequest(scoped_ptr<base::ListValue> request); |
+ |
+ // Initializes the shared memory buffer and notifies the plugin |
+ bool InitializeMemoryBuffer( ); |
+ // Replaces a defined slot inside the list with a copied chunk |
+ // from shared memory |
+ bool AddFromSharedMemoryToMessage(base::ListValue& message); |
+ // Extracts from the message a defined slot from inside the list |
+ // and places it in memory. |
+ bool AddFromMessageToSharedMemory(base::ListValue& message); |
+ // The filesystem info |
+ ProvidedFilesystemInfo filesystem_info_; |
+ // Flag for status |
+ bool mounted_; |
+ // A map that holds callbacks for every type of events |
+ ListOfHandlers handlers_list_; |
+ // All events that a plugin listens for |
+ std::vector<std::string> events_; |
+ // A shared memory buffer that has 2 parts |
+ // 1st: Read Buffer - kReaderBufferSize |
+ // 2nd: Write Buffer - kWriterBufferSize |
+ scoped_ptr<ShmBuffer> read_write_buffer_; |
+ // Not owned. These are owned by the parent ResourceHost |
+ ppapi::host::PpapiHost* host_; |
+ PP_Resource resource_; |
+ scoped_ptr<ShmChannelSynchronizer> write_channel_controller_; |
+ // Sabin Remove this |
+ std::chrono::time_point<std::chrono::system_clock> time_stamp_; |
+ base::WeakPtrFactory<PepperFilesystemProviderBackendChromeOS> weak_factory_; |
+ DISALLOW_COPY_AND_ASSIGN(PepperFilesystemProviderBackendChromeOS); |
+}; |
+ |
+struct MountOperationTranslator{ |
+ MountOperationTranslator(){} |
+ ~MountOperationTranslator(){} |
+ |
+ static scoped_ptr<MountOperationTranslator> PopulateFromResponse( |
+ const base::ListValue& request); |
+ // The filesystem identifier of the filesystem related to this operation. |
+ std::string file_system_id; |
+ // The display name for the filesystem |
+ std::string display_name; |
+ // A flag that indicates if the filesystem is writable or not |
+ bool writable; |
+ // The opened files limit indicator. If 0 there is no file limit |
+ int opened_files_limit; |
+}; |
+} // content namespace |
+ |
+#endif // PEPPER_FILESYSTEM_PROVIDER_HOST_H |
+ |