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

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

Issue 23450012: Make NetworkList and NetworkMonitor APIs public (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/network_list.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), 20 : monitor_(instance),
21 start_count_(0), 21 start_count_(0),
22 network_list_received_(false), 22 network_list_received_(false),
23 callback_factory_(this), 23 callback_factory_(this),
24 weak_factory_(this) { 24 weak_factory_(this) {
25 pp::CompletionCallbackWithOutput<pp::NetworkListPrivate> callback = 25 pp::CompletionCallbackWithOutput<pp::NetworkList> callback =
26 callback_factory_.NewCallbackWithOutput( 26 callback_factory_.NewCallbackWithOutput(
27 &PepperNetworkManager::OnNetworkList); 27 &PepperNetworkManager::OnNetworkList);
28 monitor_.UpdateNetworkList(callback); 28 monitor_.UpdateNetworkList(callback);
29 } 29 }
30 30
31 PepperNetworkManager::~PepperNetworkManager() { 31 PepperNetworkManager::~PepperNetworkManager() {
32 DCHECK(!start_count_); 32 DCHECK(!start_count_);
33 } 33 }
34 34
35 void PepperNetworkManager::StartUpdating() { 35 void PepperNetworkManager::StartUpdating() {
36 if (network_list_received_) { 36 if (network_list_received_) {
37 // Post a task to avoid reentrancy. 37 // Post a task to avoid reentrancy.
38 base::ThreadTaskRunnerHandle::Get()->PostTask( 38 base::ThreadTaskRunnerHandle::Get()->PostTask(
39 FROM_HERE, base::Bind(&PepperNetworkManager::SendNetworksChangedSignal, 39 FROM_HERE, base::Bind(&PepperNetworkManager::SendNetworksChangedSignal,
40 weak_factory_.GetWeakPtr())); 40 weak_factory_.GetWeakPtr()));
41 } 41 }
42 ++start_count_; 42 ++start_count_;
43 } 43 }
44 44
45 void PepperNetworkManager::StopUpdating() { 45 void PepperNetworkManager::StopUpdating() {
46 DCHECK_GT(start_count_, 0); 46 DCHECK_GT(start_count_, 0);
47 --start_count_; 47 --start_count_;
48 } 48 }
49 49
50
51 void PepperNetworkManager::OnNetworkList(int32_t result, 50 void PepperNetworkManager::OnNetworkList(int32_t result,
52 const pp::NetworkListPrivate& list) { 51 const pp::NetworkList& list) {
53 if (result != PP_OK) { 52 if (result != PP_OK) {
54 SignalError(); 53 SignalError();
55 return; 54 return;
56 } 55 }
57 DCHECK(!list.is_null()); 56 DCHECK(!list.is_null());
58 57
59 network_list_received_ = true; 58 network_list_received_ = true;
60 59
61 // Request for the next update. 60 // Request for the next update.
62 pp::CompletionCallbackWithOutput<pp::NetworkListPrivate> callback = 61 pp::CompletionCallbackWithOutput<pp::NetworkList> callback =
63 callback_factory_.NewCallbackWithOutput( 62 callback_factory_.NewCallbackWithOutput(
64 &PepperNetworkManager::OnNetworkList); 63 &PepperNetworkManager::OnNetworkList);
65 monitor_.UpdateNetworkList(callback); 64 monitor_.UpdateNetworkList(callback);
66 65
67 // Convert the networks to talk_base::Network. 66 // Convert the networks to talk_base::Network.
68 std::vector<talk_base::Network*> networks; 67 std::vector<talk_base::Network*> networks;
69 size_t count = list.GetCount(); 68 size_t count = list.GetCount();
70 for (size_t i = 0; i < count; i++) { 69 for (size_t i = 0; i < count; i++) {
71 std::vector<pp::NetAddress> addresses; 70 std::vector<pp::NetAddress> addresses;
72 list.GetIpAddresses(i, &addresses); 71 list.GetIpAddresses(i, &addresses);
(...skipping 17 matching lines...) Expand all
90 MergeNetworkList(networks, &changed); 89 MergeNetworkList(networks, &changed);
91 if (changed) 90 if (changed)
92 SignalNetworksChanged(); 91 SignalNetworksChanged();
93 } 92 }
94 93
95 void PepperNetworkManager::SendNetworksChangedSignal() { 94 void PepperNetworkManager::SendNetworksChangedSignal() {
96 SignalNetworksChanged(); 95 SignalNetworksChanged();
97 } 96 }
98 97
99 } // namespace remoting 98 } // 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