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

Side by Side Diff: chrome/browser/chromeos/options/network_connect.cc

Issue 15937008: Unify ActivateCellular into network_connect.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 6 months 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) 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
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::CellularNetwork* cellular =
82 cros->FindCellularNetworkByPath(service_path);
83 if (!cellular)
84 return;
85 if (cellular->activation_state() != chromeos::ACTIVATION_STATE_ACTIVATED)
86 cellular->StartActivation();
87 return;
88 }
89
90 void ShowMobileSetup(const std::string& service_path) {
91 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
92 const CellularNetwork* cellular =
93 cros->FindCellularNetworkByPath(service_path);
94 if (cellular && !cellular->activated() &&
95 cellular->activate_over_non_cellular_network() &&
96 (!cros->connected_network() || !cros->connected_network()->online())) {
97 NetworkTechnology technology = cellular->network_technology();
98 ash::NetworkObserver::NetworkType network_type =
99 (technology == chromeos::NETWORK_TECHNOLOGY_LTE ||
100 technology == chromeos::NETWORK_TECHNOLOGY_LTE_ADVANCED)
101 ? ash::NetworkObserver::NETWORK_CELLULAR_LTE
102 : ash::NetworkObserver::NETWORK_CELLULAR;
103 ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage(
104 NULL,
105 ash::NetworkObserver::ERROR_CONNECT_FAILED,
106 network_type,
107 l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE),
108 l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION,
109 UTF8ToUTF16((cellular->name()))),
110 std::vector<string16>());
111 return;
112 }
113 MobileSetupDialog::Show(service_path);
114 }
115
77 ConnectResult ConnectToNetwork(const std::string& service_path, 116 ConnectResult ConnectToNetwork(const std::string& service_path,
78 gfx::NativeWindow parent_window) { 117 gfx::NativeWindow parent_window) {
79 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); 118 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
80 Network* network = cros->FindNetworkByPath(service_path); 119 Network* network = cros->FindNetworkByPath(service_path);
81 if (!network) 120 if (!network)
82 return NETWORK_NOT_FOUND; 121 return NETWORK_NOT_FOUND;
83 122
84 if (network->connecting_or_connected()) 123 if (network->connecting_or_connected())
85 return CONNECT_NOT_STARTED; 124 return CONNECT_NOT_STARTED;
86 125
(...skipping 13 matching lines...) Expand all
100 139
101 if (network->type() == TYPE_WIMAX) { 140 if (network->type() == TYPE_WIMAX) {
102 WimaxNetwork* wimax = static_cast<WimaxNetwork*>(network); 141 WimaxNetwork* wimax = static_cast<WimaxNetwork*>(network);
103 wimax->AttemptConnection(base::Bind(&DoConnect, wimax, parent_window)); 142 wimax->AttemptConnection(base::Bind(&DoConnect, wimax, parent_window));
104 return CONNECT_STARTED; 143 return CONNECT_STARTED;
105 } 144 }
106 145
107 if (network->type() == TYPE_CELLULAR) { 146 if (network->type() == TYPE_CELLULAR) {
108 CellularNetwork* cellular = static_cast<CellularNetwork*>(network); 147 CellularNetwork* cellular = static_cast<CellularNetwork*>(network);
109 if (cellular->NeedsActivation() || cellular->out_of_credits()) { 148 if (cellular->NeedsActivation() || cellular->out_of_credits()) {
110 ActivateCellular(cellular); 149 ActivateCellular(service_path);
111 return CONNECT_STARTED; 150 return CONNECT_STARTED;
112 } 151 }
113 if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING) 152 if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING)
114 return CONNECT_NOT_STARTED; 153 return CONNECT_NOT_STARTED;
115 cros->ConnectToCellularNetwork(cellular); 154 cros->ConnectToCellularNetwork(cellular);
116 return CONNECT_STARTED; 155 return CONNECT_STARTED;
117 } 156 }
118 157
119 if (network->type() == TYPE_VPN) { 158 if (network->type() == TYPE_VPN) {
120 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(network); 159 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(network);
121 vpn->SetEnrollmentDelegate( 160 vpn->SetEnrollmentDelegate(
122 chromeos::CreateEnrollmentDelegate( 161 chromeos::CreateEnrollmentDelegate(
123 parent_window, 162 parent_window,
124 vpn->name(), 163 vpn->name(),
125 ProfileManager::GetLastUsedProfile())); 164 ProfileManager::GetLastUsedProfile()));
126 vpn->AttemptConnection(base::Bind(&DoConnect, vpn, parent_window)); 165 vpn->AttemptConnection(base::Bind(&DoConnect, vpn, parent_window));
127 return CONNECT_STARTED; 166 return CONNECT_STARTED;
128 } 167 }
129 168
130 NOTREACHED(); 169 NOTREACHED();
131 return CONNECT_NOT_STARTED; 170 return CONNECT_NOT_STARTED;
132 } 171 }
133 172
134 } // namespace network_connect 173 } // namespace network_connect
135 } // namespace chromeos 174 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/options/network_connect.h ('k') | chrome/browser/chromeos/system/ash_system_tray_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698