| 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_connect.h" | 9 #include "ash/system/chromeos/network/network_connect.h" |
| 10 #include "ash/system/chromeos/network/network_observer.h" | 10 #include "ash/system/chromeos/network/network_observer.h" |
| 11 #include "ash/system/tray/system_tray_notifier.h" | 11 #include "ash/system/tray/system_tray_notifier.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 15 #include "chrome/browser/chromeos/cros/network_library.h" | 15 #include "chrome/browser/chromeos/cros/network_library.h" |
| 16 #include "chrome/browser/chromeos/enrollment_dialog_view.h" | 16 #include "chrome/browser/chromeos/enrollment_dialog_view.h" |
| 17 #include "chrome/browser/chromeos/options/network_config_view.h" | 17 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 18 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" | 20 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" |
| 20 #include "chromeos/chromeos_switches.h" | 21 #include "chromeos/chromeos_switches.h" |
| 21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 namespace network_connect { | 27 namespace network_connect { |
| 27 | 28 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 Network* network = cros->FindNetworkByPath(service_path); | 129 Network* network = cros->FindNetworkByPath(service_path); |
| 129 if (!network) | 130 if (!network) |
| 130 return NETWORK_NOT_FOUND; | 131 return NETWORK_NOT_FOUND; |
| 131 | 132 |
| 132 if (network->connecting_or_connected()) | 133 if (network->connecting_or_connected()) |
| 133 return CONNECT_NOT_STARTED; | 134 return CONNECT_NOT_STARTED; |
| 134 | 135 |
| 135 if (network->type() == TYPE_ETHERNET) | 136 if (network->type() == TYPE_ETHERNET) |
| 136 return CONNECT_NOT_STARTED; // Normally this shouldn't happen | 137 return CONNECT_NOT_STARTED; // Normally this shouldn't happen |
| 137 | 138 |
| 138 if (network->type() == TYPE_WIFI) { | 139 if (network->type() == TYPE_WIFI || network->type() == TYPE_VPN) { |
| 139 WifiNetwork* wifi = static_cast<WifiNetwork*>(network); | 140 network->SetEnrollmentDelegate(chromeos::CreateEnrollmentDelegate( |
| 140 wifi->SetEnrollmentDelegate( | 141 parent_window, network->name(), ProfileManager::GetLastUsedProfile())); |
| 141 chromeos::CreateEnrollmentDelegate( | 142 network->AttemptConnection(base::Bind(&DoConnect, network, parent_window)); |
| 142 parent_window, | |
| 143 wifi->name(), | |
| 144 ProfileManager::GetLastUsedProfile())); | |
| 145 wifi->AttemptConnection(base::Bind(&DoConnect, wifi, parent_window)); | |
| 146 return CONNECT_STARTED; | 143 return CONNECT_STARTED; |
| 147 } | 144 } |
| 148 | 145 |
| 149 if (network->type() == TYPE_WIMAX) { | 146 if (network->type() == TYPE_WIMAX) { |
| 150 WimaxNetwork* wimax = static_cast<WimaxNetwork*>(network); | 147 WimaxNetwork* wimax = static_cast<WimaxNetwork*>(network); |
| 151 wimax->AttemptConnection(base::Bind(&DoConnect, wimax, parent_window)); | 148 wimax->AttemptConnection(base::Bind(&DoConnect, wimax, parent_window)); |
| 152 return CONNECT_STARTED; | 149 return CONNECT_STARTED; |
| 153 } | 150 } |
| 154 | 151 |
| 155 if (network->type() == TYPE_CELLULAR) { | 152 if (network->type() == TYPE_CELLULAR) { |
| 156 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); | 153 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); |
| 157 if (cellular->NeedsActivation() || cellular->out_of_credits()) { | 154 if (cellular->NeedsActivation() || cellular->out_of_credits()) { |
| 158 ActivateCellular(service_path); | 155 ActivateCellular(service_path); |
| 159 return CONNECT_STARTED; | 156 return CONNECT_STARTED; |
| 160 } | 157 } |
| 161 if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING) | 158 if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING) |
| 162 return CONNECT_NOT_STARTED; | 159 return CONNECT_NOT_STARTED; |
| 163 cros->ConnectToCellularNetwork(cellular); | 160 cros->ConnectToCellularNetwork(cellular); |
| 164 return CONNECT_STARTED; | 161 return CONNECT_STARTED; |
| 165 } | 162 } |
| 166 | 163 |
| 167 if (network->type() == TYPE_VPN) { | |
| 168 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(network); | |
| 169 vpn->SetEnrollmentDelegate( | |
| 170 chromeos::CreateEnrollmentDelegate( | |
| 171 parent_window, | |
| 172 vpn->name(), | |
| 173 ProfileManager::GetLastUsedProfile())); | |
| 174 vpn->AttemptConnection(base::Bind(&DoConnect, vpn, parent_window)); | |
| 175 return CONNECT_STARTED; | |
| 176 } | |
| 177 | |
| 178 NOTREACHED(); | 164 NOTREACHED(); |
| 179 return CONNECT_NOT_STARTED; | 165 return CONNECT_NOT_STARTED; |
| 180 } | 166 } |
| 181 | 167 |
| 168 void ConfigureNetwork(const std::string& service_path, |
| 169 gfx::NativeWindow parent_window) { |
| 170 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 171 Network* network = cros->FindNetworkByPath(service_path); |
| 172 if (!network) |
| 173 return; |
| 174 |
| 175 if (network->type() == TYPE_WIFI || network->type() == TYPE_VPN) { |
| 176 network->SetEnrollmentDelegate(chromeos::CreateEnrollmentDelegate( |
| 177 parent_window, network->name(), ProfileManager::GetLastUsedProfile())); |
| 178 // This will connect to the network only if the network just needs to have |
| 179 // its certificate configured. Otherwise it will show an enrollment dialog |
| 180 // if available, or call NetworkConfigView::Show(). |
| 181 network->AttemptConnection( |
| 182 base::Bind(&NetworkConfigView::Show, network, parent_window)); |
| 183 return; |
| 184 } |
| 185 |
| 186 if (network->type() == TYPE_WIMAX) { |
| 187 NetworkConfigView::Show(network, parent_window); |
| 188 return; |
| 189 } |
| 190 |
| 191 if (network->type() == TYPE_CELLULAR) { |
| 192 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); |
| 193 if (cellular->NeedsActivation()) { |
| 194 ActivateCellular(service_path); |
| 195 return; |
| 196 } else if (cellular->out_of_credits()) { |
| 197 ShowMobileSetup(service_path); |
| 198 return; |
| 199 } |
| 200 } |
| 201 |
| 202 // No special configure or setup for |service_path|, show the settings UI. |
| 203 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( |
| 204 service_path); |
| 205 } |
| 206 |
| 182 } // namespace network_connect | 207 } // namespace network_connect |
| 183 } // namespace chromeos | 208 } // namespace chromeos |
| OLD | NEW |