OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "webkit/plugins/ppapi/ppb_network_monitor_private_impl.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "ppapi/shared_impl/ppb_network_list_private_shared.h" | |
9 #include "webkit/plugins/ppapi/resource_helper.h" | |
10 | |
11 namespace webkit { | |
12 namespace ppapi { | |
13 | |
14 PPB_NetworkMonitor_Private_Impl::PPB_NetworkMonitor_Private_Impl( | |
15 PP_Instance instance, | |
16 PPB_NetworkMonitor_Callback callback, | |
17 void* user_data) | |
18 : Resource(::ppapi::OBJECT_IS_IMPL, instance), | |
19 callback_(callback), | |
20 user_data_(user_data), | |
21 started_(false) { | |
22 } | |
23 | |
24 PPB_NetworkMonitor_Private_Impl::~PPB_NetworkMonitor_Private_Impl() { | |
25 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
26 if (plugin_delegate && started_) { | |
27 plugin_delegate->RemoveNetworkListObserver(this); | |
28 } | |
29 } | |
30 | |
31 PP_Resource PPB_NetworkMonitor_Private_Impl::Create( | |
dmichael (off chromium)
2012/03/01 18:58:04
nit: // static
Sergey Ulanov
2012/03/03 02:26:08
Done.
| |
32 PP_Instance instance, | |
33 PPB_NetworkMonitor_Callback callback, | |
34 void* user_data) { | |
35 scoped_refptr<PPB_NetworkMonitor_Private_Impl> t( | |
dmichael (off chromium)
2012/03/01 18:58:04
nit: t is not a very good name...
Sergey Ulanov
2012/03/03 02:26:08
Done.
| |
36 new PPB_NetworkMonitor_Private_Impl(instance, callback, user_data)); | |
37 if (!t->Start()) | |
38 return 0; | |
39 return t->GetReference(); | |
40 } | |
41 | |
42 ::ppapi::thunk::PPB_NetworkMonitor_Private_API* | |
43 PPB_NetworkMonitor_Private_Impl::AsPPB_NetworkMonitor_Private_API() { | |
44 return this; | |
45 } | |
46 | |
47 bool PPB_NetworkMonitor_Private_Impl::Start() { | |
48 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
49 if (!plugin_delegate) | |
50 return false; | |
51 started_ = plugin_delegate->AddNetworkListObserver(this); | |
52 return started_; | |
53 } | |
54 | |
55 void PPB_NetworkMonitor_Private_Impl::OnNetworkListChanged( | |
56 const net::NetworkInterfaceList& list) { | |
dmichael (off chromium)
2012/03/01 18:58:04
nit: 4-space indent
Sergey Ulanov
2012/03/03 02:26:08
Done.
| |
57 scoped_ptr<net::NetworkInterfaceList> list_copy( | |
58 new net::NetworkInterfaceList(list)); | |
dmichael (off chromium)
2012/03/01 18:58:04
optional suggestion: If you have to copy it anyway
Sergey Ulanov
2012/03/03 02:26:08
Now we need to convert it to a different type, so
| |
59 PP_Resource list_resource = | |
60 ::ppapi::PPB_NetworkList_Private_Shared::Create( | |
61 ::ppapi::OBJECT_IS_IMPL, pp_instance(), list_copy.Pass()); | |
62 callback_(user_data_, list_resource); | |
63 } | |
64 | |
65 } // namespace ppapi | |
66 } // namespace webkit | |
OLD | NEW |