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

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

Issue 23819033: Simplify PPB_NetworkMonitor proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
(Empty)
1 // Copyright 2013 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
5 #include "ppapi/proxy/network_monitor_resource.h"
6
7 #include "ppapi/proxy/dispatch_reply_message.h"
8 #include "ppapi/proxy/ppapi_messages.h"
9 #include "ppapi/thunk/enter.h"
10 #include "ppapi/thunk/ppb_network_monitor_api.h"
11
12 namespace ppapi {
13 namespace proxy {
14
15 NetworkMonitorResource::NetworkMonitorResource(Connection connection,
16 PP_Instance instance)
17 : PluginResource(connection, instance),
18 initial_list_sent_(false),
19 forbidden_(false) {
yzshen1 2013/09/11 22:51:26 Please also init the PP_Resource* member, too.
Sergey Ulanov 2013/09/12 07:01:51 Done.
20 SendCreate(BROWSER, PpapiHostMsg_NetworkMonitor_Create());
21 }
22
23 NetworkMonitorResource::~NetworkMonitorResource() {}
24
25 ppapi::thunk::PPB_NetworkMonitor_API*
26 NetworkMonitorResource::AsPPB_NetworkMonitor_API() {
27 return this;
28 }
29
30 void NetworkMonitorResource::OnReplyReceived(
31 const ResourceMessageReplyParams& params,
32 const IPC::Message& msg) {
33 IPC_BEGIN_MESSAGE_MAP(NetworkMonitorResource, msg)
34 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
35 PpapiMsg_NetworkMonitor_NetworkList, OnPluginMsgNetworkList)
36 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_0(
37 PpapiMsg_NetworkMonitor_Forbidden, OnPluginMsgForbidden)
38 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(
39 PluginResource::OnReplyReceived(params, msg))
40 IPC_END_MESSAGE_MAP()
41 }
42
43 int32_t NetworkMonitorResource::UpdateNetworkList(
44 PP_Resource* network_list,
yzshen1 2013/09/11 22:51:26 wrong indent.
Sergey Ulanov 2013/09/12 07:01:51 Done.
45 scoped_refptr<TrackedCallback> callback) {
46 if (!network_list)
47 return PP_ERROR_BADARGUMENT;
48 if (TrackedCallback::IsPending(update_callback_))
49 return PP_ERROR_INPROGRESS;
50 if (forbidden_)
51 return PP_ERROR_NOACCESS;
52
53 if (current_list_ && !initial_list_sent_) {
54 initial_list_sent_ = true;
55 thunk::EnterResourceCreationNoLock enter(pp_instance());
yzshen1 2013/09/11 22:51:26 You don't need this line, right? |enter| is never
Sergey Ulanov 2013/09/12 07:01:51 Done.
56 *network_list = PPB_NetworkList_Private_Shared::Create(
yzshen1 2013/09/11 22:51:26 You could also make changes to PPB_NetworkList_Pri
Sergey Ulanov 2013/09/12 07:01:51 Yes. Good point. I moved it to this directory, and
57 OBJECT_IS_PROXY, pp_instance(), current_list_);
58 return PP_OK;
59 }
60
61 network_list_ = network_list;
62 update_callback_ = callback;
63 return PP_OK_COMPLETIONPENDING;
64 }
65
66 void NetworkMonitorResource::OnPluginMsgNetworkList(
67 const ResourceMessageReplyParams& params,
68 const NetworkList& list) {
69 current_list_ = new NetworkListStorage(list);
70
71 if (TrackedCallback::IsPending(update_callback_)) {
72 initial_list_sent_ = true;
73 {
74 thunk::EnterResourceCreationNoLock enter(pp_instance());
yzshen1 2013/09/11 22:51:26 This line is not needed.
Sergey Ulanov 2013/09/12 07:01:51 Done.
75 *network_list_ = PPB_NetworkList_Private_Shared::Create(
76 OBJECT_IS_PROXY, pp_instance(), current_list_);
77 network_list_ = NULL;
78 }
79 update_callback_->Run(PP_OK);
80 }
81 }
82
83 void NetworkMonitorResource::OnPluginMsgForbidden(
yzshen1 2013/09/11 22:51:26 This message is not needed, |params| has a result
Sergey Ulanov 2013/09/12 07:01:51 I don't see way to set the result filed when using
yzshen1 2013/09/13 17:47:10 Right. SendUnsolicitedReply() doesn't have params.
84 const ResourceMessageReplyParams& params) {
85 forbidden_ = true;
86
87 if (TrackedCallback::IsPending(update_callback_)) {
88 initial_list_sent_ = true;
89 update_callback_->Run(PP_ERROR_NOACCESS);
90 }
91 }
92
93 } // namespace proxy
94 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698