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

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

Issue 4482003: Landing change for ers@chromium.org: http://codereview.chromium.org/4134012/s... (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
39 initialized_ = true; 42 initialized_ = true;
40 } 43 }
41 44
42 NetworkMessageObserver::~NetworkMessageObserver() { 45 NetworkMessageObserver::~NetworkMessageObserver() {
46 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
47 netlib->RemoveNetworkManagerObserver(this);
48 netlib->RemoveCellularDataPlanObserver(this);
43 notification_connection_error_.Hide(); 49 notification_connection_error_.Hide();
44 notification_low_data_.Hide(); 50 notification_low_data_.Hide();
45 notification_no_data_.Hide(); 51 notification_no_data_.Hide();
46 STLDeleteValues(&cellular_networks_); 52 STLDeleteValues(&cellular_networks_);
47 STLDeleteValues(&wifi_networks_); 53 STLDeleteValues(&wifi_networks_);
48 } 54 }
49 55
50 void NetworkMessageObserver::CreateModalPopup(views::WindowDelegate* view) { 56 void NetworkMessageObserver::CreateModalPopup(views::WindowDelegate* view) {
51 Browser* browser = BrowserList::GetLastActive(); 57 Browser* browser = BrowserList::GetLastActive();
52 if (browser && browser->type() != Browser::TYPE_NORMAL) { 58 if (browser && browser->type() != Browser::TYPE_NORMAL) {
53 browser = BrowserList::FindBrowserWithType(browser->profile(), 59 browser = BrowserList::FindBrowserWithType(browser->profile(),
54 Browser::TYPE_NORMAL, 60 Browser::TYPE_NORMAL,
55 true); 61 true);
56 } 62 }
57 DCHECK(browser); 63 DCHECK(browser);
58 views::Window* window = browser::CreateViewsWindow( 64 views::Window* window = browser::CreateViewsWindow(
59 browser->window()->GetNativeHandle(), gfx::Rect(), view); 65 browser->window()->GetNativeHandle(), gfx::Rect(), view);
60 window->SetIsAlwaysOnTop(true); 66 window->SetIsAlwaysOnTop(true);
61 window->Show(); 67 window->Show();
62 } 68 }
63 69
64 void NetworkMessageObserver::MobileSetup(const ListValue* args) { 70 void NetworkMessageObserver::MobileSetup(const ListValue* args) {
65 BrowserList::GetLastActive()->OpenMobilePlanTabAndActivate(); 71 BrowserList::GetLastActive()->OpenMobilePlanTabAndActivate();
66 } 72 }
67 73
68 void NetworkMessageObserver::NetworkChanged(NetworkLibrary* obj) { 74 void NetworkMessageObserver::OnNetworkManagerChanged(NetworkLibrary* obj) {
69 const WifiNetworkVector& wifi_networks = obj->wifi_networks(); 75 const WifiNetworkVector& wifi_networks = obj->wifi_networks();
70 const CellularNetworkVector& cellular_networks = obj->cellular_networks(); 76 const CellularNetworkVector& cellular_networks = obj->cellular_networks();
71 77
72 NetworkConfigView* view = NULL; 78 NetworkConfigView* view = NULL;
73 std::string new_failed_network; 79 std::string new_failed_network;
74 // Check to see if we have any newly failed wifi network. 80 // Check to see if we have any newly failed wifi network.
75 for (WifiNetworkVector::const_iterator it = wifi_networks.begin(); 81 for (WifiNetworkVector::const_iterator it = wifi_networks.begin();
76 it < wifi_networks.end(); it++) { 82 it < wifi_networks.end(); it++) {
77 const WifiNetwork* wifi = *it; 83 const WifiNetwork* wifi = *it;
78 if (wifi->failed()) { 84 if (wifi->failed()) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 notification_connection_error_.Show(l10n_util::GetStringFUTF16( 149 notification_connection_error_.Show(l10n_util::GetStringFUTF16(
144 IDS_NETWORK_CONNECTION_ERROR_MESSAGE, 150 IDS_NETWORK_CONNECTION_ERROR_MESSAGE,
145 ASCIIToUTF16(new_failed_network)), false, false); 151 ASCIIToUTF16(new_failed_network)), false, false);
146 } 152 }
147 153
148 // Show login box if necessary. 154 // Show login box if necessary.
149 if (view && initialized_) 155 if (view && initialized_)
150 CreateModalPopup(view); 156 CreateModalPopup(view);
151 } 157 }
152 158
153 void NetworkMessageObserver::CellularDataPlanChanged(NetworkLibrary* obj) { 159 void NetworkMessageObserver::OnCellularDataPlanChanged(NetworkLibrary* obj) {
154 const CellularNetwork* cellular = obj->cellular_network(); 160 const CellularNetwork* cellular = obj->cellular_network();
155 if (!cellular) 161 if (!cellular)
156 return; 162 return;
157 // Active plan is the first one in the list. Use empty one if none found. 163 // Active plan is the first one in the list. Use empty one if none found.
158 const CellularDataPlanVector& plans = cellular->GetDataPlans(); 164 const CellularDataPlanVector& plans = cellular->GetDataPlans();
159 CellularDataPlan plan = plans.empty() ? CellularDataPlan() : plans[0]; 165 CellularDataPlan plan = plans.empty() ? CellularDataPlan() : plans[0];
160 // If connected cellular network changed, or data plan is different, then 166 // If connected cellular network changed, or data plan is different, then
161 // it's a new network. Then hide all previous notifications. 167 // it's a new network. Then hide all previous notifications.
162 bool new_plan = false; 168 bool new_plan = false;
163 if (cellular->service_path() != cellular_service_path_) { 169 if (cellular->service_path() != cellular_service_path_) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // Got data, so hide notifications. 224 // Got data, so hide notifications.
219 notification_low_data_.Hide(); 225 notification_low_data_.Hide();
220 notification_no_data_.Hide(); 226 notification_no_data_.Hide();
221 } 227 }
222 } 228 }
223 229
224 cellular_data_plan_ = plan; 230 cellular_data_plan_ = plan;
225 } 231 }
226 232
227 } // 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