Index: ppapi/proxy/network_monitor_resource.cc |
diff --git a/ppapi/proxy/network_monitor_resource.cc b/ppapi/proxy/network_monitor_resource.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..daa7e39975a2753c664258b6eb217656079413e3 |
--- /dev/null |
+++ b/ppapi/proxy/network_monitor_resource.cc |
@@ -0,0 +1,94 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ppapi/proxy/network_monitor_resource.h" |
+ |
+#include "ppapi/proxy/dispatch_reply_message.h" |
+#include "ppapi/proxy/ppapi_messages.h" |
+#include "ppapi/thunk/enter.h" |
+#include "ppapi/thunk/ppb_network_monitor_api.h" |
+ |
+namespace ppapi { |
+namespace proxy { |
+ |
+NetworkMonitorResource::NetworkMonitorResource(Connection connection, |
+ PP_Instance instance) |
+ : PluginResource(connection, instance), |
+ initial_list_sent_(false), |
+ 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.
|
+ SendCreate(BROWSER, PpapiHostMsg_NetworkMonitor_Create()); |
+} |
+ |
+NetworkMonitorResource::~NetworkMonitorResource() {} |
+ |
+ppapi::thunk::PPB_NetworkMonitor_API* |
+NetworkMonitorResource::AsPPB_NetworkMonitor_API() { |
+ return this; |
+} |
+ |
+void NetworkMonitorResource::OnReplyReceived( |
+ const ResourceMessageReplyParams& params, |
+ const IPC::Message& msg) { |
+ IPC_BEGIN_MESSAGE_MAP(NetworkMonitorResource, msg) |
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( |
+ PpapiMsg_NetworkMonitor_NetworkList, OnPluginMsgNetworkList) |
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_0( |
+ PpapiMsg_NetworkMonitor_Forbidden, OnPluginMsgForbidden) |
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( |
+ PluginResource::OnReplyReceived(params, msg)) |
+ IPC_END_MESSAGE_MAP() |
+} |
+ |
+int32_t NetworkMonitorResource::UpdateNetworkList( |
+ PP_Resource* network_list, |
yzshen1
2013/09/11 22:51:26
wrong indent.
Sergey Ulanov
2013/09/12 07:01:51
Done.
|
+ scoped_refptr<TrackedCallback> callback) { |
+ if (!network_list) |
+ return PP_ERROR_BADARGUMENT; |
+ if (TrackedCallback::IsPending(update_callback_)) |
+ return PP_ERROR_INPROGRESS; |
+ if (forbidden_) |
+ return PP_ERROR_NOACCESS; |
+ |
+ if (current_list_ && !initial_list_sent_) { |
+ initial_list_sent_ = true; |
+ 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.
|
+ *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
|
+ OBJECT_IS_PROXY, pp_instance(), current_list_); |
+ return PP_OK; |
+ } |
+ |
+ network_list_ = network_list; |
+ update_callback_ = callback; |
+ return PP_OK_COMPLETIONPENDING; |
+} |
+ |
+void NetworkMonitorResource::OnPluginMsgNetworkList( |
+ const ResourceMessageReplyParams& params, |
+ const NetworkList& list) { |
+ current_list_ = new NetworkListStorage(list); |
+ |
+ if (TrackedCallback::IsPending(update_callback_)) { |
+ initial_list_sent_ = true; |
+ { |
+ 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.
|
+ *network_list_ = PPB_NetworkList_Private_Shared::Create( |
+ OBJECT_IS_PROXY, pp_instance(), current_list_); |
+ network_list_ = NULL; |
+ } |
+ update_callback_->Run(PP_OK); |
+ } |
+} |
+ |
+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.
|
+ const ResourceMessageReplyParams& params) { |
+ forbidden_ = true; |
+ |
+ if (TrackedCallback::IsPending(update_callback_)) { |
+ initial_list_sent_ = true; |
+ update_callback_->Run(PP_ERROR_NOACCESS); |
+ } |
+} |
+ |
+} // namespace proxy |
+} // namespace ppapi |