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

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

Issue 11106019: PluginResource: Avoid having two sets of similar methods for talking with browser and renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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
« no previous file with comments | « ppapi/proxy/plugin_resource.h ('k') | ppapi/proxy/printing_resource.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/plugin_resource.h" 5 #include "ppapi/proxy/plugin_resource.h"
6 6
7 #include "ppapi/proxy/ppapi_messages.h" 7 #include "ppapi/proxy/ppapi_messages.h"
8 #include "ppapi/proxy/resource_message_params.h"
9 8
10 namespace ppapi { 9 namespace ppapi {
11 namespace proxy { 10 namespace proxy {
12 11
13 PluginResource::PluginResource(Connection connection, PP_Instance instance) 12 PluginResource::PluginResource(Connection connection, PP_Instance instance)
14 : Resource(OBJECT_IS_PROXY, instance), 13 : Resource(OBJECT_IS_PROXY, instance),
15 connection_(connection), 14 connection_(connection),
16 next_sequence_number_(0), 15 next_sequence_number_(0),
17 sent_create_to_browser_(false), 16 sent_create_to_browser_(false),
18 sent_create_to_renderer_(false) { 17 sent_create_to_renderer_(false) {
(...skipping 17 matching lines...) Expand all
36 CallbackMap::iterator it = callbacks_.find(params.sequence()); 35 CallbackMap::iterator it = callbacks_.find(params.sequence());
37 if (it == callbacks_.end()) { 36 if (it == callbacks_.end()) {
38 DCHECK(false) << "Callback does not exist for an expected sequence number."; 37 DCHECK(false) << "Callback does not exist for an expected sequence number.";
39 } else { 38 } else {
40 scoped_refptr<PluginResourceCallbackBase> callback = it->second; 39 scoped_refptr<PluginResourceCallbackBase> callback = it->second;
41 callbacks_.erase(it); 40 callbacks_.erase(it);
42 callback->Run(params, msg); 41 callback->Run(params, msg);
43 } 42 }
44 } 43 }
45 44
46 void PluginResource::SendCreateToBrowser(const IPC::Message& msg) { 45 void PluginResource::SendCreate(Destination dest, const IPC::Message& msg) {
47 DCHECK(!sent_create_to_browser_); 46 if (dest == RENDERER) {
48 sent_create_to_browser_ = true; 47 DCHECK(!sent_create_to_renderer_);
49 ResourceMessageCallParams params(pp_resource(), 48 sent_create_to_renderer_ = true;
50 next_sequence_number_++); 49 } else {
51 connection_.browser_sender->Send( 50 DCHECK(!sent_create_to_browser_);
51 sent_create_to_browser_ = true;
52 }
53 ResourceMessageCallParams params(pp_resource(), next_sequence_number_++);
54 GetSender(dest)->Send(
52 new PpapiHostMsg_ResourceCreated(params, pp_instance(), msg)); 55 new PpapiHostMsg_ResourceCreated(params, pp_instance(), msg));
53 } 56 }
54 57
55 void PluginResource::SendCreateToRenderer(const IPC::Message& msg) { 58 void PluginResource::Post(Destination dest, const IPC::Message& msg) {
56 DCHECK(!sent_create_to_renderer_); 59 ResourceMessageCallParams params(pp_resource(), next_sequence_number_++);
57 sent_create_to_renderer_ = true; 60 SendResourceCall(dest, params, msg);
58 ResourceMessageCallParams params(pp_resource(),
59 next_sequence_number_++);
60 connection_.renderer_sender->Send(
61 new PpapiHostMsg_ResourceCreated(params, pp_instance(), msg));
62 }
63
64 void PluginResource::PostToBrowser(const IPC::Message& msg) {
65 ResourceMessageCallParams params(pp_resource(),
66 next_sequence_number_++);
67 SendResourceCall(connection_.browser_sender, params, msg);
68 }
69
70 void PluginResource::PostToRenderer(const IPC::Message& msg) {
71 ResourceMessageCallParams params(pp_resource(),
72 next_sequence_number_++);
73 SendResourceCall(connection_.renderer_sender, params, msg);
74 } 61 }
75 62
76 bool PluginResource::SendResourceCall( 63 bool PluginResource::SendResourceCall(
77 IPC::Sender* sender, 64 Destination dest,
78 const ResourceMessageCallParams& call_params, 65 const ResourceMessageCallParams& call_params,
79 const IPC::Message& nested_msg) { 66 const IPC::Message& nested_msg) {
80 return sender->Send(new PpapiHostMsg_ResourceCall(call_params, nested_msg)); 67 return GetSender(dest)->Send(
68 new PpapiHostMsg_ResourceCall(call_params, nested_msg));
81 } 69 }
82 70
83 int32_t PluginResource::GenericSyncCall(Destination dest, 71 int32_t PluginResource::GenericSyncCall(Destination dest,
84 const IPC::Message& msg, 72 const IPC::Message& msg,
85 IPC::Message* reply) { 73 IPC::Message* reply) {
86 ResourceMessageCallParams params(pp_resource(), 74 ResourceMessageCallParams params(pp_resource(), next_sequence_number_++);
87 next_sequence_number_++);
88 params.set_has_callback(); 75 params.set_has_callback();
89 ResourceMessageReplyParams reply_params; 76 ResourceMessageReplyParams reply_params;
90 bool success = GetSender(dest)->Send(new PpapiHostMsg_ResourceSyncCall( 77 bool success = GetSender(dest)->Send(new PpapiHostMsg_ResourceSyncCall(
91 params, msg, &reply_params, reply)); 78 params, msg, &reply_params, reply));
92 if (success) 79 if (success)
93 return reply_params.result(); 80 return reply_params.result();
94 return PP_ERROR_FAILED; 81 return PP_ERROR_FAILED;
95 } 82 }
96 83
97 } // namespace proxy 84 } // namespace proxy
98 } // namespace ppapi 85 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_resource.h ('k') | ppapi/proxy/printing_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698