Index: webkit/plugins/ppapi/ppb_network_monitor_private_impl.cc |
diff --git a/webkit/plugins/ppapi/ppb_network_monitor_private_impl.cc b/webkit/plugins/ppapi/ppb_network_monitor_private_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9c502744c33670b73bedbc74a14893f239a91439 |
--- /dev/null |
+++ b/webkit/plugins/ppapi/ppb_network_monitor_private_impl.cc |
@@ -0,0 +1,66 @@ |
+// Copyright (c) 2012 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 "webkit/plugins/ppapi/ppb_network_monitor_private_impl.h" |
+ |
+#include "base/bind.h" |
+#include "ppapi/shared_impl/ppb_network_list_private_shared.h" |
+#include "webkit/plugins/ppapi/resource_helper.h" |
+ |
+namespace webkit { |
+namespace ppapi { |
+ |
+PPB_NetworkMonitor_Private_Impl::PPB_NetworkMonitor_Private_Impl( |
+ PP_Instance instance, |
+ PPB_NetworkMonitor_Callback callback, |
+ void* user_data) |
+ : Resource(::ppapi::OBJECT_IS_IMPL, instance), |
+ callback_(callback), |
+ user_data_(user_data), |
+ started_(false) { |
+} |
+ |
+PPB_NetworkMonitor_Private_Impl::~PPB_NetworkMonitor_Private_Impl() { |
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
+ if (plugin_delegate && started_) { |
+ plugin_delegate->RemoveNetworkListObserver(this); |
+ } |
+} |
+ |
+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.
|
+ PP_Instance instance, |
+ PPB_NetworkMonitor_Callback callback, |
+ void* user_data) { |
+ 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.
|
+ new PPB_NetworkMonitor_Private_Impl(instance, callback, user_data)); |
+ if (!t->Start()) |
+ return 0; |
+ return t->GetReference(); |
+} |
+ |
+::ppapi::thunk::PPB_NetworkMonitor_Private_API* |
+PPB_NetworkMonitor_Private_Impl::AsPPB_NetworkMonitor_Private_API() { |
+ return this; |
+} |
+ |
+bool PPB_NetworkMonitor_Private_Impl::Start() { |
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
+ if (!plugin_delegate) |
+ return false; |
+ started_ = plugin_delegate->AddNetworkListObserver(this); |
+ return started_; |
+} |
+ |
+void PPB_NetworkMonitor_Private_Impl::OnNetworkListChanged( |
+ 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.
|
+ scoped_ptr<net::NetworkInterfaceList> list_copy( |
+ 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
|
+ PP_Resource list_resource = |
+ ::ppapi::PPB_NetworkList_Private_Shared::Create( |
+ ::ppapi::OBJECT_IS_IMPL, pp_instance(), list_copy.Pass()); |
+ callback_(user_data_, list_resource); |
+} |
+ |
+} // namespace ppapi |
+} // namespace webkit |