Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 current_list_(0), | |
| 19 forbidden_(false), | |
| 20 network_list_(NULL) { | |
| 21 SendCreate(BROWSER, PpapiHostMsg_NetworkMonitor_Create()); | |
| 22 } | |
| 23 | |
| 24 NetworkMonitorResource::~NetworkMonitorResource() {} | |
| 25 | |
| 26 ppapi::thunk::PPB_NetworkMonitor_API* | |
| 27 NetworkMonitorResource::AsPPB_NetworkMonitor_API() { | |
| 28 return this; | |
| 29 } | |
| 30 | |
| 31 void NetworkMonitorResource::OnReplyReceived( | |
| 32 const ResourceMessageReplyParams& params, | |
| 33 const IPC::Message& msg) { | |
| 34 IPC_BEGIN_MESSAGE_MAP(NetworkMonitorResource, msg) | |
| 35 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( | |
| 36 PpapiMsg_NetworkMonitor_NetworkList, OnPluginMsgNetworkList) | |
| 37 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_0( | |
| 38 PpapiMsg_NetworkMonitor_Forbidden, OnPluginMsgForbidden) | |
| 39 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( | |
| 40 PluginResource::OnReplyReceived(params, msg)) | |
| 41 IPC_END_MESSAGE_MAP() | |
| 42 } | |
| 43 | |
| 44 int32_t NetworkMonitorResource::UpdateNetworkList( | |
| 45 PP_Resource* network_list, | |
| 46 scoped_refptr<TrackedCallback> callback) { | |
| 47 if (!network_list) | |
| 48 return PP_ERROR_BADARGUMENT; | |
| 49 if (TrackedCallback::IsPending(update_callback_)) | |
| 50 return PP_ERROR_INPROGRESS; | |
| 51 if (forbidden_) | |
| 52 return PP_ERROR_NOACCESS; | |
| 53 | |
| 54 if (current_list_.get()) { | |
| 55 *network_list = current_list_.Release(); | |
| 56 return PP_OK; | |
| 57 } | |
| 58 | |
| 59 network_list_ = network_list; | |
| 60 update_callback_ = callback; | |
| 61 return PP_OK_COMPLETIONPENDING; | |
| 62 } | |
| 63 | |
| 64 void NetworkMonitorResource::OnPluginMsgNetworkList( | |
| 65 const ResourceMessageReplyParams& params, | |
| 66 const NetworkList& list) { | |
| 67 current_list_ = ScopedPPResource( | |
| 68 new NetworkListResource(OBJECT_IS_PROXY, pp_instance(), list)); | |
| 69 | |
| 70 if (TrackedCallback::IsPending(update_callback_)) { | |
| 71 *network_list_ = current_list_.Release(); | |
| 72 update_callback_->Run(PP_OK); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 void NetworkMonitorResource::OnPluginMsgForbidden( | |
| 77 const ResourceMessageReplyParams& params) { | |
| 78 forbidden_ = true; | |
| 79 | |
| 80 if (TrackedCallback::IsPending(update_callback_)) { | |
|
yzshen1
2013/09/13 17:47:10
nit: no need to have {}
Sergey Ulanov
2013/09/13 18:35:00
Done.
| |
| 81 update_callback_->Run(PP_ERROR_NOACCESS); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 } // namespace proxy | |
| 86 } // namespace ppapi | |
| OLD | NEW |