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