OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppb_file_system_proxy.h" | 5 #include "ppapi/proxy/ppb_file_system_proxy.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/task.h" | 8 #include "base/task.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/ppb_file_system.h" | 10 #include "ppapi/c/ppb_file_system.h" |
11 #include "ppapi/proxy/enter_proxy.h" | 11 #include "ppapi/proxy/enter_proxy.h" |
12 #include "ppapi/proxy/host_dispatcher.h" | 12 #include "ppapi/proxy/host_dispatcher.h" |
13 #include "ppapi/proxy/plugin_dispatcher.h" | 13 #include "ppapi/proxy/plugin_dispatcher.h" |
14 #include "ppapi/proxy/plugin_resource.h" | |
15 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
16 #include "ppapi/proxy/serialized_var.h" | 15 #include "ppapi/proxy/serialized_var.h" |
17 #include "ppapi/thunk/enter.h" | 16 #include "ppapi/thunk/enter.h" |
18 #include "ppapi/thunk/ppb_file_system_api.h" | 17 #include "ppapi/thunk/ppb_file_system_api.h" |
19 #include "ppapi/thunk/resource_creation_api.h" | 18 #include "ppapi/thunk/resource_creation_api.h" |
20 #include "ppapi/thunk/thunk.h" | 19 #include "ppapi/thunk/thunk.h" |
21 | 20 |
22 using ppapi::HostResource; | 21 using ppapi::HostResource; |
| 22 using ppapi::Resource; |
23 using ppapi::thunk::EnterFunctionNoLock; | 23 using ppapi::thunk::EnterFunctionNoLock; |
24 using ppapi::thunk::PPB_FileSystem_API; | 24 using ppapi::thunk::PPB_FileSystem_API; |
25 using ppapi::thunk::ResourceCreationAPI; | 25 using ppapi::thunk::ResourceCreationAPI; |
26 | 26 |
27 namespace pp { | 27 namespace pp { |
28 namespace proxy { | 28 namespace proxy { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 InterfaceProxy* CreateFileSystemProxy(Dispatcher* dispatcher, | 32 InterfaceProxy* CreateFileSystemProxy(Dispatcher* dispatcher, |
33 const void* target_interface) { | 33 const void* target_interface) { |
34 return new PPB_FileSystem_Proxy(dispatcher, target_interface); | 34 return new PPB_FileSystem_Proxy(dispatcher, target_interface); |
35 } | 35 } |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 // This object maintains most of the state of the ref in the plugin for fast | 39 // This object maintains most of the state of the ref in the plugin for fast |
40 // querying. It's all set in the constructor from the "create info" sent from | 40 // querying. It's all set in the constructor from the "create info" sent from |
41 // the host. | 41 // the host. |
42 class FileSystem : public PluginResource, public PPB_FileSystem_API { | 42 class FileSystem : public Resource, public PPB_FileSystem_API { |
43 public: | 43 public: |
44 FileSystem(const HostResource& host_resource, PP_FileSystemType type); | 44 FileSystem(const HostResource& host_resource, PP_FileSystemType type); |
45 virtual ~FileSystem(); | 45 virtual ~FileSystem(); |
46 | 46 |
47 // ResourceObjectBase override. | 47 // Resource override. |
48 virtual PPB_FileSystem_API* AsPPB_FileSystem_API() OVERRIDE; | 48 virtual PPB_FileSystem_API* AsPPB_FileSystem_API() OVERRIDE; |
49 | 49 |
50 // PPB_FileSystem_APi implementation. | 50 // PPB_FileSystem_APi implementation. |
51 virtual int32_t Open(int64_t expected_size, | 51 virtual int32_t Open(int64_t expected_size, |
52 PP_CompletionCallback callback) OVERRIDE; | 52 PP_CompletionCallback callback) OVERRIDE; |
53 virtual PP_FileSystemType GetType() OVERRIDE; | 53 virtual PP_FileSystemType GetType() OVERRIDE; |
54 | 54 |
55 // Called when the host has responded to our open request. | 55 // Called when the host has responded to our open request. |
56 void OpenComplete(int32_t result); | 56 void OpenComplete(int32_t result); |
57 | 57 |
58 private: | 58 private: |
59 PP_FileSystemType type_; | 59 PP_FileSystemType type_; |
60 bool called_open_; | 60 bool called_open_; |
61 PP_CompletionCallback current_open_callback_; | 61 PP_CompletionCallback current_open_callback_; |
62 | 62 |
63 DISALLOW_COPY_AND_ASSIGN(FileSystem); | 63 DISALLOW_COPY_AND_ASSIGN(FileSystem); |
64 }; | 64 }; |
65 | 65 |
66 FileSystem::FileSystem(const HostResource& host_resource, | 66 FileSystem::FileSystem(const HostResource& host_resource, |
67 PP_FileSystemType type) | 67 PP_FileSystemType type) |
68 : PluginResource(host_resource), | 68 : Resource(host_resource), |
69 type_(type), | 69 type_(type), |
70 called_open_(false), | 70 called_open_(false), |
71 current_open_callback_(PP_MakeCompletionCallback(NULL, NULL)) { | 71 current_open_callback_(PP_MakeCompletionCallback(NULL, NULL)) { |
72 } | 72 } |
73 | 73 |
74 // TODO(brettw) this logic is duplicated with some other resource objects | 74 // TODO(brettw) this logic is duplicated with some other resource objects |
75 // like FileChooser. It would be nice to look at all of the different resources | 75 // like FileChooser. It would be nice to look at all of the different resources |
76 // that need callback tracking and design something that they can all re-use. | 76 // that need callback tracking and design something that they can all re-use. |
77 FileSystem::~FileSystem() { | 77 FileSystem::~FileSystem() { |
78 // Ensure the callback is always fired. | 78 // Ensure the callback is always fired. |
(...skipping 12 matching lines...) Expand all Loading... |
91 | 91 |
92 int32_t FileSystem::Open(int64_t expected_size, | 92 int32_t FileSystem::Open(int64_t expected_size, |
93 PP_CompletionCallback callback) { | 93 PP_CompletionCallback callback) { |
94 if (current_open_callback_.func) | 94 if (current_open_callback_.func) |
95 return PP_ERROR_INPROGRESS; | 95 return PP_ERROR_INPROGRESS; |
96 if (called_open_) | 96 if (called_open_) |
97 return PP_ERROR_FAILED; | 97 return PP_ERROR_FAILED; |
98 | 98 |
99 current_open_callback_ = callback; | 99 current_open_callback_ = callback; |
100 called_open_ = true; | 100 called_open_ = true; |
101 GetDispatcher()->Send(new PpapiHostMsg_PPBFileSystem_Open( | 101 PluginDispatcher::GetForResource(this)->Send( |
102 INTERFACE_ID_PPB_FILE_SYSTEM, host_resource(), expected_size)); | 102 new PpapiHostMsg_PPBFileSystem_Open( |
| 103 INTERFACE_ID_PPB_FILE_SYSTEM, host_resource(), expected_size)); |
103 return PP_OK_COMPLETIONPENDING; | 104 return PP_OK_COMPLETIONPENDING; |
104 } | 105 } |
105 | 106 |
106 PP_FileSystemType FileSystem::GetType() { | 107 PP_FileSystemType FileSystem::GetType() { |
107 return type_; | 108 return type_; |
108 } | 109 } |
109 | 110 |
110 void FileSystem::OpenComplete(int32_t result) { | 111 void FileSystem::OpenComplete(int32_t result) { |
111 PP_RunAndClearCompletionCallback(¤t_open_callback_, result); | 112 PP_RunAndClearCompletionCallback(¤t_open_callback_, result); |
112 } | 113 } |
(...skipping 24 matching lines...) Expand all Loading... |
137 PP_FileSystemType type) { | 138 PP_FileSystemType type) { |
138 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 139 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
139 if (!dispatcher) | 140 if (!dispatcher) |
140 return PP_ERROR_BADARGUMENT; | 141 return PP_ERROR_BADARGUMENT; |
141 | 142 |
142 HostResource result; | 143 HostResource result; |
143 dispatcher->Send(new PpapiHostMsg_PPBFileSystem_Create( | 144 dispatcher->Send(new PpapiHostMsg_PPBFileSystem_Create( |
144 INTERFACE_ID_PPB_FILE_SYSTEM, instance, type, &result)); | 145 INTERFACE_ID_PPB_FILE_SYSTEM, instance, type, &result)); |
145 if (result.is_null()) | 146 if (result.is_null()) |
146 return 0; | 147 return 0; |
147 | 148 return (new FileSystem(result, type))->GetReference(); |
148 return PluginResourceTracker::GetInstance()->AddResource( | |
149 new FileSystem(result, type)); | |
150 } | 149 } |
151 | 150 |
152 bool PPB_FileSystem_Proxy::OnMessageReceived(const IPC::Message& msg) { | 151 bool PPB_FileSystem_Proxy::OnMessageReceived(const IPC::Message& msg) { |
153 bool handled = true; | 152 bool handled = true; |
154 IPC_BEGIN_MESSAGE_MAP(PPB_FileSystem_Proxy, msg) | 153 IPC_BEGIN_MESSAGE_MAP(PPB_FileSystem_Proxy, msg) |
155 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileSystem_Create, OnMsgCreate) | 154 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileSystem_Create, OnMsgCreate) |
156 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileSystem_Open, OnMsgOpen) | 155 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileSystem_Open, OnMsgOpen) |
157 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileSystem_OpenComplete, OnMsgOpenComplete) | 156 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileSystem_OpenComplete, OnMsgOpenComplete) |
158 IPC_MESSAGE_UNHANDLED(handled = false) | 157 IPC_MESSAGE_UNHANDLED(handled = false) |
159 IPC_END_MESSAGE_MAP() | 158 IPC_END_MESSAGE_MAP() |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 191 |
193 void PPB_FileSystem_Proxy::OpenCompleteInHost( | 192 void PPB_FileSystem_Proxy::OpenCompleteInHost( |
194 int32_t result, | 193 int32_t result, |
195 const HostResource& host_resource) { | 194 const HostResource& host_resource) { |
196 dispatcher()->Send(new PpapiMsg_PPBFileSystem_OpenComplete( | 195 dispatcher()->Send(new PpapiMsg_PPBFileSystem_OpenComplete( |
197 INTERFACE_ID_PPB_FILE_SYSTEM, host_resource, result)); | 196 INTERFACE_ID_PPB_FILE_SYSTEM, host_resource, result)); |
198 } | 197 } |
199 | 198 |
200 } // namespace proxy | 199 } // namespace proxy |
201 } // namespace pp | 200 } // namespace pp |
OLD | NEW |