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

Side by Side Diff: ppapi/proxy/ppb_file_chooser_proxy.cc

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
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_chooser_proxy.h" 5 #include "ppapi/proxy/ppb_file_chooser_proxy.h"
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "ppapi/c/dev/ppb_file_chooser_dev.h" 9 #include "ppapi/c/dev/ppb_file_chooser_dev.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/private/ppb_proxy_private.h" 11 #include "ppapi/c/private/ppb_proxy_private.h"
12 #include "ppapi/proxy/enter_proxy.h" 12 #include "ppapi/proxy/enter_proxy.h"
13 #include "ppapi/proxy/host_dispatcher.h" 13 #include "ppapi/proxy/host_dispatcher.h"
14 #include "ppapi/proxy/plugin_dispatcher.h" 14 #include "ppapi/proxy/plugin_dispatcher.h"
15 #include "ppapi/proxy/plugin_resource.h"
16 #include "ppapi/proxy/ppapi_messages.h" 15 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/proxy/ppb_file_ref_proxy.h" 16 #include "ppapi/proxy/ppb_file_ref_proxy.h"
18 #include "ppapi/proxy/serialized_var.h" 17 #include "ppapi/proxy/serialized_var.h"
19 #include "ppapi/thunk/thunk.h" 18 #include "ppapi/thunk/thunk.h"
20 19
21 using ppapi::HostResource; 20 using ppapi::HostResource;
21 using ppapi::Resource;
22 using ppapi::thunk::PPB_FileChooser_API; 22 using ppapi::thunk::PPB_FileChooser_API;
23 23
24 namespace pp { 24 namespace pp {
25 namespace proxy { 25 namespace proxy {
26 26
27 class FileChooser : public PluginResource, 27 class FileChooser : public Resource,
28 public PPB_FileChooser_API { 28 public PPB_FileChooser_API {
29 public: 29 public:
30 FileChooser(const HostResource& resource); 30 FileChooser(const HostResource& resource);
31 virtual ~FileChooser(); 31 virtual ~FileChooser();
32 32
33 // ResourceObjectBase overrides. 33 // Resource overrides.
34 virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; 34 virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE;
35 35
36 // PPB_FileChooser_API implementation. 36 // PPB_FileChooser_API implementation.
37 virtual int32_t Show(PP_CompletionCallback callback) OVERRIDE; 37 virtual int32_t Show(PP_CompletionCallback callback) OVERRIDE;
38 virtual PP_Resource GetNextChosenFile() OVERRIDE; 38 virtual PP_Resource GetNextChosenFile() OVERRIDE;
39 39
40 // Handles the choose complete notification from the host. 40 // Handles the choose complete notification from the host.
41 void ChooseComplete( 41 void ChooseComplete(
42 int32_t result_code, 42 int32_t result_code,
43 const std::vector<PPBFileRef_CreateInfo>& chosen_files); 43 const std::vector<PPBFileRef_CreateInfo>& chosen_files);
44 44
45 private: 45 private:
46 PP_CompletionCallback current_show_callback_; 46 PP_CompletionCallback current_show_callback_;
47 47
48 // All files returned by the current show callback that haven't yet been 48 // All files returned by the current show callback that haven't yet been
49 // given to the plugin. The plugin will repeatedly call us to get the next 49 // given to the plugin. The plugin will repeatedly call us to get the next
50 // file, and we'll vend those out of this queue, removing them when ownership 50 // file, and we'll vend those out of this queue, removing them when ownership
51 // has transferred to the plugin. 51 // has transferred to the plugin.
52 std::queue<PP_Resource> file_queue_; 52 std::queue<PP_Resource> file_queue_;
53 53
54 DISALLOW_COPY_AND_ASSIGN(FileChooser); 54 DISALLOW_COPY_AND_ASSIGN(FileChooser);
55 }; 55 };
56 56
57 FileChooser::FileChooser(const HostResource& resource) 57 FileChooser::FileChooser(const HostResource& resource)
58 : PluginResource(resource), 58 : Resource(resource),
59 current_show_callback_(PP_MakeCompletionCallback(NULL, NULL)) { 59 current_show_callback_(PP_MakeCompletionCallback(NULL, NULL)) {
60 } 60 }
61 61
62 FileChooser::~FileChooser() { 62 FileChooser::~FileChooser() {
63 // Always need to fire completion callbacks to prevent a leak in the plugin. 63 // Always need to fire completion callbacks to prevent a leak in the plugin.
64 if (current_show_callback_.func) { 64 if (current_show_callback_.func) {
65 // TODO(brettw) the callbacks at this level should be refactored with a 65 // TODO(brettw) the callbacks at this level should be refactored with a
66 // more automatic tracking system like we have in the renderer. 66 // more automatic tracking system like we have in the renderer.
67 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction( 67 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(
68 current_show_callback_.func, current_show_callback_.user_data, 68 current_show_callback_.func, current_show_callback_.user_data,
(...skipping 11 matching lines...) Expand all
80 80
81 PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() { 81 PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() {
82 return this; 82 return this;
83 } 83 }
84 84
85 int32_t FileChooser::Show(PP_CompletionCallback callback) { 85 int32_t FileChooser::Show(PP_CompletionCallback callback) {
86 if (current_show_callback_.func) 86 if (current_show_callback_.func)
87 return PP_ERROR_INPROGRESS; // Can't show more than once. 87 return PP_ERROR_INPROGRESS; // Can't show more than once.
88 88
89 current_show_callback_ = callback; 89 current_show_callback_ = callback;
90 GetDispatcher()->Send(new PpapiHostMsg_PPBFileChooser_Show( 90 PluginDispatcher::GetForResource(this)->Send(
91 INTERFACE_ID_PPB_FILE_CHOOSER, host_resource())); 91 new PpapiHostMsg_PPBFileChooser_Show(
92 INTERFACE_ID_PPB_FILE_CHOOSER, host_resource()));
92 return PP_OK_COMPLETIONPENDING; 93 return PP_OK_COMPLETIONPENDING;
93 } 94 }
94 95
95 PP_Resource FileChooser::GetNextChosenFile() { 96 PP_Resource FileChooser::GetNextChosenFile() {
96 if (file_queue_.empty()) 97 if (file_queue_.empty())
97 return 0; 98 return 0;
98 99
99 // Return the next resource in the queue. These resource have already been 100 // Return the next resource in the queue. These resource have already been
100 // addrefed (they're currently owned by the FileChooser) and returning them 101 // addrefed (they're currently owned by the FileChooser) and returning them
101 // transfers ownership of that reference to the plugin. 102 // transfers ownership of that reference to the plugin.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 158
158 HostResource result; 159 HostResource result;
159 dispatcher->Send(new PpapiHostMsg_PPBFileChooser_Create( 160 dispatcher->Send(new PpapiHostMsg_PPBFileChooser_Create(
160 INTERFACE_ID_PPB_FILE_CHOOSER, instance, 161 INTERFACE_ID_PPB_FILE_CHOOSER, instance,
161 options->mode, 162 options->mode,
162 options->accept_mime_types ? options->accept_mime_types : std::string(), 163 options->accept_mime_types ? options->accept_mime_types : std::string(),
163 &result)); 164 &result));
164 165
165 if (result.is_null()) 166 if (result.is_null())
166 return 0; 167 return 0;
167 return PluginResourceTracker::GetInstance()->AddResource( 168 return (new FileChooser(result))->GetReference();
168 new FileChooser(result));
169 } 169 }
170 170
171 bool PPB_FileChooser_Proxy::OnMessageReceived(const IPC::Message& msg) { 171 bool PPB_FileChooser_Proxy::OnMessageReceived(const IPC::Message& msg) {
172 bool handled = true; 172 bool handled = true;
173 IPC_BEGIN_MESSAGE_MAP(PPB_FileChooser_Proxy, msg) 173 IPC_BEGIN_MESSAGE_MAP(PPB_FileChooser_Proxy, msg)
174 // Plugin -> host messages. 174 // Plugin -> host messages.
175 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileChooser_Create, OnMsgCreate) 175 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileChooser_Create, OnMsgCreate)
176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileChooser_Show, OnMsgShow) 176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileChooser_Show, OnMsgShow)
177 177
178 // Host -> plugin messages. 178 // Host -> plugin messages.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 files.push_back(cur_create_info); 233 files.push_back(cur_create_info);
234 } 234 }
235 } 235 }
236 236
237 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete( 237 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete(
238 INTERFACE_ID_PPB_FILE_CHOOSER, chooser, result, files)); 238 INTERFACE_ID_PPB_FILE_CHOOSER, chooser, result, files));
239 } 239 }
240 240
241 } // namespace proxy 241 } // namespace proxy
242 } // namespace pp 242 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698