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.
5 #include "ppapi/proxy/network_monitor_resource.h"
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"
15 NetworkMonitorResource::NetworkMonitorResource(Connection connection
,
17 : PluginResource(connection
, instance
),
21 SendCreate(BROWSER
, PpapiHostMsg_NetworkMonitor_Create());
24 NetworkMonitorResource::~NetworkMonitorResource() {}
26 ppapi::thunk::PPB_NetworkMonitor_API
*
27 NetworkMonitorResource::AsPPB_NetworkMonitor_API() {
31 void NetworkMonitorResource::OnReplyReceived(
32 const ResourceMessageReplyParams
& params
,
33 const IPC::Message
& msg
) {
34 PPAPI_BEGIN_MESSAGE_MAP(NetworkMonitorResource
, msg
)
35 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
36 PpapiPluginMsg_NetworkMonitor_NetworkList
, OnPluginMsgNetworkList
)
37 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_0(
38 PpapiPluginMsg_NetworkMonitor_Forbidden
, OnPluginMsgForbidden
)
39 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(
40 PluginResource::OnReplyReceived(params
, msg
))
41 PPAPI_END_MESSAGE_MAP()
44 int32_t NetworkMonitorResource::UpdateNetworkList(
45 PP_Resource
* network_list
,
46 scoped_refptr
<TrackedCallback
> callback
) {
48 return PP_ERROR_BADARGUMENT
;
49 if (TrackedCallback::IsPending(update_callback_
))
50 return PP_ERROR_INPROGRESS
;
52 return PP_ERROR_NOACCESS
;
54 if (current_list_
.get()) {
55 *network_list
= current_list_
.Release();
59 network_list_
= network_list
;
60 update_callback_
= callback
;
61 return PP_OK_COMPLETIONPENDING
;
64 void NetworkMonitorResource::OnPluginMsgNetworkList(
65 const ResourceMessageReplyParams
& params
,
66 const SerializedNetworkList
& list
) {
67 current_list_
= ScopedPPResource(
68 new NetworkListResource(pp_instance(), list
));
70 if (TrackedCallback::IsPending(update_callback_
)) {
71 *network_list_
= current_list_
.Release();
72 update_callback_
->Run(PP_OK
);
76 void NetworkMonitorResource::OnPluginMsgForbidden(
77 const ResourceMessageReplyParams
& params
) {
80 if (TrackedCallback::IsPending(update_callback_
))
81 update_callback_
->Run(PP_ERROR_NOACCESS
);