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/mobile/mobile_activator.h" | 5 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 MobileActivator::MobileActivator() | 158 MobileActivator::MobileActivator() |
159 : cellular_config_(new CellularConfigDocument()), | 159 : cellular_config_(new CellularConfigDocument()), |
160 state_(PLAN_ACTIVATION_PAGE_LOADING), | 160 state_(PLAN_ACTIVATION_PAGE_LOADING), |
161 reenable_cert_check_(false), | 161 reenable_cert_check_(false), |
162 terminated_(true), | 162 terminated_(true), |
163 pending_activation_request_(false), | 163 pending_activation_request_(false), |
164 connection_retry_count_(0), | 164 connection_retry_count_(0), |
165 initial_OTASP_attempts_(0), | 165 initial_OTASP_attempts_(0), |
166 trying_OTASP_attempts_(0), | 166 trying_OTASP_attempts_(0), |
167 final_OTASP_attempts_(0), | 167 final_OTASP_attempts_(0), |
168 payment_reconnect_count_(0) { | 168 payment_reconnect_count_(0), |
169 weak_ptr_factory_(this) { | |
169 } | 170 } |
170 | 171 |
171 MobileActivator::~MobileActivator() { | 172 MobileActivator::~MobileActivator() { |
172 TerminateActivation(); | 173 TerminateActivation(); |
173 } | 174 } |
174 | 175 |
175 MobileActivator* MobileActivator::GetInstance() { | 176 MobileActivator* MobileActivator::GetInstance() { |
176 return Singleton<MobileActivator>::get(); | 177 return Singleton<MobileActivator>::get(); |
177 } | 178 } |
178 | 179 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 | 262 |
262 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, ""); | 263 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, ""); |
263 | 264 |
264 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 265 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
265 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, | 266 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, |
266 cellular_config_.get()), | 267 cellular_config_.get()), |
267 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); | 268 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); |
268 } | 269 } |
269 | 270 |
270 void MobileActivator::ContinueActivation() { | 271 void MobileActivator::ContinueActivation() { |
271 const NetworkState* network = GetNetworkState(service_path_); | 272 NetworkHandler::Get()->network_configuration_handler()->GetProperties( |
272 if (!network || | 273 service_path_, |
273 (network->payment_url().empty() && network->usage_url().empty())) | 274 base::Bind(&MobileActivator::GetPropertiesSuccess, |
275 weak_ptr_factory_.GetWeakPtr()), | |
276 base::Bind(&MobileActivator::GetPropertiesFailure, | |
277 weak_ptr_factory_.GetWeakPtr())); | |
278 } | |
279 | |
280 void MobileActivator::GetPropertiesSuccess( | |
281 const std::string& service_path, | |
282 const base::DictionaryValue& properties) { | |
armansito
2013/09/03 23:52:06
This method is really meant for the initial proper
stevenjb
2013/09/04 00:04:50
Actually it's called for ContinueActivation(), so
| |
283 const DictionaryValue* payment_dict; | |
284 std::string usage_url, payment_url; | |
285 if (!properties.GetStringWithoutPathExpansion( | |
gauravsh
2013/09/04 00:06:52
It shouldn't happen, but you should check for serv
stevenjb
2013/09/04 01:04:11
Done.
| |
286 flimflam::kUsageURLProperty, &usage_url) || | |
287 !properties.GetDictionaryWithoutPathExpansion( | |
288 flimflam::kPaymentPortalProperty, &payment_dict) || | |
289 !payment_dict->GetStringWithoutPathExpansion( | |
290 flimflam::kPaymentPortalURL, &payment_url)) { | |
291 NET_LOG_ERROR("MobileActivator missing properties", service_path_); | |
292 return; | |
293 } | |
294 | |
295 if (payment_url.empty() && usage_url.empty()) | |
274 return; | 296 return; |
275 | 297 |
276 DisableCertRevocationChecking(); | 298 DisableCertRevocationChecking(); |
277 | 299 |
278 // We want shill to connect us after activations, so enable autoconnect. | 300 // We want shill to connect us after activations, so enable autoconnect. |
279 DictionaryValue auto_connect_property; | 301 DictionaryValue auto_connect_property; |
280 auto_connect_property.SetBoolean(flimflam::kAutoConnectProperty, true); | 302 auto_connect_property.SetBoolean(flimflam::kAutoConnectProperty, true); |
281 NetworkHandler::Get()->network_configuration_handler()->SetProperties( | 303 NetworkHandler::Get()->network_configuration_handler()->SetProperties( |
282 network->path(), | 304 service_path_, |
283 auto_connect_property, | 305 auto_connect_property, |
284 base::Bind(&base::DoNothing), | 306 base::Bind(&base::DoNothing), |
285 network_handler::ErrorCallback()); | 307 network_handler::ErrorCallback()); |
286 StartActivation(); | 308 StartActivation(); |
287 } | 309 } |
288 | 310 |
311 void MobileActivator::GetPropertiesFailure( | |
312 const std::string& error_name, | |
313 scoped_ptr<base::DictionaryValue> error_data) { | |
314 NET_LOG_ERROR("MobileActivator GetProperties Failed: " + error_name, | |
315 service_path_); | |
316 } | |
317 | |
289 void MobileActivator::OnSetTransactionStatus(bool success) { | 318 void MobileActivator::OnSetTransactionStatus(bool success) { |
290 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 319 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
291 base::Bind(&MobileActivator::HandleSetTransactionStatus, | 320 base::Bind(&MobileActivator::HandleSetTransactionStatus, |
292 AsWeakPtr(), success)); | 321 AsWeakPtr(), success)); |
293 } | 322 } |
294 | 323 |
295 void MobileActivator::HandleSetTransactionStatus(bool success) { | 324 void MobileActivator::HandleSetTransactionStatus(bool success) { |
296 // The payment is received, try to reconnect and check the status all over | 325 // The payment is received, try to reconnect and check the status all over |
297 // again. | 326 // again. |
298 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 327 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1019 cellular_plan_payment_time_ = base::Time::Now(); | 1048 cellular_plan_payment_time_ = base::Time::Now(); |
1020 } | 1049 } |
1021 | 1050 |
1022 bool MobileActivator::HasRecentCellularPlanPayment() const { | 1051 bool MobileActivator::HasRecentCellularPlanPayment() const { |
1023 const int kRecentPlanPaymentHours = 6; | 1052 const int kRecentPlanPaymentHours = 6; |
1024 return (base::Time::Now() - | 1053 return (base::Time::Now() - |
1025 cellular_plan_payment_time_).InHours() < kRecentPlanPaymentHours; | 1054 cellular_plan_payment_time_).InHours() < kRecentPlanPaymentHours; |
1026 } | 1055 } |
1027 | 1056 |
1028 } // namespace chromeos | 1057 } // namespace chromeos |
OLD | NEW |