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

Side by Side Diff: content/browser/renderer_host/pepper/pepper_filesystem_provider_backend_chromeos.h

Issue 1093383002: [WIP] Provided file system from NACL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Various cleanups Created 5 years, 6 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
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 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 eventrouter.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 namespace content {
23
24 class CONTENT_EXPORT PepperFilesystemProviderBackendChromeOS
25 : public PepperFilesystemProviderBackend
26 , public chromeos::PluginEventRouter::PluginEventRouterClient {
27 public:
28
29 struct ProvidedFilesystemInfo{
30 ProvidedFilesystemInfo();
31 std::string filesystem_id;
32 std::string display_name;
33 std::string plugin_name;
34 bool writable;
35 int32_t opened_files_limit;
36 };
37 struct ShmBuffer {
38 ShmBuffer(uint32_t size, scoped_ptr<base::SharedMemory> shm);
39 ~ShmBuffer();
40 uint32_t size;
41 scoped_ptr<base::SharedMemory> shm;
42 };
43 // Waiting room for shared memory
44 class ShmChannelSynchronizer{
45 public:
46 typedef base::Callback<bool(scoped_ptr<base::ListValue>)>
47 FlushRequestCallback;
48 ShmChannelSynchronizer( uint32_t size, FlushRequestCallback callback );
49 ~ShmChannelSynchronizer();
50 // This will discard the request if no room is found
51 bool EnqueueRequest(scoped_ptr<base::ListValue> response);
52 bool PushNextRequest();
53 bool AckLastPushedRequest();
54 private:
55 uint32_t size();
56 uint32_t max_size;
57 ScopedVector<base::ListValue> replies;
58 bool ready;
59 FlushRequestCallback callback;
60 };
61 public:
62 // Creates a new PepperFilesystemProviderBackendChromeOS
63 PepperFilesystemProviderBackendChromeOS(content::BrowserPpapiHost *host,
64 PP_Instance, PP_Resource);
65 ~PepperFilesystemProviderBackendChromeOS()override;
66
67 private:
68 typedef base::Callback<
69 void(PP_OperationType_Dev, scoped_ptr<base::ListValue> event_args)>
70 DispatchEventImplCallback;
71 typedef std::map<
72 std::string,std::pair< DispatchEventImplCallback, PP_OperationType_Dev>>
73 ListOfHandlers;
74 typedef ListOfHandlers::iterator ListOfHandlersIterator;
75
76 // Handles the mount requests from plugins
77 int32_t SendMountRequest(
78 ppapi::host::HostMessageContext *context,
79 const base::ListValue&
80 /*std::string fsid,
81 std::string display_name,
82 bool writable,
83 int32_t opened_files_limit*/)override;
84 // Handles unmount requests from plugins
85 int32_t SendUnmountRequest(
86 ppapi::host::HostMessageContext* context,
87 std::string fsid )override;
88 // Handles plugin notifications. These are responses to browser request
89 int32_t OnPluginResponse(ppapi::host::HostMessageContext *context,
90 const base::ListValue &)override;
91 int32_t OnPluginWriteAck(ppapi::host::HostMessageContext *context)override;
92 // Helper Functions that register desired events with
93 // the PluginEventRouter
94 void RegisterFilesystemEventListeners();
95 void UnregisterFilesystemEventListeners();
96
97 // The next 2 functions are for the mount logic
98 static base::File::Error RegisterFilesystemOnUI(
99 ProvidedFilesystemInfo filesystem_info);
100 void MountReplyOnIO(
101 ppapi::host::ReplyMessageContext reply_msg,
102 ProvidedFilesystemInfo filesystem_info,
103 base::File::Error err );
104 // The next 2 functions are for the unmount logic
105 static base::File::Error UnregisterFilesystemOnUI(
106 ProvidedFilesystemInfo filesystem_info);
107 void UnmountReplyOnIO(
108 ppapi::host::ReplyMessageContext reply_msg,
109 base::File::Error err );
110
111 // PluginEventRouterClient interface
112 void OnDispatchEvent(
113 std::string event_name,
114 scoped_ptr<base::ListValue> event_args)override;
115
116 // Dispatchers of messages to plugin
117 void SendOperationRequestToPlugin(
118 PP_OperationType_Dev operation_type,
119 scoped_ptr<base::ListValue>event_args );
120 void SendWriteRequestToPlugin(
121 PP_OperationType_Dev operation_type,
122 scoped_ptr<base::ListValue> event_args );
123
124 // Composes success messages that are expected
125 // by the filesystem backend
126 static int32_t OnGeneralSuccessResponse(int operation,
127 ProvidedFilesystemInfo filesystem_info,
128 scoped_ptr<base::ListValue> event_args);
129 // Composes error messages that are expected
130 // by the filesystem backend
131 static int32_t OnGeneralErrorResponse(
132 ProvidedFilesystemInfo filesystem_info,
133 scoped_ptr<base::ListValue> event_args);
134
135 bool FlushRequest(scoped_ptr<base::ListValue> request);
136
137 // Initializes the shared memory buffer and notifies the plugin
138 bool InitializeMemoryBuffer( );
139 // Replaces a defined slot inside the list with a copied chunk
140 // from shared memory
141 bool AddFromSharedMemoryToMessage(base::ListValue& message);
142 // Extracts from the message a defined slot from inside the list
143 // and places it in memory.
144 bool AddFromMessageToSharedMemory(base::ListValue& message);
145 // The filesystem info
146 ProvidedFilesystemInfo filesystem_info_;
147 // Flag for status
148 bool mounted_;
149 // A map that holds callbacks for every type of events
150 ListOfHandlers handlers_list_;
151 // All events that a plugin listens for
152 std::vector<std::string> events_;
153 // A shared memory buffer that has 2 parts
154 // 1st: Read Buffer - kReaderBufferSize
155 // 2nd: Write Buffer - kWriterBufferSize
156 scoped_ptr<ShmBuffer> read_write_buffer_;
157 // Not owned. These are owned by the parent ResourceHost
158 ppapi::host::PpapiHost* host_;
159 PP_Resource resource_;
160 scoped_ptr<ShmChannelSynchronizer> write_channel_controller_;
161 // Sabin Remove this
162 std::chrono::time_point<std::chrono::system_clock> time_stamp_;
163 base::WeakPtrFactory<PepperFilesystemProviderBackendChromeOS> weak_factory_;
164 DISALLOW_COPY_AND_ASSIGN(PepperFilesystemProviderBackendChromeOS);
165 };
166
167 struct MountOperationTranslator{
168 MountOperationTranslator(){}
169 ~MountOperationTranslator(){}
170
171 static scoped_ptr<MountOperationTranslator> PopulateFromResponse(
172 const base::ListValue& request);
173 // The filesystem identifier of the filesystem related to this operation.
174 std::string file_system_id;
175 // The display name for the filesystem
176 std::string display_name;
177 // A flag that indicates if the filesystem is writable or not
178 bool writable;
179 // The opened files limit indicator. If 0 there is no file limit
180 int opened_files_limit;
181 };
182 } // content namespace
183
184 #endif // PEPPER_FILESYSTEM_PROVIDER_HOST_H
185
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698