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

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

Issue 22796014: Eliminate c/b/chromeos/options/network_connect.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/options/network_connect.h"
6
7 #include "ash/shell.h"
8 #include "ash/shell_delegate.h"
9 #include "ash/system/chromeos/network/network_connect.h"
10 #include "ash/system/chromeos/network/network_observer.h"
11 #include "ash/system/tray/system_tray_notifier.h"
12 #include "base/command_line.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/chromeos/enrollment_dialog_view.h"
16 #include "chrome/browser/chromeos/login/user.h"
17 #include "chrome/browser/chromeos/login/user_manager.h"
18 #include "chrome/browser/chromeos/options/network_config_view.h"
19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/ui/browser_finder.h"
21 #include "chrome/browser/ui/chrome_pages.h"
22 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
23 #include "chrome/common/url_constants.h"
24 #include "chromeos/chromeos_switches.h"
25 #include "chromeos/network/certificate_pattern.h"
26 #include "chromeos/network/managed_network_configuration_handler.h"
27 #include "chromeos/network/network_event_log.h"
28 #include "chromeos/network/network_handler.h"
29 #include "chromeos/network/network_state.h"
30 #include "chromeos/network/network_state_handler.h"
31 #include "content/public/browser/user_metrics.h"
32 #include "grit/generated_resources.h"
33 #include "net/base/escape.h"
34 #include "third_party/cros_system_api/dbus/service_constants.h"
35 #include "ui/base/l10n/l10n_util.h"
36
37 namespace chromeos {
38
39 namespace {
40
41 void EnrollmentComplete(const std::string& service_path) {
42 NET_LOG_USER("Enrollment Complete", service_path);
43 }
44
45 }
46
47 namespace network_connect {
48
49 void ShowMobileSetup(const std::string& service_path) {
50 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
51 const NetworkState* cellular = handler->GetNetworkState(service_path);
52 if (cellular && cellular->type() == flimflam::kTypeCellular &&
53 cellular->activation_state() != flimflam::kActivationStateActivated &&
54 cellular->activate_over_non_cellular_networks() &&
55 !handler->DefaultNetwork()) {
56 std::string technology = cellular->network_technology();
57 ash::NetworkObserver::NetworkType network_type =
58 (technology == flimflam::kNetworkTechnologyLte ||
59 technology == flimflam::kNetworkTechnologyLteAdvanced)
60 ? ash::NetworkObserver::NETWORK_CELLULAR_LTE
61 : ash::NetworkObserver::NETWORK_CELLULAR;
62 ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage(
63 NULL,
64 ash::NetworkObserver::ERROR_CONNECT_FAILED,
65 network_type,
66 l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE),
67 l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION,
68 UTF8ToUTF16((cellular->name()))),
69 std::vector<string16>());
70 return;
71 }
72 MobileSetupDialog::Show(service_path);
73 }
74
75 void ShowNetworkSettings(const std::string& service_path) {
76 std::string page = chrome::kInternetOptionsSubPage;
77 const NetworkState* network = service_path.empty() ? NULL :
78 NetworkHandler::Get()->network_state_handler()->GetNetworkState(
79 service_path);
80 if (network) {
81 std::string name(network->name());
82 if (name.empty() && network->type() == flimflam::kTypeEthernet)
83 name = l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
84 page += base::StringPrintf(
85 "?servicePath=%s&networkType=%s&networkName=%s",
86 net::EscapeUrlEncodedData(service_path, true).c_str(),
87 net::EscapeUrlEncodedData(network->type(), true).c_str(),
88 net::EscapeUrlEncodedData(name, false).c_str());
89 }
90 content::RecordAction(
91 content::UserMetricsAction("OpenInternetOptionsDialog"));
92 Browser* browser = chrome::FindOrCreateTabbedBrowser(
93 ProfileManager::GetDefaultProfileOrOffTheRecord(),
94 chrome::HOST_DESKTOP_TYPE_ASH);
95 chrome::ShowSettingsSubPage(browser, page);
96 }
97
98 void HandleUnconfiguredNetwork(const std::string& service_path,
99 gfx::NativeWindow parent_window) {
100 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
101 GetNetworkState(service_path);
102 if (!network) {
103 NET_LOG_ERROR("Configuring unknown network", service_path);
104 return;
105 }
106
107 if (network->type() == flimflam::kTypeWifi) {
108 // Only show the config view for secure networks, otherwise do nothing.
109 if (network->security() != flimflam::kSecurityNone)
110 NetworkConfigView::Show(service_path, parent_window);
111 return;
112 }
113
114 if (network->type() == flimflam::kTypeWimax ||
115 network->type() == flimflam::kTypeVPN) {
116 NetworkConfigView::Show(service_path, parent_window);
117 return;
118 }
119
120 if (network->type() == flimflam::kTypeCellular) {
121 if (network->activation_state() != flimflam::kActivationStateActivated) {
122 ash::network_connect::ActivateCellular(service_path);
123 return;
124 }
125 if (network->cellular_out_of_credits()) {
126 ShowMobileSetup(service_path);
127 return;
128 }
129 // No special configure or setup for |network|, show the settings UI.
130 ShowNetworkSettings(service_path);
131 }
132 NOTREACHED();
133 }
134
135 bool EnrollNetwork(const std::string& service_path,
136 gfx::NativeWindow parent_window) {
137 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
138 GetNetworkState(service_path);
139 if (!network) {
140 NET_LOG_ERROR("Enrolling Unknown network", service_path);
141 return false;
142 }
143 // We skip certificate patterns for device policy ONC so that an unmanaged
144 // user can't get to the place where a cert is presented for them
145 // involuntarily.
146 if (network->ui_data().onc_source() == onc::ONC_SOURCE_DEVICE_POLICY)
147 return false;
148
149 const CertificatePattern& certificate_pattern =
150 network->ui_data().certificate_pattern();
151 if (certificate_pattern.Empty())
152 return false;
153
154 NET_LOG_USER("Enrolling", service_path);
155
156 EnrollmentDelegate* enrollment = CreateEnrollmentDelegate(
157 parent_window, network->name(), ProfileManager::GetDefaultProfile());
158 return enrollment->Enroll(certificate_pattern.enrollment_uri_list(),
159 base::Bind(&EnrollmentComplete, service_path));
160 }
161
162 const base::DictionaryValue* FindPolicyForActiveUser(
163 const NetworkState* network,
164 onc::ONCSource* onc_source) {
165 const User* user = UserManager::Get()->GetActiveUser();
166 std::string username_hash = user ? user->username_hash() : std::string();
167 return NetworkHandler::Get()->managed_network_configuration_handler()->
168 FindPolicyByGUID(username_hash, network->guid(), onc_source);
169 }
170
171 } // namespace network_connect
172 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/options/network_connect.h ('k') | chrome/browser/chromeos/options/vpn_config_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698