OLD | NEW |
(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 PEPPER_FILESYSTEM_PROVIDER_HOST_H |
| 5 #define PEPPER_FILESYSTEM_PROVIDER_HOST_H |
| 6 |
| 7 #include <chrono> |
| 8 #include <queue> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "chrome/browser/chromeos/file_system_provider/file_system_plugin/plugin
_operation_router.h" |
| 16 #include "content/browser/renderer_host/pepper/pepper_filesystem_provider_host.h
" |
| 17 #include "content/common/content_export.h" |
| 18 #include "ppapi/c/dev/ppb_filesystemprovider_dev.h" |
| 19 #include "ppapi/c/pp_file_info.h" |
| 20 #include "ppapi/host/host_message_context.h" |
| 21 |
| 22 |
| 23 namespace content { |
| 24 |
| 25 class CONTENT_EXPORT PepperFilesystemProviderBackendChromeOS |
| 26 : public PepperFilesystemProviderBackend |
| 27 , public chromeos::file_system_provider:: |
| 28 PluginOperationRouter::PluginOperationRouterClient { |
| 29 public: |
| 30 |
| 31 struct ProvidedFilesystemInfo{ |
| 32 ProvidedFilesystemInfo(); |
| 33 std::string filesystem_id; |
| 34 std::string display_name; |
| 35 std::string plugin_name; |
| 36 bool writable; |
| 37 int32_t opened_files_limit; |
| 38 }; |
| 39 struct ShmBuffer { |
| 40 ShmBuffer(uint32_t size, scoped_ptr<base::SharedMemory> shm); |
| 41 ~ShmBuffer(); |
| 42 uint32_t size; |
| 43 scoped_ptr<base::SharedMemory> shm; |
| 44 }; |
| 45 // Waiting room for shared memory |
| 46 class ShmChannelController{ |
| 47 public: |
| 48 typedef base::Callback<bool(scoped_ptr<base::ListValue>)> |
| 49 FlushRequestCallback; |
| 50 ShmChannelController( uint32_t size, FlushRequestCallback callback ); |
| 51 ~ShmChannelController(); |
| 52 // This will discard the request if no room is found |
| 53 bool EnqueueRequest(scoped_ptr<base::ListValue> response); |
| 54 bool PushNextRequest(); |
| 55 bool AckLastPushedRequest(); |
| 56 private: |
| 57 uint32_t size(); |
| 58 uint32_t max_size; |
| 59 ScopedVector<base::ListValue> replies; |
| 60 bool ready; |
| 61 FlushRequestCallback callback; |
| 62 }; |
| 63 public: |
| 64 // Creates a new PepperFilesystemProviderBackendChromeOS |
| 65 PepperFilesystemProviderBackendChromeOS(content::BrowserPpapiHost *host, |
| 66 PP_Instance, PP_Resource); |
| 67 ~PepperFilesystemProviderBackendChromeOS()override; |
| 68 private: |
| 69 // Handles the mount requests from plugins |
| 70 int32_t SendMountRequest( |
| 71 ppapi::host::HostMessageContext *context, |
| 72 const base::ListValue& |
| 73 /*std::string fsid, |
| 74 std::string display_name, |
| 75 bool writable, |
| 76 int32_t opened_files_limit*/)override; |
| 77 // Handles unmount requests from plugins |
| 78 int32_t SendUnmountRequest( |
| 79 ppapi::host::HostMessageContext* context, |
| 80 const std::string& fsid )override; |
| 81 // Handles plugin notifications. These are responses to browser request |
| 82 int32_t OnPluginResponse(ppapi::host::HostMessageContext *context, |
| 83 const base::ListValue &)override; |
| 84 int32_t OnPluginWriteAck(ppapi::host::HostMessageContext *context)override; |
| 85 int32_t OnPluginNotification(ppapi::host::HostMessageContext *context, |
| 86 const base::ListValue &)override; |
| 87 // Helper Function to Send a notification to the backend |
| 88 static void SendNotificationOnUI(const ProvidedFilesystemInfo&, |
| 89 scoped_ptr<base::ListValue>); |
| 90 // Helper Functions that register desired events with |
| 91 // the PluginEventRouter |
| 92 void RegisterFilesystemListenedOperations(); |
| 93 void UnregisterFilesystemListenedOperations(); |
| 94 |
| 95 // The next 2 functions are for the mount logic |
| 96 static base::File::Error RegisterFilesystemOnUI( |
| 97 ProvidedFilesystemInfo filesystem_info); |
| 98 void MountReplyOnIO( |
| 99 ppapi::host::ReplyMessageContext reply_msg, |
| 100 ProvidedFilesystemInfo filesystem_info, |
| 101 base::File::Error err ); |
| 102 // The next 2 functions are for the unmount logic |
| 103 static base::File::Error UnregisterFilesystemOnUI( |
| 104 ProvidedFilesystemInfo filesystem_info); |
| 105 void UnmountReplyOnIO( |
| 106 ppapi::host::ReplyMessageContext reply_msg, |
| 107 base::File::Error err ); |
| 108 |
| 109 // PluginOperationsRouterClient interface |
| 110 void OnDispatchOperationRequest( |
| 111 chromeos::file_system_provider::RequestType, |
| 112 scoped_ptr<base::ListValue> request)override; |
| 113 |
| 114 // Composes success messages that are expected |
| 115 // by the filesystem backend |
| 116 static int32_t OnSuccessResponse(int operation, |
| 117 const ProvidedFilesystemInfo& filesystem_info, |
| 118 scoped_ptr<base::ListValue> response); |
| 119 // Composes error messages that are expected |
| 120 // by the filesystem backend |
| 121 static int32_t OnErrorResponse( |
| 122 const ProvidedFilesystemInfo& filesystem_info, |
| 123 scoped_ptr<base::ListValue> response); |
| 124 |
| 125 // Utility function that is used for inserting the request payload into |
| 126 // the shared memory and send it to the plugin |
| 127 bool FlushRequest(scoped_ptr<base::ListValue> request); |
| 128 // Initializes the shared memory buffer and notifies the plugin |
| 129 bool InitializeMemoryBuffer( ); |
| 130 // Replaces a defined slot inside the list with a copied chunk |
| 131 // from shared memory |
| 132 bool AddFromSharedMemoryToMessage(base::ListValue& message); |
| 133 // Extracts from the message a defined slot from inside the list |
| 134 // and places it in memory. |
| 135 bool AddFromMessageToSharedMemory(base::ListValue& message); |
| 136 // Removes a custom header that it's use to make the processing easier |
| 137 // and pre-processes the message |
| 138 bool PreprocessMessage(base::ListValue& message, |
| 139 bool& message_status, |
| 140 int& operation_type); |
| 141 void SendReadAck(); |
| 142 // The filesystem info |
| 143 ProvidedFilesystemInfo filesystem_info_; |
| 144 // Flag for status |
| 145 bool mounted_; |
| 146 // 1st: Read Buffer - kReaderBufferSize |
| 147 // 2nd: Write Buffer - kWriterBufferSize |
| 148 scoped_ptr<ShmBuffer> read_write_buffer_; |
| 149 // Not owned. These are owned by the parent ResourceHost |
| 150 ppapi::host::PpapiHost* host_; |
| 151 PP_Resource resource_; |
| 152 scoped_ptr<ShmChannelController> write_channel_controller_; |
| 153 // Sabin Remove this |
| 154 std::chrono::time_point<std::chrono::system_clock> time_stamp_; |
| 155 base::WeakPtrFactory<PepperFilesystemProviderBackendChromeOS> weak_factory_; |
| 156 DISALLOW_COPY_AND_ASSIGN(PepperFilesystemProviderBackendChromeOS); |
| 157 }; |
| 158 |
| 159 namespace filesystem_provider_internal { |
| 160 struct MountOperationTranslator{ |
| 161 MountOperationTranslator(){} |
| 162 ~MountOperationTranslator(){} |
| 163 |
| 164 static scoped_ptr<MountOperationTranslator> PopulateFromResponse( |
| 165 const base::ListValue& request); |
| 166 // The filesystem identifier of the filesystem related to this operation. |
| 167 std::string file_system_id; |
| 168 // The display name for the filesystem |
| 169 std::string display_name; |
| 170 // A flag that indicates if the filesystem is writable or not |
| 171 bool writable; |
| 172 // The opened files limit indicator. If 0 there is no file limit |
| 173 int opened_files_limit; |
| 174 }; |
| 175 } // namespace filesystem_provider_internal |
| 176 } // namespace content |
| 177 |
| 178 #endif // PEPPER_FILESYSTEM_PROVIDER_HOST_H |
| 179 |
OLD | NEW |