OLD | NEW |
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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 131 } |
132 | 132 |
133 void NetworkStateHelper::GetConnectedWifiNetwork(std::string* out_onc_spec) { | 133 void NetworkStateHelper::GetConnectedWifiNetwork(std::string* out_onc_spec) { |
134 const NetworkState* network_state = | 134 const NetworkState* network_state = |
135 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( | 135 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( |
136 NetworkTypePattern::WiFi()); | 136 NetworkTypePattern::WiFi()); |
137 | 137 |
138 if (!network_state) | 138 if (!network_state) |
139 return; | 139 return; |
140 | 140 |
141 scoped_ptr<base::DictionaryValue> current_onc = | 141 std::unique_ptr<base::DictionaryValue> current_onc = |
142 network_util::TranslateNetworkStateToONC(network_state); | 142 network_util::TranslateNetworkStateToONC(network_state); |
143 std::string security; | 143 std::string security; |
144 current_onc->GetString( | 144 current_onc->GetString( |
145 onc::network_config::WifiProperty(onc::wifi::kSecurity), &security); | 145 onc::network_config::WifiProperty(onc::wifi::kSecurity), &security); |
146 if (security != onc::wifi::kSecurityNone) | 146 if (security != onc::wifi::kSecurityNone) |
147 return; | 147 return; |
148 | 148 |
149 const std::string hex_ssid = network_state->GetHexSsid(); | 149 const std::string hex_ssid = network_state->GetHexSsid(); |
150 | 150 |
151 scoped_ptr<base::DictionaryValue> copied_onc(new base::DictionaryValue()); | 151 std::unique_ptr<base::DictionaryValue> copied_onc( |
| 152 new base::DictionaryValue()); |
152 copied_onc->Set(onc::toplevel_config::kType, | 153 copied_onc->Set(onc::toplevel_config::kType, |
153 new base::StringValue(onc::network_type::kWiFi)); | 154 new base::StringValue(onc::network_type::kWiFi)); |
154 copied_onc->Set(onc::network_config::WifiProperty(onc::wifi::kHexSSID), | 155 copied_onc->Set(onc::network_config::WifiProperty(onc::wifi::kHexSSID), |
155 new base::StringValue(hex_ssid)); | 156 new base::StringValue(hex_ssid)); |
156 copied_onc->Set(onc::network_config::WifiProperty(onc::wifi::kSecurity), | 157 copied_onc->Set(onc::network_config::WifiProperty(onc::wifi::kSecurity), |
157 new base::StringValue(security)); | 158 new base::StringValue(security)); |
158 base::JSONWriter::Write(*copied_onc.get(), out_onc_spec); | 159 base::JSONWriter::Write(*copied_onc.get(), out_onc_spec); |
159 } | 160 } |
160 | 161 |
161 void NetworkStateHelper::CreateAndConnectNetworkFromOnc( | 162 void NetworkStateHelper::CreateAndConnectNetworkFromOnc( |
162 const std::string& onc_spec, | 163 const std::string& onc_spec, |
163 const base::Closure& success_callback, | 164 const base::Closure& success_callback, |
164 const base::Closure& error_callback) const { | 165 const base::Closure& error_callback) const { |
165 std::string error; | 166 std::string error; |
166 scoped_ptr<base::Value> root = base::JSONReader::ReadAndReturnError( | 167 std::unique_ptr<base::Value> root = base::JSONReader::ReadAndReturnError( |
167 onc_spec, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error); | 168 onc_spec, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error); |
168 | 169 |
169 base::DictionaryValue* toplevel_onc = nullptr; | 170 base::DictionaryValue* toplevel_onc = nullptr; |
170 if (!root || !root->GetAsDictionary(&toplevel_onc)) { | 171 if (!root || !root->GetAsDictionary(&toplevel_onc)) { |
171 LOG(ERROR) << "Invalid JSON Dictionary: " << error; | 172 LOG(ERROR) << "Invalid JSON Dictionary: " << error; |
172 error_callback.Run(); | 173 error_callback.Run(); |
173 return; | 174 return; |
174 } | 175 } |
175 | 176 |
176 NetworkHandler::Get() | 177 NetworkHandler::Get() |
(...skipping 29 matching lines...) Expand all Loading... |
206 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( | 207 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( |
207 service_path, success_callback, | 208 service_path, success_callback, |
208 base::Bind(&NetworkStateHelper::OnCreateOrConnectNetworkFailed, | 209 base::Bind(&NetworkStateHelper::OnCreateOrConnectNetworkFailed, |
209 base::Unretained(this), error_callback), | 210 base::Unretained(this), error_callback), |
210 false); | 211 false); |
211 } | 212 } |
212 | 213 |
213 void NetworkStateHelper::OnCreateOrConnectNetworkFailed( | 214 void NetworkStateHelper::OnCreateOrConnectNetworkFailed( |
214 const base::Closure& error_callback, | 215 const base::Closure& error_callback, |
215 const std::string& error_name, | 216 const std::string& error_name, |
216 scoped_ptr<base::DictionaryValue> error_data) const { | 217 std::unique_ptr<base::DictionaryValue> error_data) const { |
217 LOG(ERROR) << "Failed to create or connect to network: " << error_name; | 218 LOG(ERROR) << "Failed to create or connect to network: " << error_name; |
218 error_callback.Run(); | 219 error_callback.Run(); |
219 } | 220 } |
220 | 221 |
221 content::StoragePartition* GetSigninPartition() { | 222 content::StoragePartition* GetSigninPartition() { |
222 content::WebContents* embedder = GetLoginWebContents(); | 223 content::WebContents* embedder = GetLoginWebContents(); |
223 if (!embedder) | 224 if (!embedder) |
224 return nullptr; | 225 return nullptr; |
225 | 226 |
226 // Note the partition name must match the sign-in webview used. For now, | 227 // Note the partition name must match the sign-in webview used. For now, |
(...skipping 16 matching lines...) Expand all Loading... |
243 | 244 |
244 return signin_partition->GetURLRequestContext(); | 245 return signin_partition->GetURLRequestContext(); |
245 } | 246 } |
246 | 247 |
247 return ProfileHelper::GetSigninProfile()->GetRequestContext(); | 248 return ProfileHelper::GetSigninProfile()->GetRequestContext(); |
248 } | 249 } |
249 | 250 |
250 } // namespace login | 251 } // namespace login |
251 | 252 |
252 } // namespace chromeos | 253 } // namespace chromeos |
OLD | NEW |