Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/options/network_connect.h" | 5 #include "chrome/browser/chromeos/options/network_connect.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_delegate.h" | 8 #include "ash/shell_delegate.h" |
| 9 #include "ash/system/chromeos/network/network_observer.h" | |
| 10 #include "ash/system/tray/system_tray_notifier.h" | |
| 11 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | 12 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "chrome/browser/chromeos/cros/network_library.h" | 13 #include "chrome/browser/chromeos/cros/network_library.h" |
| 11 #include "chrome/browser/chromeos/enrollment_dialog_view.h" | 14 #include "chrome/browser/chromeos/enrollment_dialog_view.h" |
| 12 #include "chrome/browser/chromeos/options/network_config_view.h" | 15 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" | |
| 18 #include "grit/generated_resources.h" | |
| 19 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 20 #include "ui/base/l10n/l10n_util.h" | |
| 14 | 21 |
| 15 namespace chromeos { | 22 namespace chromeos { |
| 16 namespace network_connect { | 23 namespace network_connect { |
| 17 | 24 |
| 18 namespace { | 25 namespace { |
| 19 | 26 |
| 20 void ActivateCellular(chromeos::CellularNetwork* cellular) { | |
| 21 DCHECK(cellular); | |
| 22 chromeos::NetworkLibrary* cros = | |
| 23 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | |
| 24 if (cros->CellularDeviceUsesDirectActivation()) { | |
| 25 cellular->StartActivation(); | |
| 26 } else { | |
| 27 ash::Shell::GetInstance()->delegate()->OpenMobileSetup( | |
| 28 cellular->service_path()); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 void DoConnect(Network* network, gfx::NativeWindow parent_window) { | 27 void DoConnect(Network* network, gfx::NativeWindow parent_window) { |
| 33 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 28 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 34 if (network->type() == TYPE_VPN) { | 29 if (network->type() == TYPE_VPN) { |
| 35 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(network); | 30 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(network); |
| 36 if (vpn->NeedMoreInfoToConnect()) { | 31 if (vpn->NeedMoreInfoToConnect()) { |
| 37 // Show the connection UI if info for a field is missing. | 32 // Show the connection UI if info for a field is missing. |
| 38 NetworkConfigView::Show(vpn, parent_window); | 33 NetworkConfigView::Show(vpn, parent_window); |
| 39 } else { | 34 } else { |
| 40 cros->ConnectToVirtualNetwork(vpn); | 35 cros->ConnectToVirtualNetwork(vpn); |
| 41 // Connection failures are responsible for updating the UI, including | 36 // Connection failures are responsible for updating the UI, including |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 58 NetworkConfigView::Show(wimax, parent_window); | 53 NetworkConfigView::Show(wimax, parent_window); |
| 59 } else { | 54 } else { |
| 60 cros->ConnectToWimaxNetwork(wimax); | 55 cros->ConnectToWimaxNetwork(wimax); |
| 61 // Connection failures are responsible for updating the UI, including | 56 // Connection failures are responsible for updating the UI, including |
| 62 // reopening dialogs. | 57 // reopening dialogs. |
| 63 } | 58 } |
| 64 } else if (network->type() == TYPE_CELLULAR) { | 59 } else if (network->type() == TYPE_CELLULAR) { |
| 65 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); | 60 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); |
| 66 if (cellular->activation_state() != ACTIVATION_STATE_ACTIVATED || | 61 if (cellular->activation_state() != ACTIVATION_STATE_ACTIVATED || |
| 67 cellular->out_of_credits()) { | 62 cellular->out_of_credits()) { |
| 68 ActivateCellular(cellular); | 63 ActivateCellular(cellular->service_path()); |
| 69 } else { | 64 } else { |
| 70 cros->ConnectToCellularNetwork(cellular); | 65 cros->ConnectToCellularNetwork(cellular); |
| 71 } | 66 } |
| 72 } | 67 } |
| 73 } | 68 } |
| 74 | 69 |
| 75 } // namespace | 70 } // namespace |
| 76 | 71 |
| 72 void ActivateCellular(const std::string& service_path) { | |
| 73 chromeos::NetworkLibrary* cros = | |
| 74 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | |
| 75 if (!cros->CellularDeviceUsesDirectActivation()) { | |
| 76 // For non direct activation, show the mobile setup dialog which can be | |
| 77 // used to activate the network. | |
| 78 ShowMobileSetup(service_path); | |
| 79 return; | |
| 80 } | |
| 81 chromeos::Network* network = NULL; | |
| 82 network = cros-> FindNetworkByPath(service_path); | |
|
tbarzic
2013/05/24 21:24:34
FindCellularNetworkByPath? That way you don't have
stevenjb
2013/05/24 22:17:45
Yes, done (copy/pasted old code).
| |
| 83 if (!network || network->type() != chromeos::TYPE_CELLULAR) | |
| 84 return; | |
| 85 chromeos::CellularNetwork* cellular = | |
| 86 static_cast<chromeos::CellularNetwork*>(network); | |
| 87 if (cellular->activation_state() != chromeos::ACTIVATION_STATE_ACTIVATED) | |
| 88 cellular->StartActivation(); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 void ShowMobileSetup(const std::string& service_path) { | |
| 93 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | |
| 94 const CellularNetwork* cellular = | |
| 95 cros->FindCellularNetworkByPath(service_path); | |
| 96 if (cellular && !cellular->activated() && | |
| 97 cellular->activate_over_non_cellular_network() && | |
| 98 (!cros->connected_network() || !cros->connected_network()->online())) { | |
| 99 NetworkTechnology technology = cellular->network_technology(); | |
| 100 ash::NetworkObserver::NetworkType network_type = | |
| 101 (technology == chromeos::NETWORK_TECHNOLOGY_LTE || | |
| 102 technology == chromeos::NETWORK_TECHNOLOGY_LTE_ADVANCED) | |
| 103 ? ash::NetworkObserver::NETWORK_CELLULAR_LTE | |
| 104 : ash::NetworkObserver::NETWORK_CELLULAR; | |
| 105 ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage( | |
| 106 NULL, | |
| 107 ash::NetworkObserver::ERROR_CONNECT_FAILED, | |
| 108 network_type, | |
| 109 l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE), | |
| 110 l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION, | |
| 111 UTF8ToUTF16((cellular->name()))), | |
| 112 std::vector<string16>()); | |
| 113 return; | |
| 114 } | |
| 115 MobileSetupDialog::Show(service_path); | |
| 116 } | |
| 117 | |
| 77 ConnectResult ConnectToNetwork(const std::string& service_path, | 118 ConnectResult ConnectToNetwork(const std::string& service_path, |
| 78 gfx::NativeWindow parent_window) { | 119 gfx::NativeWindow parent_window) { |
| 79 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 120 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 80 Network* network = cros->FindNetworkByPath(service_path); | 121 Network* network = cros->FindNetworkByPath(service_path); |
| 81 if (!network) | 122 if (!network) |
| 82 return NETWORK_NOT_FOUND; | 123 return NETWORK_NOT_FOUND; |
| 83 | 124 |
| 84 if (network->connecting_or_connected()) | 125 if (network->connecting_or_connected()) |
| 85 return CONNECT_NOT_STARTED; | 126 return CONNECT_NOT_STARTED; |
| 86 | 127 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 100 | 141 |
| 101 if (network->type() == TYPE_WIMAX) { | 142 if (network->type() == TYPE_WIMAX) { |
| 102 WimaxNetwork* wimax = static_cast<WimaxNetwork*>(network); | 143 WimaxNetwork* wimax = static_cast<WimaxNetwork*>(network); |
| 103 wimax->AttemptConnection(base::Bind(&DoConnect, wimax, parent_window)); | 144 wimax->AttemptConnection(base::Bind(&DoConnect, wimax, parent_window)); |
| 104 return CONNECT_STARTED; | 145 return CONNECT_STARTED; |
| 105 } | 146 } |
| 106 | 147 |
| 107 if (network->type() == TYPE_CELLULAR) { | 148 if (network->type() == TYPE_CELLULAR) { |
| 108 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); | 149 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); |
| 109 if (cellular->NeedsActivation() || cellular->out_of_credits()) { | 150 if (cellular->NeedsActivation() || cellular->out_of_credits()) { |
| 110 ActivateCellular(cellular); | 151 ActivateCellular(service_path); |
| 111 return CONNECT_STARTED; | 152 return CONNECT_STARTED; |
| 112 } | 153 } |
| 113 if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING) | 154 if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING) |
| 114 return CONNECT_NOT_STARTED; | 155 return CONNECT_NOT_STARTED; |
| 115 cros->ConnectToCellularNetwork(cellular); | 156 cros->ConnectToCellularNetwork(cellular); |
| 116 return CONNECT_STARTED; | 157 return CONNECT_STARTED; |
| 117 } | 158 } |
| 118 | 159 |
| 119 if (network->type() == TYPE_VPN) { | 160 if (network->type() == TYPE_VPN) { |
| 120 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(network); | 161 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(network); |
| 121 vpn->SetEnrollmentDelegate( | 162 vpn->SetEnrollmentDelegate( |
| 122 chromeos::CreateEnrollmentDelegate( | 163 chromeos::CreateEnrollmentDelegate( |
| 123 parent_window, | 164 parent_window, |
| 124 vpn->name(), | 165 vpn->name(), |
| 125 ProfileManager::GetLastUsedProfile())); | 166 ProfileManager::GetLastUsedProfile())); |
| 126 vpn->AttemptConnection(base::Bind(&DoConnect, vpn, parent_window)); | 167 vpn->AttemptConnection(base::Bind(&DoConnect, vpn, parent_window)); |
| 127 return CONNECT_STARTED; | 168 return CONNECT_STARTED; |
| 128 } | 169 } |
| 129 | 170 |
| 130 NOTREACHED(); | 171 NOTREACHED(); |
| 131 return CONNECT_NOT_STARTED; | 172 return CONNECT_NOT_STARTED; |
| 132 } | 173 } |
| 133 | 174 |
| 134 } // namespace network_connect | 175 } // namespace network_connect |
| 135 } // namespace chromeos | 176 } // namespace chromeos |
| OLD | NEW |