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

Side by Side Diff: chrome/browser/chromeos/cros/network_library.cc

Issue 3084027: Clean up code by removing network traffic code in network library.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 4 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/chrome_thread.h" 12 #include "chrome/browser/chrome_thread.h"
13 #include "chrome/browser/chromeos/cros/cros_library.h" 13 #include "chrome/browser/chromeos/cros/cros_library.h"
14 #include "net/url_request/url_request_job.h"
15 14
16 namespace chromeos { 15 namespace chromeos {
17 16
18 static const std::string kGoogleWifi = "Google"; 17 static const std::string kGoogleWifi = "Google";
19 static const std::string kGoogleAWifi = "Google-A"; 18 static const std::string kGoogleAWifi = "Google-A";
20 19
21 // Helper function to wrap Html with <th> tag. 20 // Helper function to wrap Html with <th> tag.
22 static std::string WrapWithTH(std::string text) { 21 static std::string WrapWithTH(std::string text) {
23 return "<th>" + text + "</th>"; 22 return "<th>" + text + "</th>";
24 } 23 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 case SECURITY_RSN: 197 case SECURITY_RSN:
199 return "RSN"; 198 return "RSN";
200 case SECURITY_8021X: 199 case SECURITY_8021X:
201 return "8021X"; 200 return "8021X";
202 } 201 }
203 return "Unknown";} 202 return "Unknown";}
204 203
205 //////////////////////////////////////////////////////////////////////////////// 204 ////////////////////////////////////////////////////////////////////////////////
206 // NetworkLibrary 205 // NetworkLibrary
207 206
208 class NetworkLibraryImpl : public NetworkLibrary, 207 class NetworkLibraryImpl : public NetworkLibrary {
209 public URLRequestJobTracker::JobObserver {
210 public: 208 public:
211 NetworkLibraryImpl() 209 NetworkLibraryImpl()
212 : traffic_type_(0), 210 : network_status_connection_(NULL),
213 network_status_connection_(NULL),
214 available_devices_(0), 211 available_devices_(0),
215 enabled_devices_(0), 212 enabled_devices_(0),
216 connected_devices_(0), 213 connected_devices_(0),
217 offline_mode_(false) { 214 offline_mode_(false) {
218 if (CrosLibrary::Get()->EnsureLoaded()) { 215 if (CrosLibrary::Get()->EnsureLoaded()) {
219 Init(); 216 Init();
220 } else { 217 } else {
221 InitTestData(); 218 InitTestData();
222 } 219 }
223 g_url_request_job_tracker.AddObserver(this);
224 } 220 }
225 221
226 ~NetworkLibraryImpl() { 222 ~NetworkLibraryImpl() {
227 if (network_status_connection_) { 223 if (network_status_connection_) {
228 DisconnectMonitorNetwork(network_status_connection_); 224 DisconnectMonitorNetwork(network_status_connection_);
229 } 225 }
230 g_url_request_job_tracker.RemoveObserver(this);
231 }
232
233 /////////////////////////////////////////////////////////////////////////////
234 // NetworkLibraryImpl, URLRequestJobTracker::JobObserver implementation:
235
236 void OnJobAdded(URLRequestJob* job) {
237 CheckNetworkTraffic(false);
238 }
239
240 void OnJobRemoved(URLRequestJob* job) {
241 CheckNetworkTraffic(false);
242 }
243
244 void OnJobDone(URLRequestJob* job, const URLRequestStatus& status) {
245 CheckNetworkTraffic(false);
246 }
247
248 void OnJobRedirect(
249 URLRequestJob* job, const GURL& location, int status_code) {
250 CheckNetworkTraffic(false);
251 }
252
253 void OnBytesRead(URLRequestJob* job, const char* buf, int byte_count) {
254 CheckNetworkTraffic(true);
255 } 226 }
256 227
257 void AddObserver(Observer* observer) { 228 void AddObserver(Observer* observer) {
258 observers_.AddObserver(observer); 229 observers_.AddObserver(observer);
259 } 230 }
260 231
261 void RemoveObserver(Observer* observer) { 232 void RemoveObserver(Observer* observer) {
262 observers_.RemoveObserver(observer); 233 observers_.RemoveObserver(observer);
263 } 234 }
264 235
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 876
906 available_devices_ = system->available_technologies; 877 available_devices_ = system->available_technologies;
907 enabled_devices_ = system->enabled_technologies; 878 enabled_devices_ = system->enabled_technologies;
908 connected_devices_ = system->connected_technologies; 879 connected_devices_ = system->connected_technologies;
909 offline_mode_ = system->offline_mode; 880 offline_mode_ = system->offline_mode;
910 881
911 FOR_EACH_OBSERVER(Observer, observers_, NetworkChanged(this)); 882 FOR_EACH_OBSERVER(Observer, observers_, NetworkChanged(this));
912 FreeSystemInfo(system); 883 FreeSystemInfo(system);
913 } 884 }
914 885
915 void CheckNetworkTraffic(bool download) {
916 // If we already have a pending upload and download notification, then
917 // shortcut and return.
918 if (traffic_type_ ==
919 (Observer::TRAFFIC_DOWNLOAD | Observer::TRAFFIC_UPLOAD)) {
920 return;
921 }
922 // Figure out if we are uploading and/or downloading. We are downloading
923 // if download == true. We are uploading if we have upload progress.
924 if (download)
925 traffic_type_ |= Observer::TRAFFIC_DOWNLOAD;
926 if ((traffic_type_ & Observer::TRAFFIC_UPLOAD) == 0) {
927 URLRequestJobTracker::JobIterator it;
928 for (it = g_url_request_job_tracker.begin();
929 it != g_url_request_job_tracker.end();
930 ++it) {
931 URLRequestJob* job = *it;
932 if (job->GetUploadProgress() > 0) {
933 traffic_type_ |= Observer::TRAFFIC_UPLOAD;
934 break;
935 }
936 }
937 }
938 // If we have new traffic data to send out and the timer is not currently
939 // running, then start a new timer.
940 if (traffic_type_ && !timer_.IsRunning()) {
941 timer_.Start(base::TimeDelta::FromSeconds(kNetworkTrafficeTimerSecs),
942 this,
943 &NetworkLibraryImpl::NetworkTrafficTimerFired);
944 }
945 }
946
947 void NetworkTrafficTimerFired() {
948 ChromeThread::PostTask(
949 ChromeThread::UI, FROM_HERE,
950 NewRunnableMethod(this, &NetworkLibraryImpl::NotifyNetworkTraffic,
951 traffic_type_));
952 // Reset traffic type so that we don't send the same data next time.
953 traffic_type_ = 0;
954 }
955
956 void NotifyNetworkTraffic(int traffic_type) {
957 FOR_EACH_OBSERVER(Observer, observers_, NetworkTraffic(this, traffic_type));
958 }
959
960 ObserverList<Observer> observers_; 886 ObserverList<Observer> observers_;
961 887
962 // The amount of time to wait between each NetworkTraffic notifications.
963 static const int kNetworkTrafficeTimerSecs = 1;
964
965 // Timer for sending NetworkTraffic notification every
966 // kNetworkTrafficeTimerSecs seconds.
967 base::OneShotTimer<NetworkLibraryImpl> timer_;
968
969 // The current traffic type that will be sent out for the next NetworkTraffic
970 // notification. This is a bitfield of TrafficTypeMasks.
971 int traffic_type_;
972
973 // The network status connection for monitoring network status changes. 888 // The network status connection for monitoring network status changes.
974 MonitorNetworkConnection network_status_connection_; 889 MonitorNetworkConnection network_status_connection_;
975 890
976 // The ethernet network. 891 // The ethernet network.
977 EthernetNetwork ethernet_; 892 EthernetNetwork ethernet_;
978 893
979 // The list of available wifi networks. 894 // The list of available wifi networks.
980 WifiNetworkVector wifi_networks_; 895 WifiNetworkVector wifi_networks_;
981 896
982 // The current connected (or connecting) wifi network. 897 // The current connected (or connecting) wifi network.
(...skipping 22 matching lines...) Expand all
1005 920
1006 bool offline_mode_; 921 bool offline_mode_;
1007 922
1008 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImpl); 923 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImpl);
1009 }; 924 };
1010 925
1011 class NetworkLibraryStubImpl : public NetworkLibrary { 926 class NetworkLibraryStubImpl : public NetworkLibrary {
1012 public: 927 public:
1013 NetworkLibraryStubImpl() : ip_address_("1.1.1.1") {} 928 NetworkLibraryStubImpl() : ip_address_("1.1.1.1") {}
1014 ~NetworkLibraryStubImpl() {} 929 ~NetworkLibraryStubImpl() {}
1015 void OnJobAdded(URLRequestJob* job) {}
1016 void OnJobRemoved(URLRequestJob* job) {}
1017 void OnJobDone(URLRequestJob* job, const URLRequestStatus& status) {}
1018 void OnJobRedirect(
1019 URLRequestJob* job, const GURL& location, int status_code) {}
1020 void OnBytesRead(URLRequestJob* job, const char* buf, int byte_count) {}
1021 void AddObserver(Observer* observer) {} 930 void AddObserver(Observer* observer) {}
1022 void RemoveObserver(Observer* observer) {} 931 void RemoveObserver(Observer* observer) {}
1023 virtual const EthernetNetwork& ethernet_network() const { 932 virtual const EthernetNetwork& ethernet_network() const {
1024 return ethernet_; 933 return ethernet_;
1025 } 934 }
1026 virtual bool ethernet_connecting() const { return false; } 935 virtual bool ethernet_connecting() const { return false; }
1027 virtual bool ethernet_connected() const { return true; } 936 virtual bool ethernet_connected() const { return true; }
1028 virtual const std::string& wifi_name() const { return EmptyString(); } 937 virtual const std::string& wifi_name() const { return EmptyString(); }
1029 virtual bool wifi_connecting() const { return false; } 938 virtual bool wifi_connecting() const { return false; }
1030 virtual bool wifi_connected() const { return false; } 939 virtual bool wifi_connected() const { return false; }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 return new NetworkLibraryStubImpl(); 1015 return new NetworkLibraryStubImpl();
1107 else 1016 else
1108 return new NetworkLibraryImpl(); 1017 return new NetworkLibraryImpl();
1109 } 1018 }
1110 1019
1111 } // namespace chromeos 1020 } // namespace chromeos
1112 1021
1113 // Allows InvokeLater without adding refcounting. This class is a Singleton and 1022 // Allows InvokeLater without adding refcounting. This class is a Singleton and
1114 // won't be deleted until it's last InvokeLater is run. 1023 // won't be deleted until it's last InvokeLater is run.
1115 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); 1024 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl);
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.h ('k') | chrome/browser/chromeos/dom_ui/internet_options_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698