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

Side by Side Diff: chrome/browser/chromeos/login/helper.cc

Issue 1428353002: Network Setup from Shark to Remora. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address achuithb@'s comment. Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/login/helper.h" 5 #include "chrome/browser/chromeos/login/helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/chromeos/login/startup_utils.h" 11 #include "chrome/browser/chromeos/login/startup_utils.h"
12 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" 12 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
13 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" 13 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" 14 #include "chrome/browser/chromeos/profiles/profile_helper.h"
15 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
16 #include "chromeos/chromeos_switches.h" 16 #include "chromeos/chromeos_switches.h"
17 #include "chromeos/network/managed_network_configuration_handler.h" 17 #include "chromeos/network/managed_network_configuration_handler.h"
18 #include "chromeos/network/network_connection_handler.h"
18 #include "chromeos/network/network_handler.h" 19 #include "chromeos/network/network_handler.h"
19 #include "chromeos/network/network_state.h" 20 #include "chromeos/network/network_state.h"
20 #include "chromeos/network/network_state_handler.h" 21 #include "chromeos/network/network_state_handler.h"
21 #include "components/guest_view/browser/guest_view_manager.h" 22 #include "components/guest_view/browser/guest_view_manager.h"
22 #include "content/public/browser/storage_partition.h" 23 #include "content/public/browser/storage_partition.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 25 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
25 #include "third_party/cros_system_api/dbus/service_constants.h" 26 #include "third_party/cros_system_api/dbus/service_constants.h"
26 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/gfx/image/image_skia.h" 28 #include "ui/gfx/image/image_skia.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 122
122 network = nsh->ConnectingNetworkByType(NetworkTypePattern::NonVirtual()); 123 network = nsh->ConnectingNetworkByType(NetworkTypePattern::NonVirtual());
123 if (network) { 124 if (network) {
124 if (network->Matches(NetworkTypePattern::Ethernet())) 125 if (network->Matches(NetworkTypePattern::Ethernet()))
125 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); 126 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
126 return base::UTF8ToUTF16(network->name()); 127 return base::UTF8ToUTF16(network->name());
127 } 128 }
128 return base::string16(); 129 return base::string16();
129 } 130 }
130 131
131 void NetworkStateHelper::CreateNetworkFromOnc( 132 void NetworkStateHelper::CreateAndConnectNetworkFromOnc(
132 const std::string& onc_spec) const { 133 const std::string& onc_spec,
134 const base::Closure& success_callback,
135 const base::Closure& error_callback) const {
133 std::string error; 136 std::string error;
134 scoped_ptr<base::Value> root = base::JSONReader::ReadAndReturnError( 137 scoped_ptr<base::Value> root = base::JSONReader::ReadAndReturnError(
135 onc_spec, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error); 138 onc_spec, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error);
136 139
137 base::DictionaryValue* toplevel_onc = nullptr; 140 base::DictionaryValue* toplevel_onc = nullptr;
138 if (!root || !root->GetAsDictionary(&toplevel_onc)) { 141 if (!root || !root->GetAsDictionary(&toplevel_onc)) {
139 LOG(ERROR) << "Invalid JSON Dictionary: " << error; 142 LOG(ERROR) << "Invalid JSON Dictionary: " << error;
140 return; 143 return;
141 } 144 }
142 145
143 NetworkHandler::Get()->managed_network_configuration_handler()-> 146 NetworkHandler::Get()
144 CreateConfiguration( 147 ->managed_network_configuration_handler()
148 ->CreateConfiguration(
145 "", *toplevel_onc, 149 "", *toplevel_onc,
146 base::Bind(&NetworkStateHelper::OnCreateConfiguration, 150 base::Bind(&NetworkStateHelper::OnCreateConfiguration,
147 base::Unretained(this)), 151 base::Unretained(this), success_callback, error_callback),
148 base::Bind(&NetworkStateHelper::OnCreateConfigurationFailed, 152 base::Bind(&NetworkStateHelper::OnCreateOrConnectNetworkFailed,
149 base::Unretained(this))); 153 base::Unretained(this), error_callback));
150 }
151
152 void NetworkStateHelper::OnCreateConfiguration(
153 const std::string& service_path) const {
154 // Do Nothing.
155 }
156
157 void NetworkStateHelper::OnCreateConfigurationFailed(
158 const std::string& error_name,
159 scoped_ptr<base::DictionaryValue> error_data) const {
160 LOG(ERROR) << "Failed to create network configuration: " << error_name;
161 } 154 }
162 155
163 bool NetworkStateHelper::IsConnected() const { 156 bool NetworkStateHelper::IsConnected() const {
164 chromeos::NetworkStateHandler* nsh = 157 chromeos::NetworkStateHandler* nsh =
165 chromeos::NetworkHandler::Get()->network_state_handler(); 158 chromeos::NetworkHandler::Get()->network_state_handler();
166 return nsh->ConnectedNetworkByType(chromeos::NetworkTypePattern::Default()) != 159 return nsh->ConnectedNetworkByType(chromeos::NetworkTypePattern::Default()) !=
167 nullptr; 160 nullptr;
168 } 161 }
169 162
170 bool NetworkStateHelper::IsConnecting() const { 163 bool NetworkStateHelper::IsConnecting() const {
171 chromeos::NetworkStateHandler* nsh = 164 chromeos::NetworkStateHandler* nsh =
172 chromeos::NetworkHandler::Get()->network_state_handler(); 165 chromeos::NetworkHandler::Get()->network_state_handler();
173 return nsh->ConnectingNetworkByType( 166 return nsh->ConnectingNetworkByType(
174 chromeos::NetworkTypePattern::Default()) != nullptr; 167 chromeos::NetworkTypePattern::Default()) != nullptr;
175 } 168 }
176 169
170 void NetworkStateHelper::OnCreateConfiguration(
171 const base::Closure& success_callback,
172 const base::Closure& error_callback,
173 const std::string& service_path) const {
174 // Connect to the network.
175 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork(
176 service_path, success_callback,
177 base::Bind(&NetworkStateHelper::OnCreateOrConnectNetworkFailed,
178 base::Unretained(this), error_callback),
179 false);
180 }
181
182 void NetworkStateHelper::OnCreateOrConnectNetworkFailed(
183 const base::Closure& error_callback,
184 const std::string& error_name,
185 scoped_ptr<base::DictionaryValue> error_data) const {
186 LOG(ERROR) << "Failed to create or connect to network: " << error_name;
187 error_callback.Run();
188 }
189
177 content::StoragePartition* GetSigninPartition() { 190 content::StoragePartition* GetSigninPartition() {
178 content::WebContents* embedder = GetLoginWebContents(); 191 content::WebContents* embedder = GetLoginWebContents();
179 if (!embedder) 192 if (!embedder)
180 return nullptr; 193 return nullptr;
181 194
182 // Note the partition name must match the sign-in webview used. For now, 195 // Note the partition name must match the sign-in webview used. For now,
183 // this is the default unnamed, shared, in-memory partition. 196 // this is the default unnamed, shared, in-memory partition.
184 return GetPartition(embedder, std::string()); 197 return GetPartition(embedder, std::string());
185 } 198 }
186 199
(...skipping 12 matching lines...) Expand all
199 212
200 return signin_partition->GetURLRequestContext(); 213 return signin_partition->GetURLRequestContext();
201 } 214 }
202 215
203 return ProfileHelper::GetSigninProfile()->GetRequestContext(); 216 return ProfileHelper::GetSigninProfile()->GetRequestContext();
204 } 217 }
205 218
206 } // namespace login 219 } // namespace login
207 220
208 } // namespace chromeos 221 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698