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

Side by Side Diff: chrome/browser/chromeos/network_message_observer.cc

Issue 4235005: Push for ers:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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/network_message_observer.h" 5 #include "chrome/browser/chromeos/network_message_observer.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 17 matching lines...) Expand all
28 : initialized_(false), 28 : initialized_(false),
29 notification_connection_error_(profile, "network_connection.chromeos", 29 notification_connection_error_(profile, "network_connection.chromeos",
30 IDR_NOTIFICATION_NETWORK_FAILED, 30 IDR_NOTIFICATION_NETWORK_FAILED,
31 l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE)), 31 l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE)),
32 notification_low_data_(profile, "network_low_data.chromeos", 32 notification_low_data_(profile, "network_low_data.chromeos",
33 IDR_NOTIFICATION_BARS_CRITICAL, 33 IDR_NOTIFICATION_BARS_CRITICAL,
34 l10n_util::GetStringUTF16(IDS_NETWORK_LOW_DATA_TITLE)), 34 l10n_util::GetStringUTF16(IDS_NETWORK_LOW_DATA_TITLE)),
35 notification_no_data_(profile, "network_no_data.chromeos", 35 notification_no_data_(profile, "network_no_data.chromeos",
36 IDR_NOTIFICATION_BARS_EMPTY, 36 IDR_NOTIFICATION_BARS_EMPTY,
37 l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_DATA_TITLE)) { 37 l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_DATA_TITLE)) {
38 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); 38 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
39 OnNetworkManagerChanged(netlib);
40 // Note that this gets added as a NetworkManagerObserver and a
41 // CellularDataPlanObserver in browser_init.cc
42 netlib->AddNetworkManagerObserver(this);
43 netlib->AddCellularDataPlanObserver(this);
39 initialized_ = true; 44 initialized_ = true;
40 } 45 }
41 46
42 NetworkMessageObserver::~NetworkMessageObserver() { 47 NetworkMessageObserver::~NetworkMessageObserver() {
48 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
49 netlib->RemoveNetworkManagerObserver(this);
50 netlib->RemoveCellularDataPlanObserver(this);
43 notification_connection_error_.Hide(); 51 notification_connection_error_.Hide();
44 notification_low_data_.Hide(); 52 notification_low_data_.Hide();
45 notification_no_data_.Hide(); 53 notification_no_data_.Hide();
46 STLDeleteValues(&cellular_networks_); 54 STLDeleteValues(&cellular_networks_);
47 STLDeleteValues(&wifi_networks_); 55 STLDeleteValues(&wifi_networks_);
48 } 56 }
49 57
50 void NetworkMessageObserver::CreateModalPopup(views::WindowDelegate* view) { 58 void NetworkMessageObserver::CreateModalPopup(views::WindowDelegate* view) {
51 Browser* browser = BrowserList::GetLastActive(); 59 Browser* browser = BrowserList::GetLastActive();
52 if (browser && browser->type() != Browser::TYPE_NORMAL) { 60 if (browser && browser->type() != Browser::TYPE_NORMAL) {
53 browser = BrowserList::FindBrowserWithType(browser->profile(), 61 browser = BrowserList::FindBrowserWithType(browser->profile(),
54 Browser::TYPE_NORMAL, 62 Browser::TYPE_NORMAL,
55 true); 63 true);
56 } 64 }
57 DCHECK(browser); 65 DCHECK(browser);
58 views::Window* window = browser::CreateViewsWindow( 66 views::Window* window = browser::CreateViewsWindow(
59 browser->window()->GetNativeHandle(), gfx::Rect(), view); 67 browser->window()->GetNativeHandle(), gfx::Rect(), view);
60 window->SetIsAlwaysOnTop(true); 68 window->SetIsAlwaysOnTop(true);
61 window->Show(); 69 window->Show();
62 } 70 }
63 71
64 void NetworkMessageObserver::MobileSetup(const ListValue* args) { 72 void NetworkMessageObserver::MobileSetup(const ListValue* args) {
65 BrowserList::GetLastActive()->OpenMobilePlanTabAndActivate(); 73 BrowserList::GetLastActive()->OpenMobilePlanTabAndActivate();
66 } 74 }
67 75
68 void NetworkMessageObserver::NetworkChanged(NetworkLibrary* obj) { 76 void NetworkMessageObserver::OnNetworkManagerChanged(NetworkLibrary* obj) {
69 const WifiNetworkVector& wifi_networks = obj->wifi_networks(); 77 const WifiNetworkVector& wifi_networks = obj->wifi_networks();
70 const CellularNetworkVector& cellular_networks = obj->cellular_networks(); 78 const CellularNetworkVector& cellular_networks = obj->cellular_networks();
71 79
72 NetworkConfigView* view = NULL; 80 NetworkConfigView* view = NULL;
73 std::string new_failed_network; 81 std::string new_failed_network;
74 // Check to see if we have any newly failed wifi network. 82 // Check to see if we have any newly failed wifi network.
75 for (WifiNetworkVector::const_iterator it = wifi_networks.begin(); 83 for (WifiNetworkVector::const_iterator it = wifi_networks.begin();
76 it < wifi_networks.end(); it++) { 84 it < wifi_networks.end(); it++) {
77 const WifiNetwork* wifi = *it; 85 const WifiNetwork* wifi = *it;
78 if (wifi->failed()) { 86 if (wifi->failed()) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 notification_connection_error_.Show(l10n_util::GetStringFUTF16( 151 notification_connection_error_.Show(l10n_util::GetStringFUTF16(
144 IDS_NETWORK_CONNECTION_ERROR_MESSAGE, 152 IDS_NETWORK_CONNECTION_ERROR_MESSAGE,
145 ASCIIToUTF16(new_failed_network)), false, false); 153 ASCIIToUTF16(new_failed_network)), false, false);
146 } 154 }
147 155
148 // Show login box if necessary. 156 // Show login box if necessary.
149 if (view && initialized_) 157 if (view && initialized_)
150 CreateModalPopup(view); 158 CreateModalPopup(view);
151 } 159 }
152 160
153 void NetworkMessageObserver::CellularDataPlanChanged(NetworkLibrary* obj) { 161 void NetworkMessageObserver::OnCellularDataPlanChanged(NetworkLibrary* obj) {
154 const CellularNetwork* cellular = obj->cellular_network(); 162 const CellularNetwork* cellular = obj->cellular_network();
155 if (!cellular) 163 if (!cellular)
156 return; 164 return;
157 // Active plan is the first one in the list. Use empty one if none found. 165 // Active plan is the first one in the list. Use empty one if none found.
158 const CellularDataPlanList& plans = cellular->GetDataPlans(); 166 const CellularDataPlanList& plans = cellular->GetDataPlans();
159 CellularDataPlan plan = plans.empty() ? CellularDataPlan() : plans[0]; 167 CellularDataPlan plan = plans.empty() ? CellularDataPlan() : plans[0];
160 // If connected cellular network changed, or data plan is different, then 168 // If connected cellular network changed, or data plan is different, then
161 // it's a new network. Then hide all previous notifications. 169 // it's a new network. Then hide all previous notifications.
162 bool new_plan = false; 170 bool new_plan = false;
163 if (cellular->service_path() != cellular_service_path_) { 171 if (cellular->service_path() != cellular_service_path_) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // Got data, so hide notifications. 224 // Got data, so hide notifications.
217 notification_low_data_.Hide(); 225 notification_low_data_.Hide();
218 notification_no_data_.Hide(); 226 notification_no_data_.Hide();
219 } 227 }
220 } 228 }
221 229
222 cellular_data_plan_ = plan; 230 cellular_data_plan_ = plan;
223 } 231 }
224 232
225 } // namespace chromeos 233 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/network_message_observer.h ('k') | chrome/browser/chromeos/network_state_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698