OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/chromeos/cros/network_library.h" | 5 #include "chrome/browser/chromeos/cros/network_library.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
11 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
12 #include "net/url_request/url_request_job.h" | 12 #include "net/url_request/url_request_job.h" |
13 | 13 |
14 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 14 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
15 // won't be deleted until it's last InvokeLater is run. | 15 // won't be deleted until it's last InvokeLater is run. |
16 template <> | 16 template <> |
17 struct RunnableMethodTraits<chromeos::NetworkLibrary> { | 17 struct RunnableMethodTraits<chromeos::NetworkLibraryImpl> { |
18 void RetainCallee(chromeos::NetworkLibrary* obj) {} | 18 void RetainCallee(chromeos::NetworkLibraryImpl* obj) {} |
19 void ReleaseCallee(chromeos::NetworkLibrary* obj) {} | 19 void ReleaseCallee(chromeos::NetworkLibraryImpl* obj) {} |
20 }; | 20 }; |
21 | 21 |
22 namespace chromeos { | 22 namespace chromeos { |
23 | 23 |
24 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
25 // NetworkLibrary | 25 // NetworkLibrary |
26 | 26 |
27 // static | 27 // static |
28 const int NetworkLibrary::kNetworkTrafficeTimerSecs = 1; | 28 const int NetworkLibraryImpl::kNetworkTrafficeTimerSecs = 1; |
29 | 29 |
30 NetworkLibrary::NetworkLibrary() | 30 NetworkLibraryImpl::NetworkLibraryImpl() |
31 : traffic_type_(0), | 31 : traffic_type_(0), |
| 32 network_status_connection_(NULL), |
32 available_devices_(0), | 33 available_devices_(0), |
33 enabled_devices_(0), | 34 enabled_devices_(0), |
34 connected_devices_(0), | 35 connected_devices_(0), |
35 offline_mode_(false) { | 36 offline_mode_(false) { |
36 if (CrosLibrary::EnsureLoaded()) { | 37 if (CrosLibrary::Get()->EnsureLoaded()) { |
37 Init(); | 38 Init(); |
38 } | 39 } |
39 g_url_request_job_tracker.AddObserver(this); | 40 g_url_request_job_tracker.AddObserver(this); |
40 } | 41 } |
41 | 42 |
42 NetworkLibrary::~NetworkLibrary() { | 43 NetworkLibraryImpl::~NetworkLibraryImpl() { |
43 if (CrosLibrary::EnsureLoaded()) { | 44 if (network_status_connection_) { |
44 DisconnectMonitorNetwork(network_status_connection_); | 45 DisconnectMonitorNetwork(network_status_connection_); |
45 } | 46 } |
46 g_url_request_job_tracker.RemoveObserver(this); | 47 g_url_request_job_tracker.RemoveObserver(this); |
47 } | 48 } |
48 | 49 |
49 // static | 50 //////////////////////////////////////////////////////////////////////////////// |
50 NetworkLibrary* NetworkLibrary::Get() { | 51 // NetworkLibraryImpl, URLRequestJobTracker::JobObserver implementation: |
51 return Singleton<NetworkLibrary>::get(); | |
52 } | |
53 | 52 |
54 //////////////////////////////////////////////////////////////////////////////// | 53 void NetworkLibraryImpl::OnJobAdded(URLRequestJob* job) { |
55 // NetworkLibrary, URLRequestJobTracker::JobObserver implementation: | |
56 | |
57 void NetworkLibrary::OnJobAdded(URLRequestJob* job) { | |
58 CheckNetworkTraffic(false); | 54 CheckNetworkTraffic(false); |
59 } | 55 } |
60 | 56 |
61 void NetworkLibrary::OnJobRemoved(URLRequestJob* job) { | 57 void NetworkLibraryImpl::OnJobRemoved(URLRequestJob* job) { |
62 CheckNetworkTraffic(false); | 58 CheckNetworkTraffic(false); |
63 } | 59 } |
64 | 60 |
65 void NetworkLibrary::OnJobDone(URLRequestJob* job, | 61 void NetworkLibraryImpl::OnJobDone(URLRequestJob* job, |
66 const URLRequestStatus& status) { | 62 const URLRequestStatus& status) { |
67 CheckNetworkTraffic(false); | 63 CheckNetworkTraffic(false); |
68 } | 64 } |
69 | 65 |
70 void NetworkLibrary::OnJobRedirect(URLRequestJob* job, const GURL& location, | 66 void NetworkLibraryImpl::OnJobRedirect(URLRequestJob* job, const GURL& location, |
71 int status_code) { | 67 int status_code) { |
72 CheckNetworkTraffic(false); | 68 CheckNetworkTraffic(false); |
73 } | 69 } |
74 | 70 |
75 void NetworkLibrary::OnBytesRead(URLRequestJob* job, int byte_count) { | 71 void NetworkLibraryImpl::OnBytesRead(URLRequestJob* job, int byte_count) { |
76 CheckNetworkTraffic(true); | 72 CheckNetworkTraffic(true); |
77 } | 73 } |
78 | 74 |
79 void NetworkLibrary::AddObserver(Observer* observer) { | 75 void NetworkLibraryImpl::AddObserver(Observer* observer) { |
80 observers_.AddObserver(observer); | 76 observers_.AddObserver(observer); |
81 } | 77 } |
82 | 78 |
83 void NetworkLibrary::RemoveObserver(Observer* observer) { | 79 void NetworkLibraryImpl::RemoveObserver(Observer* observer) { |
84 observers_.RemoveObserver(observer); | 80 observers_.RemoveObserver(observer); |
85 } | 81 } |
86 | 82 |
87 void NetworkLibrary::RequestWifiScan() { | 83 void NetworkLibraryImpl::RequestWifiScan() { |
88 if (CrosLibrary::EnsureLoaded()) { | 84 if (CrosLibrary::Get()->EnsureLoaded()) { |
89 RequestScan(TYPE_WIFI); | 85 RequestScan(TYPE_WIFI); |
90 } | 86 } |
91 } | 87 } |
92 | 88 |
93 void NetworkLibrary::ConnectToWifiNetwork(WifiNetwork network, | 89 void NetworkLibraryImpl::ConnectToWifiNetwork(WifiNetwork network, |
94 const string16& password) { | 90 const string16& password) { |
95 if (CrosLibrary::EnsureLoaded()) { | 91 if (CrosLibrary::Get()->EnsureLoaded()) { |
96 ConnectToNetwork(network.service_path.c_str(), | 92 ConnectToNetwork(network.service_path.c_str(), |
97 password.empty() ? NULL : UTF16ToUTF8(password).c_str()); | 93 password.empty() ? NULL : UTF16ToUTF8(password).c_str()); |
98 } | 94 } |
99 } | 95 } |
100 | 96 |
101 void NetworkLibrary::ConnectToWifiNetwork(const string16& ssid, | 97 void NetworkLibraryImpl::ConnectToWifiNetwork(const string16& ssid, |
102 const string16& password) { | 98 const string16& password) { |
103 if (CrosLibrary::EnsureLoaded()) { | 99 if (CrosLibrary::Get()->EnsureLoaded()) { |
104 // First create a service from hidden network. | 100 // First create a service from hidden network. |
105 ServiceInfo* service = GetWifiService(UTF16ToUTF8(ssid).c_str(), | 101 ServiceInfo* service = GetWifiService(UTF16ToUTF8(ssid).c_str(), |
106 SECURITY_UNKNOWN); | 102 SECURITY_UNKNOWN); |
107 // Now connect to that service. | 103 // Now connect to that service. |
108 if (service) { | 104 if (service) { |
109 ConnectToNetwork(service->service_path, | 105 ConnectToNetwork(service->service_path, |
110 password.empty() ? NULL : UTF16ToUTF8(password).c_str()); | 106 password.empty() ? NULL : UTF16ToUTF8(password).c_str()); |
111 // Clean up ServiceInfo object. | 107 // Clean up ServiceInfo object. |
112 FreeServiceInfo(service); | 108 FreeServiceInfo(service); |
113 } else { | 109 } else { |
114 LOG(WARNING) << "Cannot find hidden network: " << ssid; | 110 LOG(WARNING) << "Cannot find hidden network: " << ssid; |
115 // TODO(chocobo): Show error message. | 111 // TODO(chocobo): Show error message. |
116 } | 112 } |
117 } | 113 } |
118 } | 114 } |
119 | 115 |
120 void NetworkLibrary::ConnectToCellularNetwork(CellularNetwork network) { | 116 void NetworkLibraryImpl::ConnectToCellularNetwork(CellularNetwork network) { |
121 if (CrosLibrary::EnsureLoaded()) { | 117 if (CrosLibrary::Get()->EnsureLoaded()) { |
122 ConnectToNetwork(network.service_path.c_str(), NULL); | 118 ConnectToNetwork(network.service_path.c_str(), NULL); |
123 } | 119 } |
124 } | 120 } |
125 | 121 |
126 void NetworkLibrary::EnableEthernetNetworkDevice(bool enable) { | 122 void NetworkLibraryImpl::EnableEthernetNetworkDevice(bool enable) { |
127 EnableNetworkDevice(TYPE_ETHERNET, enable); | 123 EnableNetworkDevice(TYPE_ETHERNET, enable); |
128 } | 124 } |
129 | 125 |
130 void NetworkLibrary::EnableWifiNetworkDevice(bool enable) { | 126 void NetworkLibraryImpl::EnableWifiNetworkDevice(bool enable) { |
131 EnableNetworkDevice(TYPE_WIFI, enable); | 127 EnableNetworkDevice(TYPE_WIFI, enable); |
132 } | 128 } |
133 | 129 |
134 void NetworkLibrary::EnableCellularNetworkDevice(bool enable) { | 130 void NetworkLibraryImpl::EnableCellularNetworkDevice(bool enable) { |
135 EnableNetworkDevice(TYPE_CELLULAR, enable); | 131 EnableNetworkDevice(TYPE_CELLULAR, enable); |
136 } | 132 } |
137 | 133 |
138 void NetworkLibrary::EnableOfflineMode(bool enable) { | 134 void NetworkLibraryImpl::EnableOfflineMode(bool enable) { |
139 if (!CrosLibrary::EnsureLoaded()) | 135 if (!CrosLibrary::Get()->EnsureLoaded()) |
140 return; | 136 return; |
141 | 137 |
142 // If network device is already enabled/disabled, then don't do anything. | 138 // If network device is already enabled/disabled, then don't do anything. |
143 if (enable && offline_mode_) { | 139 if (enable && offline_mode_) { |
144 LOG(INFO) << "Trying to enable offline mode when it's already enabled. "; | 140 LOG(INFO) << "Trying to enable offline mode when it's already enabled. "; |
145 return; | 141 return; |
146 } | 142 } |
147 if (!enable && !offline_mode_) { | 143 if (!enable && !offline_mode_) { |
148 LOG(INFO) << "Trying to disable offline mode when it's already disabled. "; | 144 LOG(INFO) << "Trying to disable offline mode when it's already disabled. "; |
149 return; | 145 return; |
150 } | 146 } |
151 | 147 |
152 if (SetOfflineMode(enable)) { | 148 if (SetOfflineMode(enable)) { |
153 offline_mode_ = enable; | 149 offline_mode_ = enable; |
154 } | 150 } |
155 } | 151 } |
156 | 152 |
157 NetworkIPConfigVector NetworkLibrary::GetIPConfigs( | 153 NetworkIPConfigVector NetworkLibraryImpl::GetIPConfigs( |
158 const std::string& device_path) { | 154 const std::string& device_path) { |
159 NetworkIPConfigVector ipconfig_vector; | 155 NetworkIPConfigVector ipconfig_vector; |
160 if (!device_path.empty()) { | 156 if (!device_path.empty()) { |
161 IPConfigStatus* ipconfig_status = ListIPConfigs(device_path.c_str()); | 157 IPConfigStatus* ipconfig_status = ListIPConfigs(device_path.c_str()); |
162 if (ipconfig_status) { | 158 if (ipconfig_status) { |
163 for (int i = 0; i < ipconfig_status->size; i++) { | 159 for (int i = 0; i < ipconfig_status->size; i++) { |
164 IPConfig ipconfig = ipconfig_status->ips[i]; | 160 IPConfig ipconfig = ipconfig_status->ips[i]; |
165 ipconfig_vector.push_back( | 161 ipconfig_vector.push_back( |
166 NetworkIPConfig(device_path, ipconfig.type, ipconfig.address, | 162 NetworkIPConfig(device_path, ipconfig.type, ipconfig.address, |
167 ipconfig.netmask, ipconfig.gateway, | 163 ipconfig.netmask, ipconfig.gateway, |
168 ipconfig.name_servers)); | 164 ipconfig.name_servers)); |
169 } | 165 } |
170 FreeIPConfigStatus(ipconfig_status); | 166 FreeIPConfigStatus(ipconfig_status); |
171 // Sort the list of ip configs by type. | 167 // Sort the list of ip configs by type. |
172 std::sort(ipconfig_vector.begin(), ipconfig_vector.end()); | 168 std::sort(ipconfig_vector.begin(), ipconfig_vector.end()); |
173 } | 169 } |
174 } | 170 } |
175 return ipconfig_vector; | 171 return ipconfig_vector; |
176 } | 172 } |
177 | 173 |
178 // static | 174 // static |
179 void NetworkLibrary::NetworkStatusChangedHandler(void* object) { | 175 void NetworkLibraryImpl::NetworkStatusChangedHandler(void* object) { |
180 NetworkLibrary* network = static_cast<NetworkLibrary*>(object); | 176 NetworkLibraryImpl* network = static_cast<NetworkLibraryImpl*>(object); |
181 SystemInfo* system = GetSystemInfo(); | 177 SystemInfo* system = GetSystemInfo(); |
182 if (system) { | 178 if (system) { |
183 network->UpdateNetworkStatus(system); | 179 network->UpdateNetworkStatus(system); |
184 FreeSystemInfo(system); | 180 FreeSystemInfo(system); |
185 } | 181 } |
186 } | 182 } |
187 | 183 |
188 // static | 184 // static |
189 void NetworkLibrary::ParseSystem(SystemInfo* system, | 185 void NetworkLibraryImpl::ParseSystem(SystemInfo* system, |
190 EthernetNetwork* ethernet, | 186 EthernetNetwork* ethernet, |
191 WifiNetworkVector* wifi_networks, | 187 WifiNetworkVector* wifi_networks, |
192 CellularNetworkVector* cellular_networks) { | 188 CellularNetworkVector* cellular_networks) { |
193 DLOG(INFO) << "ParseSystem:"; | 189 DLOG(INFO) << "ParseSystem:"; |
194 for (int i = 0; i < system->service_size; i++) { | 190 for (int i = 0; i < system->service_size; i++) { |
195 const ServiceInfo& service = system->services[i]; | 191 const ServiceInfo& service = system->services[i]; |
196 DLOG(INFO) << " (" << service.type << | 192 DLOG(INFO) << " (" << service.type << |
197 ") " << service.name << | 193 ") " << service.name << |
198 " mode=" << service.mode << | 194 " mode=" << service.mode << |
199 " state=" << service.state << | 195 " state=" << service.state << |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 ip_address)); | 240 ip_address)); |
245 } else if (service.type == TYPE_CELLULAR) { | 241 } else if (service.type == TYPE_CELLULAR) { |
246 cellular_networks->push_back(CellularNetwork(service, | 242 cellular_networks->push_back(CellularNetwork(service, |
247 connecting, | 243 connecting, |
248 connected, | 244 connected, |
249 ip_address)); | 245 ip_address)); |
250 } | 246 } |
251 } | 247 } |
252 } | 248 } |
253 | 249 |
254 void NetworkLibrary::Init() { | 250 void NetworkLibraryImpl::Init() { |
255 // First, get the currently available networks. This data is cached | 251 // First, get the currently available networks. This data is cached |
256 // on the connman side, so the call should be quick. | 252 // on the connman side, so the call should be quick. |
257 SystemInfo* system = GetSystemInfo(); | 253 SystemInfo* system = GetSystemInfo(); |
258 if (system) { | 254 if (system) { |
259 LOG(INFO) << "Getting initial CrOS network info."; | 255 LOG(INFO) << "Getting initial CrOS network info."; |
260 UpdateNetworkStatus(system); | 256 UpdateNetworkStatus(system); |
261 FreeSystemInfo(system); | 257 FreeSystemInfo(system); |
262 } | 258 } |
263 LOG(INFO) << "Registering for network status updates."; | 259 LOG(INFO) << "Registering for network status updates."; |
264 // Now, register to receive updates on network status. | 260 // Now, register to receive updates on network status. |
265 network_status_connection_ = MonitorNetwork(&NetworkStatusChangedHandler, | 261 network_status_connection_ = MonitorNetwork(&NetworkStatusChangedHandler, |
266 this); | 262 this); |
267 } | 263 } |
268 | 264 |
269 void NetworkLibrary::EnableNetworkDevice(ConnectionType device, bool enable) { | 265 void NetworkLibraryImpl::EnableNetworkDevice(ConnectionType device, |
270 if (!CrosLibrary::EnsureLoaded()) | 266 bool enable) { |
| 267 if (!CrosLibrary::Get()->EnsureLoaded()) |
271 return; | 268 return; |
272 | 269 |
273 // If network device is already enabled/disabled, then don't do anything. | 270 // If network device is already enabled/disabled, then don't do anything. |
274 if (enable && (enabled_devices_ & (1 << device))) { | 271 if (enable && (enabled_devices_ & (1 << device))) { |
275 LOG(WARNING) << "Trying to enable a device that's already enabled: " | 272 LOG(WARNING) << "Trying to enable a device that's already enabled: " |
276 << device; | 273 << device; |
277 return; | 274 return; |
278 } | 275 } |
279 if (!enable && !(enabled_devices_ & (1 << device))) { | 276 if (!enable && !(enabled_devices_ & (1 << device))) { |
280 LOG(WARNING) << "Trying to disable a device that's already disabled: " | 277 LOG(WARNING) << "Trying to disable a device that's already disabled: " |
281 << device; | 278 << device; |
282 return; | 279 return; |
283 } | 280 } |
284 | 281 |
285 EnableNetworkDevice(device, enable); | 282 EnableNetworkDevice(device, enable); |
286 } | 283 } |
287 | 284 |
288 void NetworkLibrary::UpdateNetworkStatus(SystemInfo* system) { | 285 void NetworkLibraryImpl::UpdateNetworkStatus(SystemInfo* system) { |
289 // Make sure we run on UI thread. | 286 // Make sure we run on UI thread. |
290 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { | 287 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { |
291 ChromeThread::PostTask( | 288 ChromeThread::PostTask( |
292 ChromeThread::UI, FROM_HERE, | 289 ChromeThread::UI, FROM_HERE, |
293 NewRunnableMethod(this, | 290 NewRunnableMethod(this, |
294 &NetworkLibrary::UpdateNetworkStatus, system)); | 291 &NetworkLibraryImpl::UpdateNetworkStatus, system)); |
295 return; | 292 return; |
296 } | 293 } |
297 | 294 |
298 EthernetNetwork ethernet; | 295 EthernetNetwork ethernet; |
299 WifiNetworkVector wifi_networks; | 296 WifiNetworkVector wifi_networks; |
300 CellularNetworkVector cellular_networks; | 297 CellularNetworkVector cellular_networks; |
301 ParseSystem(system, ðernet, &wifi_networks, &cellular_networks); | 298 ParseSystem(system, ðernet, &wifi_networks, &cellular_networks); |
302 | 299 |
303 ethernet_ = ethernet; | 300 ethernet_ = ethernet; |
304 wifi_networks_ = wifi_networks; | 301 wifi_networks_ = wifi_networks; |
(...skipping 14 matching lines...) Expand all Loading... |
319 } | 316 } |
320 | 317 |
321 available_devices_ = system->available_technologies; | 318 available_devices_ = system->available_technologies; |
322 enabled_devices_ = system->enabled_technologies; | 319 enabled_devices_ = system->enabled_technologies; |
323 connected_devices_ = system->connected_technologies; | 320 connected_devices_ = system->connected_technologies; |
324 offline_mode_ = system->offline_mode; | 321 offline_mode_ = system->offline_mode; |
325 | 322 |
326 FOR_EACH_OBSERVER(Observer, observers_, NetworkChanged(this)); | 323 FOR_EACH_OBSERVER(Observer, observers_, NetworkChanged(this)); |
327 } | 324 } |
328 | 325 |
329 void NetworkLibrary::CheckNetworkTraffic(bool download) { | 326 void NetworkLibraryImpl::CheckNetworkTraffic(bool download) { |
330 // If we already have a pending upload and download notification, then | 327 // If we already have a pending upload and download notification, then |
331 // shortcut and return. | 328 // shortcut and return. |
332 if (traffic_type_ == (Observer::TRAFFIC_DOWNLOAD | Observer::TRAFFIC_UPLOAD)) | 329 if (traffic_type_ == (Observer::TRAFFIC_DOWNLOAD | Observer::TRAFFIC_UPLOAD)) |
333 return; | 330 return; |
334 // Figure out if we are uploading and/or downloading. We are downloading | 331 // Figure out if we are uploading and/or downloading. We are downloading |
335 // if download == true. We are uploading if we have upload progress. | 332 // if download == true. We are uploading if we have upload progress. |
336 if (download) | 333 if (download) |
337 traffic_type_ |= Observer::TRAFFIC_DOWNLOAD; | 334 traffic_type_ |= Observer::TRAFFIC_DOWNLOAD; |
338 if ((traffic_type_ & Observer::TRAFFIC_UPLOAD) == 0) { | 335 if ((traffic_type_ & Observer::TRAFFIC_UPLOAD) == 0) { |
339 URLRequestJobTracker::JobIterator it; | 336 URLRequestJobTracker::JobIterator it; |
340 for (it = g_url_request_job_tracker.begin(); | 337 for (it = g_url_request_job_tracker.begin(); |
341 it != g_url_request_job_tracker.end(); | 338 it != g_url_request_job_tracker.end(); |
342 ++it) { | 339 ++it) { |
343 URLRequestJob* job = *it; | 340 URLRequestJob* job = *it; |
344 if (job->GetUploadProgress() > 0) { | 341 if (job->GetUploadProgress() > 0) { |
345 traffic_type_ |= Observer::TRAFFIC_UPLOAD; | 342 traffic_type_ |= Observer::TRAFFIC_UPLOAD; |
346 break; | 343 break; |
347 } | 344 } |
348 } | 345 } |
349 } | 346 } |
350 // If we have new traffic data to send out and the timer is not currently | 347 // If we have new traffic data to send out and the timer is not currently |
351 // running, then start a new timer. | 348 // running, then start a new timer. |
352 if (traffic_type_ && !timer_.IsRunning()) { | 349 if (traffic_type_ && !timer_.IsRunning()) { |
353 timer_.Start(base::TimeDelta::FromSeconds(kNetworkTrafficeTimerSecs), this, | 350 timer_.Start(base::TimeDelta::FromSeconds(kNetworkTrafficeTimerSecs), this, |
354 &NetworkLibrary::NetworkTrafficTimerFired); | 351 &NetworkLibraryImpl::NetworkTrafficTimerFired); |
355 } | 352 } |
356 } | 353 } |
357 | 354 |
358 void NetworkLibrary:: NetworkTrafficTimerFired() { | 355 void NetworkLibraryImpl:: NetworkTrafficTimerFired() { |
359 ChromeThread::PostTask( | 356 ChromeThread::PostTask( |
360 ChromeThread::UI, FROM_HERE, | 357 ChromeThread::UI, FROM_HERE, |
361 NewRunnableMethod(this, &NetworkLibrary::NotifyNetworkTraffic, | 358 NewRunnableMethod(this, &NetworkLibraryImpl::NotifyNetworkTraffic, |
362 traffic_type_)); | 359 traffic_type_)); |
363 // Reset traffic type so that we don't send the same data next time. | 360 // Reset traffic type so that we don't send the same data next time. |
364 traffic_type_ = 0; | 361 traffic_type_ = 0; |
365 } | 362 } |
366 | 363 |
367 void NetworkLibrary::NotifyNetworkTraffic(int traffic_type) { | 364 void NetworkLibraryImpl::NotifyNetworkTraffic(int traffic_type) { |
368 FOR_EACH_OBSERVER(Observer, observers_, NetworkTraffic(this, traffic_type)); | 365 FOR_EACH_OBSERVER(Observer, observers_, NetworkTraffic(this, traffic_type)); |
369 } | 366 } |
370 | 367 |
371 bool NetworkLibrary::Connected() const { | 368 bool NetworkLibraryImpl::Connected() const { |
372 return ethernet_connected() || wifi_connected() || cellular_connected(); | 369 return ethernet_connected() || wifi_connected() || cellular_connected(); |
373 } | 370 } |
374 | 371 |
375 bool NetworkLibrary::Connecting() const { | 372 bool NetworkLibraryImpl::Connecting() const { |
376 return ethernet_connecting() || wifi_connecting() || cellular_connecting(); | 373 return ethernet_connecting() || wifi_connecting() || cellular_connecting(); |
377 } | 374 } |
378 | 375 |
379 const std::string& NetworkLibrary::IPAddress() const { | 376 const std::string& NetworkLibraryImpl::IPAddress() const { |
380 // Returns highest priority IP address. | 377 // Returns highest priority IP address. |
381 if (ethernet_connected()) | 378 if (ethernet_connected()) |
382 return ethernet_.ip_address; | 379 return ethernet_.ip_address; |
383 if (wifi_connected()) | 380 if (wifi_connected()) |
384 return wifi_.ip_address; | 381 return wifi_.ip_address; |
385 if (cellular_connected()) | 382 if (cellular_connected()) |
386 return cellular_.ip_address; | 383 return cellular_.ip_address; |
387 return ethernet_.ip_address; | 384 return ethernet_.ip_address; |
388 } | 385 } |
389 | 386 |
390 } // namespace chromeos | 387 } // namespace chromeos |
OLD | NEW |