Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: remoting/client/plugin/pepper_network_manager.cc

Issue 23453025: Refactor PPB_NetworkMonitor_Private interface to use CompletionCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/client/plugin/pepper_network_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/client/plugin/pepper_network_manager.h" 5 #include "remoting/client/plugin/pepper_network_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "ppapi/cpp/module.h" 11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/net_address.h" 12 #include "ppapi/cpp/net_address.h"
13 #include "ppapi/cpp/private/network_list_private.h" 13 #include "ppapi/cpp/private/network_list_private.h"
14 #include "remoting/client/plugin/pepper_util.h" 14 #include "remoting/client/plugin/pepper_util.h"
15 #include "third_party/libjingle/source/talk/base/socketaddress.h" 15 #include "third_party/libjingle/source/talk/base/socketaddress.h"
16 16
17 namespace remoting { 17 namespace remoting {
18 18
19 PepperNetworkManager::PepperNetworkManager(const pp::InstanceHandle& instance) 19 PepperNetworkManager::PepperNetworkManager(const pp::InstanceHandle& instance)
20 : monitor_(instance, &PepperNetworkManager::OnNetworkListCallbackHandler, 20 : monitor_(instance),
21 this),
22 start_count_(0), 21 start_count_(0),
23 network_list_received_(false), 22 network_list_received_(false),
23 callback_factory_(this),
24 weak_factory_(this) { 24 weak_factory_(this) {
25 pp::CompletionCallbackWithOutput<pp::NetworkListPrivate> callback =
26 callback_factory_.NewCallbackWithOutput(
27 &PepperNetworkManager::OnNetworkList);
28 monitor_.UpdateNetworkList(callback);
25 } 29 }
26 30
27 PepperNetworkManager::~PepperNetworkManager() { 31 PepperNetworkManager::~PepperNetworkManager() {
28 DCHECK(!start_count_); 32 DCHECK(!start_count_);
29 } 33 }
30 34
31 void PepperNetworkManager::StartUpdating() { 35 void PepperNetworkManager::StartUpdating() {
32 if (network_list_received_) { 36 if (network_list_received_) {
33 // Post a task to avoid reentrancy. 37 // Post a task to avoid reentrancy.
34 base::ThreadTaskRunnerHandle::Get()->PostTask( 38 base::ThreadTaskRunnerHandle::Get()->PostTask(
35 FROM_HERE, base::Bind(&PepperNetworkManager::SendNetworksChangedSignal, 39 FROM_HERE, base::Bind(&PepperNetworkManager::SendNetworksChangedSignal,
36 weak_factory_.GetWeakPtr())); 40 weak_factory_.GetWeakPtr()));
37 } 41 }
38 ++start_count_; 42 ++start_count_;
39 } 43 }
40 44
41 void PepperNetworkManager::StopUpdating() { 45 void PepperNetworkManager::StopUpdating() {
42 DCHECK_GT(start_count_, 0); 46 DCHECK_GT(start_count_, 0);
43 --start_count_; 47 --start_count_;
44 } 48 }
45 49
46 // static
47 void PepperNetworkManager::OnNetworkListCallbackHandler(
48 void* user_data,
49 PP_Resource list_resource) {
50 PepperNetworkManager* object = static_cast<PepperNetworkManager*>(user_data);
51 pp::NetworkListPrivate list(pp::PASS_REF, list_resource);
52 object->OnNetworkList(list);
53 }
54 50
55 void PepperNetworkManager::OnNetworkList(const pp::NetworkListPrivate& list) { 51 void PepperNetworkManager::OnNetworkList(int32_t result,
52 const pp::NetworkListPrivate& list) {
53 if (result != PP_OK) {
54 SignalError();
55 return;
56 }
57 DCHECK(!list.is_null());
58
56 network_list_received_ = true; 59 network_list_received_ = true;
57 60
61 // Request for the next update.
62 pp::CompletionCallbackWithOutput<pp::NetworkListPrivate> callback =
63 callback_factory_.NewCallbackWithOutput(
64 &PepperNetworkManager::OnNetworkList);
65 monitor_.UpdateNetworkList(callback);
66
67 // Convert the networks to talk_base::Network.
58 std::vector<talk_base::Network*> networks; 68 std::vector<talk_base::Network*> networks;
59 size_t count = list.GetCount(); 69 size_t count = list.GetCount();
60 for (size_t i = 0; i < count; i++) { 70 for (size_t i = 0; i < count; i++) {
61 std::vector<pp::NetAddress> addresses; 71 std::vector<pp::NetAddress> addresses;
62 list.GetIpAddresses(i, &addresses); 72 list.GetIpAddresses(i, &addresses);
63 73
64 if (addresses.size() == 0) 74 if (addresses.size() == 0)
65 continue; 75 continue;
66 76
67 talk_base::Network* network = new talk_base::Network( 77 talk_base::Network* network = new talk_base::Network(
(...skipping 12 matching lines...) Expand all
80 MergeNetworkList(networks, &changed); 90 MergeNetworkList(networks, &changed);
81 if (changed) 91 if (changed)
82 SignalNetworksChanged(); 92 SignalNetworksChanged();
83 } 93 }
84 94
85 void PepperNetworkManager::SendNetworksChangedSignal() { 95 void PepperNetworkManager::SendNetworksChangedSignal() {
86 SignalNetworksChanged(); 96 SignalNetworksChanged();
87 } 97 }
88 98
89 } // namespace remoting 99 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/plugin/pepper_network_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698