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/dev/ppb_file_system_dev.h" | 9 #include "ppapi/c/dev/ppb_file_system_dev.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 // querying. It's all set in the constructor from the "create info" sent from | 21 // querying. It's all set in the constructor from the "create info" sent from |
22 // the host. | 22 // the host. |
23 class FileSystem : public PluginResource { | 23 class FileSystem : public PluginResource { |
24 public: | 24 public: |
25 FileSystem(const HostResource& host_resource, PP_FileSystemType_Dev type); | 25 FileSystem(const HostResource& host_resource, PP_FileSystemType_Dev type); |
26 virtual ~FileSystem(); | 26 virtual ~FileSystem(); |
27 | 27 |
28 virtual FileSystem* AsFileSystem(); | 28 virtual FileSystem* AsFileSystem(); |
29 | 29 |
30 PP_FileSystemType_Dev type_; | 30 PP_FileSystemType_Dev type_; |
31 bool opened_; | 31 bool called_open_; |
32 PP_CompletionCallback current_open_callback_; | 32 PP_CompletionCallback current_open_callback_; |
33 | 33 |
34 private: | 34 private: |
35 DISALLOW_COPY_AND_ASSIGN(FileSystem); | 35 DISALLOW_COPY_AND_ASSIGN(FileSystem); |
36 }; | 36 }; |
37 | 37 |
38 FileSystem::FileSystem(const HostResource& host_resource, | 38 FileSystem::FileSystem(const HostResource& host_resource, |
39 PP_FileSystemType_Dev type) | 39 PP_FileSystemType_Dev type) |
40 : PluginResource(host_resource), | 40 : PluginResource(host_resource), |
41 type_(type), | 41 type_(type), |
42 opened_(false), | 42 called_open_(false), |
43 current_open_callback_(PP_MakeCompletionCallback(NULL, NULL)) { | 43 current_open_callback_(PP_MakeCompletionCallback(NULL, NULL)) { |
44 } | 44 } |
45 | 45 |
46 // TODO(brettw) this logic is duplicated with some other resource objects | 46 // TODO(brettw) this logic is duplicated with some other resource objects |
47 // like FileChooser. It would be nice to look at all of the different resources | 47 // like FileChooser. It would be nice to look at all of the different resources |
48 // that need callback tracking and design something that they can all re-use. | 48 // that need callback tracking and design something that they can all re-use. |
49 FileSystem::~FileSystem() { | 49 FileSystem::~FileSystem() { |
50 // Ensure the callback is always fired. | 50 // Ensure the callback is always fired. |
51 if (current_open_callback_.func) { | 51 if (current_open_callback_.func) { |
52 // TODO(brettw) the callbacks at this level should be refactored with a | 52 // TODO(brettw) the callbacks at this level should be refactored with a |
(...skipping 29 matching lines...) Expand all Loading... |
82 FileSystem* object = PluginResource::GetAs<FileSystem>(resource); | 82 FileSystem* object = PluginResource::GetAs<FileSystem>(resource); |
83 return BoolToPPBool(!!object); | 83 return BoolToPPBool(!!object); |
84 } | 84 } |
85 | 85 |
86 int32_t Open(PP_Resource file_system, | 86 int32_t Open(PP_Resource file_system, |
87 int64_t expected_size, | 87 int64_t expected_size, |
88 struct PP_CompletionCallback callback) { | 88 struct PP_CompletionCallback callback) { |
89 FileSystem* object = PluginResource::GetAs<FileSystem>(file_system); | 89 FileSystem* object = PluginResource::GetAs<FileSystem>(file_system); |
90 if (!object) | 90 if (!object) |
91 return PP_ERROR_BADRESOURCE; | 91 return PP_ERROR_BADRESOURCE; |
92 if (object->opened_) | |
93 return PP_OK; | |
94 | 92 |
95 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance()); | 93 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance()); |
96 if (!dispatcher) | 94 if (!dispatcher) |
97 return PP_ERROR_BADARGUMENT; | 95 return PP_ERROR_BADARGUMENT; |
98 | 96 |
99 if (object->current_open_callback_.func) | 97 if (object->current_open_callback_.func) |
100 return PP_ERROR_INPROGRESS; | 98 return PP_ERROR_INPROGRESS; |
| 99 else if (object->called_open_) |
| 100 return PP_ERROR_FAILED; |
| 101 |
101 object->current_open_callback_ = callback; | 102 object->current_open_callback_ = callback; |
| 103 object->called_open_ = true; |
102 | 104 |
103 dispatcher->Send(new PpapiHostMsg_PPBFileSystem_Open( | 105 dispatcher->Send(new PpapiHostMsg_PPBFileSystem_Open( |
104 INTERFACE_ID_PPB_FILE_SYSTEM, object->host_resource(), expected_size)); | 106 INTERFACE_ID_PPB_FILE_SYSTEM, object->host_resource(), expected_size)); |
105 return PP_ERROR_WOULDBLOCK; | 107 return PP_ERROR_WOULDBLOCK; |
106 } | 108 } |
107 | 109 |
108 PP_FileSystemType_Dev GetType(PP_Resource resource) { | 110 PP_FileSystemType_Dev GetType(PP_Resource resource) { |
109 FileSystem* object = PluginResource::GetAs<FileSystem>(resource); | 111 FileSystem* object = PluginResource::GetAs<FileSystem>(resource); |
110 if (!object) | 112 if (!object) |
111 return PP_FILESYSTEMTYPE_INVALID; | 113 return PP_FILESYSTEMTYPE_INVALID; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 197 |
196 void PPB_FileSystem_Proxy::OpenCompleteInHost( | 198 void PPB_FileSystem_Proxy::OpenCompleteInHost( |
197 int32_t result, | 199 int32_t result, |
198 const HostResource& host_resource) { | 200 const HostResource& host_resource) { |
199 dispatcher()->Send(new PpapiMsg_PPBFileSystem_OpenComplete( | 201 dispatcher()->Send(new PpapiMsg_PPBFileSystem_OpenComplete( |
200 INTERFACE_ID_PPB_FILE_SYSTEM, host_resource, result)); | 202 INTERFACE_ID_PPB_FILE_SYSTEM, host_resource, result)); |
201 } | 203 } |
202 | 204 |
203 } // namespace proxy | 205 } // namespace proxy |
204 } // namespace pp | 206 } // namespace pp |
OLD | NEW |