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

Side by Side Diff: chrome/browser/chromeos/mobile/mobile_activator.cc

Issue 22611005: Switch over MobileActivator to use Network*Handler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address feedback from arman and steven 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
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
11 #include "ash/system/chromeos/network/network_connect.h" 11 #include "ash/system/chromeos/network/network_connect.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
16 #include "base/location.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/memory/ref_counted_memory.h" 18 #include "base/memory/ref_counted_memory.h"
18 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
19 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
20 #include "base/observer_list_threadsafe.h" 21 #include "base/observer_list_threadsafe.h"
21 #include "base/prefs/pref_service.h" 22 #include "base/prefs/pref_service.h"
22 #include "base/strings/string_piece.h" 23 #include "base/strings/string_piece.h"
23 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
24 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
25 #include "base/timer/timer.h" 26 #include "base/timer/timer.h"
26 #include "base/values.h" 27 #include "base/values.h"
27 #include "chrome/browser/browser_process.h" 28 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/chromeos/cros/network_library.h"
29 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
30 #include "chromeos/network/device_state.h"
31 #include "chromeos/network/network_activation_handler.h"
32 #include "chromeos/network/network_configuration_handler.h"
33 #include "chromeos/network/network_connection_handler.h"
34 #include "chromeos/network/network_event_log.h"
35 #include "chromeos/network/network_handler_callbacks.h"
36 #include "chromeos/network/network_state.h"
37 #include "chromeos/network/network_state_handler.h"
30 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
39 #include "third_party/cros_system_api/dbus/service_constants.h"
31 40
32 using content::BrowserThread; 41 using content::BrowserThread;
33 42
34 namespace { 43 namespace {
35 44
36 // Cellular configuration file path. 45 // Cellular configuration file path.
37 const char kCellularConfigPath[] = 46 const char kCellularConfigPath[] =
38 "/usr/share/chromeos-assets/mobile/mobile_config.json"; 47 "/usr/share/chromeos-assets/mobile/mobile_config.json";
39 48
40 // Cellular config file field names. 49 // Cellular config file field names.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 166
158 MobileActivator::~MobileActivator() { 167 MobileActivator::~MobileActivator() {
159 TerminateActivation(); 168 TerminateActivation();
160 } 169 }
161 170
162 MobileActivator* MobileActivator::GetInstance() { 171 MobileActivator* MobileActivator::GetInstance() {
163 return Singleton<MobileActivator>::get(); 172 return Singleton<MobileActivator>::get();
164 } 173 }
165 174
166 void MobileActivator::TerminateActivation() { 175 void MobileActivator::TerminateActivation() {
167 // We're exiting; don't continue with termination.
168 if (!NetworkLibrary::Get())
169 return;
170
171 state_duration_timer_.Stop(); 176 state_duration_timer_.Stop();
172 continue_reconnect_timer_.Stop(); 177 continue_reconnect_timer_.Stop();
173 reconnect_timeout_timer_.Stop(); 178 reconnect_timeout_timer_.Stop();
174 179
175 NetworkLibrary* lib = GetNetworkLibrary(); 180 if (NetworkHandler::IsInitialized())
176 lib->RemoveNetworkManagerObserver(this); 181 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this,
177 lib->RemoveObserverForAllNetworks(this); 182 FROM_HERE);
178 ReEnableCertRevocationChecking(); 183 ReEnableCertRevocationChecking();
179 meid_.clear(); 184 meid_.clear();
180 iccid_.clear(); 185 iccid_.clear();
181 service_path_.clear(); 186 service_path_.clear();
182 state_ = PLAN_ACTIVATION_PAGE_LOADING; 187 state_ = PLAN_ACTIVATION_PAGE_LOADING;
183 reenable_cert_check_ = false; 188 reenable_cert_check_ = false;
184 terminated_ = true; 189 terminated_ = true;
185 // Release the previous cellular config and setup a new empty one. 190 // Release the previous cellular config and setup a new empty one.
186 cellular_config_ = new CellularConfigDocument(); 191 cellular_config_ = new CellularConfigDocument();
187 } 192 }
188 193
189 void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) { 194 void MobileActivator::NetworkManagerChanged() {
190 if (state_ == PLAN_ACTIVATION_PAGE_LOADING || 195 if (state_ == PLAN_ACTIVATION_PAGE_LOADING ||
191 state_ == PLAN_ACTIVATION_DONE || 196 state_ == PLAN_ACTIVATION_DONE ||
192 state_ == PLAN_ACTIVATION_ERROR) { 197 state_ == PLAN_ACTIVATION_ERROR) {
193 return; 198 return;
194 } 199 }
195 200
196 CellularNetwork* network = FindMatchingCellularNetwork(true); 201 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler();
197 if (network && network->activate_over_non_cellular_network()) { 202 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
203 GetNetworkState(service_path_);
204 if (network && network->activate_over_non_cellular_networks()) {
198 bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION); 205 bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION);
199 bool is_online = 206 bool is_online = nsh->DefaultNetwork() &&
200 cros->connected_network() && cros->connected_network()->online(); 207 nsh->DefaultNetwork()->connection_state() == flimflam::kStateOnline;
201 if (waiting && is_online) { 208 if (waiting && is_online) {
202 ChangeState(network, post_reconnect_state_, ""); 209 ChangeState(network, post_reconnect_state_, "");
203 } else if (!waiting && !is_online) { 210 } else if (!waiting && !is_online) {
204 ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, ""); 211 ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, "");
205 } 212 }
206 } 213 }
207 214
208 EvaluateCellularNetwork(network); 215 EvaluateCellularNetwork(network);
209 } 216 }
210 217
211 void MobileActivator::OnNetworkChanged(NetworkLibrary* cros, 218 void MobileActivator::DefaultNetworkChanged(const NetworkState* network) {
212 const Network* network) { 219 NetworkManagerChanged();
220 }
221
222 void MobileActivator::NetworkPropertiesUpdated(const NetworkState* network) {
213 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) 223 if (state_ == PLAN_ACTIVATION_PAGE_LOADING)
214 return; 224 return;
215 225
216 if (!network || network->type() != TYPE_CELLULAR) { 226 if (!network || network->type() != flimflam::kTypeCellular)
217 NOTREACHED(); 227 return;
228 if (network->path() != service_path_) {
229 LOG(WARNING) << "Ignoring property update for unknown cellular service "
230 << network->path() << " (Expected " << service_path_<< ")";
218 return; 231 return;
219 } 232 }
220 233
221 EvaluateCellularNetwork( 234 EvaluateCellularNetwork(network);
222 static_cast<CellularNetwork*>(const_cast<Network*>(network)));
223 } 235 }
224 236
225 void MobileActivator::AddObserver(MobileActivator::Observer* observer) { 237 void MobileActivator::AddObserver(MobileActivator::Observer* observer) {
226 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); 238 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI));
227 observers_.AddObserver(observer); 239 observers_.AddObserver(observer);
228 } 240 }
229 241
230 void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) { 242 void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) {
231 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); 243 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI));
232 observers_.RemoveObserver(observer); 244 observers_.RemoveObserver(observer);
233 } 245 }
234 246
235 void MobileActivator::InitiateActivation(const std::string& service_path) { 247 void MobileActivator::InitiateActivation(const std::string& service_path) {
236 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); 248 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI));
237 NetworkLibrary* lib = GetNetworkLibrary(); 249 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
238 CellularNetwork* network = lib->FindCellularNetworkByPath(service_path); 250 GetNetworkState(service_path);
239 if (!network) { 251 if (!network) {
240 LOG(ERROR) << "Cellular service can't be found: " << service_path; 252 LOG(ERROR) << "Cellular service can't be found: " << service_path;
241 return; 253 return;
242 } 254 }
243 255
244 const chromeos::NetworkDevice* device = 256 const DeviceState* device = NetworkHandler::Get()->network_state_handler()->
245 lib->FindNetworkDeviceByPath(network->device_path()); 257 GetDeviceState(network->device_path());
246 if (!device) { 258 if (!device) {
247 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); 259 LOG(ERROR) << "Cellular device can't be found: " << network->device_path();
248 return; 260 return;
249 } 261 }
250 262
251 terminated_ = false; 263 terminated_ = false;
252 meid_ = device->meid(); 264 meid_ = device->meid();
253 iccid_ = device->iccid(); 265 iccid_ = device->iccid();
254 service_path_ = service_path; 266 service_path_ = service_path;
255 267
256 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, ""); 268 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, "");
257 269
258 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, 270 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
259 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, 271 base::Bind(&CellularConfigDocument::LoadCellularConfigFile,
260 cellular_config_.get()), 272 cellular_config_.get()),
261 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); 273 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr()));
262 } 274 }
263 275
264 void MobileActivator::ContinueActivation() { 276 void MobileActivator::ContinueActivation() {
265 CellularNetwork* network = FindMatchingCellularNetwork(false); 277 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
266 if (!network || !network->SupportsActivation()) 278 GetNetworkState(service_path_);
279 if (!network ||
280 (network->payment_url().empty() && network->usage_url().empty()))
267 return; 281 return;
268 282
269 DisableCertRevocationChecking(); 283 DisableCertRevocationChecking();
270 // We want shill to connect us after activations.
271 network->SetAutoConnect(true);
272 284
285 // We want shill to connect us after activations, so enable autoconnect.
286 DictionaryValue auto_connect_property;
287 auto_connect_property.SetBoolean(flimflam::kAutoConnectProperty, true);
288 NetworkHandler::Get()->network_configuration_handler()->SetProperties(
289 network->path(),
290 auto_connect_property,
291 base::Bind(&base::DoNothing),
292 network_handler::ErrorCallback());
273 StartActivation(); 293 StartActivation();
274 } 294 }
275 295
276 void MobileActivator::OnSetTransactionStatus(bool success) { 296 void MobileActivator::OnSetTransactionStatus(bool success) {
277 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 297 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
278 base::Bind(&MobileActivator::HandleSetTransactionStatus, 298 base::Bind(&MobileActivator::HandleSetTransactionStatus,
279 AsWeakPtr(), success)); 299 AsWeakPtr(), success));
280 } 300 }
281 301
282 void MobileActivator::HandleSetTransactionStatus(bool success) { 302 void MobileActivator::HandleSetTransactionStatus(bool success) {
283 // The payment is received, try to reconnect and check the status all over 303 // The payment is received, try to reconnect and check the status all over
284 // again. 304 // again.
285 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { 305 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) {
286 NetworkLibrary* lib = GetNetworkLibrary(); 306 SignalCellularPlanPayment();
287 lib->SignalCellularPlanPayment();
288 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); 307 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1);
289 CellularNetwork* network = FindMatchingCellularNetwork(true); 308 const NetworkState* network =
290 if (network && network->activate_over_non_cellular_network()) { 309 NetworkHandler::Get()->network_state_handler()->GetNetworkState(
310 service_path_);
311 if (network && network->activate_over_non_cellular_networks()) {
291 state_ = PLAN_ACTIVATION_DONE; 312 state_ = PLAN_ACTIVATION_DONE;
292 network->CompleteActivation(); 313 NetworkHandler::Get()->network_activation_handler()->
314 CompleteActivation(network->path(),
315 base::Bind(&base::DoNothing),
316 network_handler::ErrorCallback());
293 } else { 317 } else {
294 StartOTASP(); 318 StartOTASP();
295 } 319 }
296 } else { 320 } else {
297 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); 321 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1);
298 } 322 }
299 } 323 }
300 324
301 void MobileActivator::OnPortalLoaded(bool success) { 325 void MobileActivator::OnPortalLoaded(bool success) {
302 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 326 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
303 base::Bind(&MobileActivator::HandlePortalLoaded, 327 base::Bind(&MobileActivator::HandlePortalLoaded,
304 AsWeakPtr(), success)); 328 AsWeakPtr(), success));
305 } 329 }
306 330
307 void MobileActivator::HandlePortalLoaded(bool success) { 331 void MobileActivator::HandlePortalLoaded(bool success) {
308 CellularNetwork* network = FindMatchingCellularNetwork(true); 332 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
333 GetNetworkState(service_path_);
309 if (!network) { 334 if (!network) {
310 ChangeState(NULL, PLAN_ACTIVATION_ERROR, 335 ChangeState(NULL, PLAN_ACTIVATION_ERROR,
311 GetErrorMessage(kErrorNoService)); 336 GetErrorMessage(kErrorNoService));
312 return; 337 return;
313 } 338 }
314 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || 339 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING ||
315 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { 340 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) {
316 if (success) { 341 if (success) {
317 payment_reconnect_count_ = 0; 342 payment_reconnect_count_ = 0;
318 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); 343 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string());
319 } else { 344 } else {
320 // There is no point in forcing reconnecting the cellular network if the 345 // There is no point in forcing reconnecting the cellular network if the
321 // activation should not be done over it. 346 // activation should not be done over it.
322 if (network->activate_over_non_cellular_network()) 347 if (network->activate_over_non_cellular_networks())
323 return; 348 return;
324 349
325 payment_reconnect_count_++; 350 payment_reconnect_count_++;
326 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { 351 if (payment_reconnect_count_ > kMaxPortalReconnectCount) {
327 ChangeState(NULL, PLAN_ACTIVATION_ERROR, 352 ChangeState(NULL, PLAN_ACTIVATION_ERROR,
328 GetErrorMessage(kErrorNoService)); 353 GetErrorMessage(kErrorNoService));
329 return; 354 return;
330 } 355 }
331 356
332 // Reconnect and try and load the frame again. 357 // Reconnect and try and load the frame again.
333 ChangeState(network, 358 ChangeState(network,
334 PLAN_ACTIVATION_RECONNECTING, 359 PLAN_ACTIVATION_RECONNECTING,
335 GetErrorMessage(kFailedPaymentError)); 360 GetErrorMessage(kFailedPaymentError));
336 } 361 }
337 } else { 362 } else {
338 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: " 363 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: "
339 << GetStateDescription(state_); 364 << GetStateDescription(state_);
340 } 365 }
341 } 366 }
342 367
343 CellularNetwork* MobileActivator::FindMatchingCellularNetwork(
344 bool reattach_observer) {
345 NetworkLibrary* lib = GetNetworkLibrary();
346 for (CellularNetworkVector::const_iterator it =
347 lib->cellular_networks().begin();
348 it != lib->cellular_networks().end(); ++it) {
349 const chromeos::NetworkDevice* device =
350 lib->FindNetworkDeviceByPath((*it)->device_path());
351 if (device && ((!meid_.empty() && meid_ == device->meid()) ||
352 (!iccid_.empty() && iccid_ == device->iccid()))) {
353 CellularNetwork* network = *it;
354 // If service path has changed, reattach the event observer for this
355 // network service.
356 if (reattach_observer && service_path_ != network->service_path()) {
357 lib->RemoveObserverForAllNetworks(this);
358 lib->AddNetworkObserver(network->service_path(), this);
359 service_path_ = network->service_path();
360 }
361 return network;
362 }
363 }
364 return NULL;
365 }
366
367 void MobileActivator::StartOTASPTimer() { 368 void MobileActivator::StartOTASPTimer() {
368 state_duration_timer_.Start( 369 state_duration_timer_.Start(
369 FROM_HERE, 370 FROM_HERE,
370 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay), 371 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay),
371 this, &MobileActivator::HandleOTASPTimeout); 372 this, &MobileActivator::HandleOTASPTimeout);
372 } 373 }
373 374
374 void MobileActivator::StartActivation() { 375 void MobileActivator::StartActivation() {
375 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); 376 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1);
376 NetworkLibrary* lib = GetNetworkLibrary(); 377 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
377 CellularNetwork* network = FindMatchingCellularNetwork(true); 378 GetNetworkState(service_path_);
378 // Check if we can start activation process. 379 // Check if we can start activation process.
379 if (!network) { 380 if (!network) {
381 NetworkStateHandler::TechnologyState technology_state =
382 NetworkHandler::Get()->network_state_handler()->GetTechnologyState(
383 flimflam::kTypeCellular);
380 std::string error; 384 std::string error;
381 if (!lib->cellular_available()) 385 if (technology_state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) {
382 error = kErrorNoDevice; 386 error = kErrorNoDevice;
383 else if (!lib->cellular_enabled()) 387 } else if (technology_state !=NetworkStateHandler::TECHNOLOGY_ENABLED) {
384 error = kErrorDisabled; 388 error = kErrorDisabled;
385 else 389 } else {
386 error = kErrorNoService; 390 error = kErrorNoService;
391 }
387 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); 392 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error));
388 return; 393 return;
389 } 394 }
390 395
391 // Start monitoring network property changes. 396 // Start monitoring network property changes.
392 lib->AddNetworkManagerObserver(this); 397 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE);
393 if (network->activate_over_non_cellular_network()) { 398 if (network->activate_over_non_cellular_networks()) {
394 // Fast forward to payment portal loading if the activation is performed 399 // Fast forward to payment portal loading if the activation is performed
395 // over a non-cellular network. 400 // over a non-cellular network.
396 ChangeState(network, 401 ChangeState(
397 (network->activation_state() == ACTIVATION_STATE_ACTIVATED) ? 402 network,
398 PLAN_ACTIVATION_DONE : 403 (network->activation_state() == flimflam::kActivationStateActivated) ?
399 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, 404 PLAN_ACTIVATION_DONE :
400 ""); 405 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING,
406 "");
401 // Verify that there is no need to wait for the connection. This will also 407 // Verify that there is no need to wait for the connection. This will also
402 // evaluate the network. 408 // evaluate the network.
403 OnNetworkManagerChanged(lib); 409 NetworkManagerChanged();
404 return; 410 return;
405 } 411 }
406 412
407 if (lib->HasRecentCellularPlanPayment() && 413 if (HasRecentCellularPlanPayment() &&
408 network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) { 414 (network->activation_state() ==
415 flimflam::kActivationStatePartiallyActivated)) {
409 // Try to start with OTASP immediately if we have received payment recently. 416 // Try to start with OTASP immediately if we have received payment recently.
410 state_ = PLAN_ACTIVATION_START_OTASP; 417 state_ = PLAN_ACTIVATION_START_OTASP;
411 } else { 418 } else {
412 state_ = PLAN_ACTIVATION_START; 419 state_ = PLAN_ACTIVATION_START;
413 } 420 }
414 421
415 EvaluateCellularNetwork(network); 422 EvaluateCellularNetwork(network);
416 } 423 }
417 424
418 void MobileActivator::RetryOTASP() { 425 void MobileActivator::RetryOTASP() {
419 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP); 426 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP);
420 StartOTASP(); 427 StartOTASP();
421 } 428 }
422 429
423 void MobileActivator::StartOTASP() { 430 void MobileActivator::StartOTASP() {
424 CellularNetwork* network = FindMatchingCellularNetwork(true); 431 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
432 GetNetworkState(service_path_);
425 ChangeState(network, PLAN_ACTIVATION_START_OTASP, std::string()); 433 ChangeState(network, PLAN_ACTIVATION_START_OTASP, std::string());
426 EvaluateCellularNetwork(network); 434 EvaluateCellularNetwork(network);
427 } 435 }
428 436
429 void MobileActivator::HandleOTASPTimeout() { 437 void MobileActivator::HandleOTASPTimeout() {
430 LOG(WARNING) << "OTASP seems to be taking too long."; 438 LOG(WARNING) << "OTASP seems to be taking too long.";
431 CellularNetwork* network = FindMatchingCellularNetwork(true); 439 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
440 GetNetworkState(service_path_);
432 // We're here because one of OTASP steps is taking too long to complete. 441 // We're here because one of OTASP steps is taking too long to complete.
433 // Usually, this means something bad has happened below us. 442 // Usually, this means something bad has happened below us.
434 if (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION) { 443 if (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION) {
435 ++initial_OTASP_attempts_; 444 ++initial_OTASP_attempts_;
436 if (initial_OTASP_attempts_ <= kMaxOTASPTries) { 445 if (initial_OTASP_attempts_ <= kMaxOTASPTries) {
437 ChangeState(network, 446 ChangeState(network,
438 PLAN_ACTIVATION_RECONNECTING, 447 PLAN_ACTIVATION_RECONNECTING,
439 GetErrorMessage(kErrorDefault)); 448 GetErrorMessage(kErrorDefault));
440 return; 449 return;
441 } 450 }
(...skipping 16 matching lines...) Expand all
458 } 467 }
459 } else { 468 } else {
460 LOG(ERROR) << "OTASP timed out from a non-OTASP wait state?"; 469 LOG(ERROR) << "OTASP timed out from a non-OTASP wait state?";
461 } 470 }
462 LOG(ERROR) << "OTASP failed too many times; aborting."; 471 LOG(ERROR) << "OTASP failed too many times; aborting.";
463 ChangeState(network, 472 ChangeState(network,
464 PLAN_ACTIVATION_ERROR, 473 PLAN_ACTIVATION_ERROR,
465 GetErrorMessage(kErrorDefault)); 474 GetErrorMessage(kErrorDefault));
466 } 475 }
467 476
468 void MobileActivator::ForceReconnect(CellularNetwork* network, 477 void MobileActivator::ForceReconnect(const NetworkState* network,
469 PlanActivationState next_state) { 478 PlanActivationState next_state) {
470 DCHECK(network); 479 DCHECK(network);
471 // Store away our next destination for when we complete. 480 // Store away our next destination for when we complete.
472 post_reconnect_state_ = next_state; 481 post_reconnect_state_ = next_state;
473 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); 482 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1);
474 // First, disconnect... 483 // First, disconnect...
475 LOG(INFO) << "Disconnecting from " << network->service_path(); 484 LOG(INFO) << "Disconnecting from " << network->path();
476 // Explicit service Disconnect()s disable autoconnect on the service until 485 // Explicit service Disconnect()s disable autoconnect on the service until
477 // Connect() is called on the service again. Hence this dance to explicitly 486 // Connect() is called on the service again. Hence this dance to explicitly
478 // call Connect(). 487 // call Connect().
479 GetNetworkLibrary()->DisconnectFromNetwork(network); 488 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork(
489 network->path(),
490 base::Bind(&base::DoNothing),
491 network_handler::ErrorCallback());
480 // Keep trying to connect until told otherwise. 492 // Keep trying to connect until told otherwise.
481 continue_reconnect_timer_.Stop(); 493 continue_reconnect_timer_.Stop();
482 continue_reconnect_timer_.Start( 494 continue_reconnect_timer_.Start(
483 FROM_HERE, 495 FROM_HERE,
484 base::TimeDelta::FromMilliseconds(kReconnectDelayMS), 496 base::TimeDelta::FromMilliseconds(kReconnectDelayMS),
485 this, &MobileActivator::ContinueConnecting); 497 this, &MobileActivator::ContinueConnecting);
486 // If we don't ever connect again, we're going to call this a failure. 498 // If we don't ever connect again, we're going to call this a failure.
487 reconnect_timeout_timer_.Stop(); 499 reconnect_timeout_timer_.Stop();
488 reconnect_timeout_timer_.Start( 500 reconnect_timeout_timer_.Start(
489 FROM_HERE, 501 FROM_HERE,
490 base::TimeDelta::FromMilliseconds(kMaxReconnectTime), 502 base::TimeDelta::FromMilliseconds(kMaxReconnectTime),
491 this, &MobileActivator::ReconnectTimedOut); 503 this, &MobileActivator::ReconnectTimedOut);
492 } 504 }
493 505
494 void MobileActivator::ReconnectTimedOut() { 506 void MobileActivator::ReconnectTimedOut() {
495 LOG(ERROR) << "Ending activation attempt after failing to reconnect."; 507 LOG(ERROR) << "Ending activation attempt after failing to reconnect.";
496 ChangeState(FindMatchingCellularNetwork(true), 508 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
509 GetNetworkState(service_path_);
510 ChangeState(network,
497 PLAN_ACTIVATION_ERROR, 511 PLAN_ACTIVATION_ERROR,
498 GetErrorMessage(kFailedConnectivity)); 512 GetErrorMessage(kFailedConnectivity));
499 } 513 }
500 514
501 void MobileActivator::ContinueConnecting() { 515 void MobileActivator::ContinueConnecting() {
502 CellularNetwork* network = FindMatchingCellularNetwork(true); 516 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
503 if (network && network->connected()) { 517 GetNetworkState(service_path_);
504 if (network->restricted_pool() && 518 if (network && network->IsConnectedState()) {
505 network->error() == ERROR_DNS_LOOKUP_FAILED) { 519 if (network->connection_state() == flimflam::kStatePortal &&
520 network->error() == flimflam::kErrorDNSLookupFailed) {
506 // It isn't an error to be in a restricted pool, but if DNS doesn't work, 521 // It isn't an error to be in a restricted pool, but if DNS doesn't work,
507 // then we're not getting traffic through at all. Just disconnect and 522 // then we're not getting traffic through at all. Just disconnect and
508 // try again. 523 // try again.
509 GetNetworkLibrary()->DisconnectFromNetwork(network); 524 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork(
525 network->path(),
526 base::Bind(&base::DoNothing),
527 network_handler::ErrorCallback());
510 return; 528 return;
511 } 529 }
512 // Stop this callback 530 // Stop this callback
513 continue_reconnect_timer_.Stop(); 531 continue_reconnect_timer_.Stop();
514 EvaluateCellularNetwork(network); 532 EvaluateCellularNetwork(network);
515 } else { 533 } else {
516 LOG(WARNING) << "Connect failed, will try again in a little bit."; 534 LOG(WARNING) << "Connect failed, will try again in a little bit.";
517 if (network) { 535 if (network) {
518 LOG(INFO) << "Connecting to: " << network->service_path(); 536 LOG(INFO) << "Connecting to: " << network->path();
519 ash::network_connect::ConnectToNetwork( 537 ash::network_connect::ConnectToNetwork(
520 network->service_path(), NULL /* no parent window */); 538 network->path(), NULL /* no parent window */);
521 } 539 }
522 } 540 }
523 } 541 }
524 542
525 void MobileActivator::EvaluateCellularNetwork(CellularNetwork* network) { 543 void MobileActivator::EvaluateCellularNetwork(const NetworkState* network) {
526 if (terminated_) { 544 if (terminated_) {
527 LOG(ERROR) << "Tried to run MobileActivator state machine while " 545 LOG(ERROR) << "Tried to run MobileActivator state machine while "
528 << "terminated."; 546 << "terminated.";
529 return; 547 return;
530 } 548 }
531 549
532 if (!network) { 550 if (!network) {
533 LOG(WARNING) << "Cellular service lost"; 551 LOG(WARNING) << "Cellular service lost";
534 return; 552 return;
535 } 553 }
536 554
537 LOG(WARNING) << "Cellular:\n service=" << network->GetStateString() 555 LOG(WARNING) << "Cellular:\n service state=" << network->connection_state()
538 << "\n ui=" << GetStateDescription(state_) 556 << "\n ui=" << GetStateDescription(state_)
539 << "\n activation=" << network->GetActivationStateString() 557 << "\n activation=" << network->activation_state()
540 << "\n error=" << network->GetErrorString() 558 << "\n error=" << network->error()
541 << "\n setvice_path=" << network->service_path() 559 << "\n setvice_path=" << network->path()
542 << "\n connected=" << network->connected(); 560 << "\n connected=" << network->IsConnectedState();
543 561
544 // If the network is activated over non cellular network, the activator state 562 // If the network is activated over non cellular network, the activator state
545 // does not depend on the network's own state. 563 // does not depend on the network's own state.
546 if (network->activate_over_non_cellular_network()) 564 if (network->activate_over_non_cellular_networks())
547 return; 565 return;
548 566
549 std::string error_description; 567 std::string error_description;
550 PlanActivationState new_state = PickNextState(network, &error_description); 568 PlanActivationState new_state = PickNextState(network, &error_description);
551 569
552 ChangeState(network, new_state, error_description); 570 ChangeState(network, new_state, error_description);
553 } 571 }
554 572
555 MobileActivator::PlanActivationState MobileActivator::PickNextState( 573 MobileActivator::PlanActivationState MobileActivator::PickNextState(
556 CellularNetwork* network, std::string* error_description) const { 574 const NetworkState* network, std::string* error_description) const {
557 PlanActivationState new_state = state_; 575 PlanActivationState new_state = state_;
558 if (!network->connected()) 576 if (!network->IsConnectedState())
559 new_state = PickNextOfflineState(network); 577 new_state = PickNextOfflineState(network);
560 else 578 else
561 new_state = PickNextOnlineState(network); 579 new_state = PickNextOnlineState(network);
562 if (new_state != PLAN_ACTIVATION_ERROR && 580 if (new_state != PLAN_ACTIVATION_ERROR &&
563 GotActivationError(network, error_description)) { 581 GotActivationError(network, error_description)) {
564 // Check for this special case when we try to do activate partially 582 // Check for this special case when we try to do activate partially
565 // activated device. If that attempt failed, try to disconnect to clear the 583 // activated device. If that attempt failed, try to disconnect to clear the
566 // state and reconnect again. 584 // state and reconnect again.
567 if ((network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED || 585 const std::string& activation = network->activation_state();
568 network->activation_state() == ACTIVATION_STATE_ACTIVATING) && 586 bool is_partially_activated =
569 (network->error() == ERROR_NO_ERROR || 587 activation == flimflam::kActivationStatePartiallyActivated ||
570 network->error() == ERROR_OTASP_FAILED) && 588 activation == flimflam::kActivationStateActivating;
571 network->state() == STATE_ACTIVATION_FAILURE) { 589 if (is_partially_activated &&
572 LOG(WARNING) << "Activation failure detected " 590 (network->error().empty() ||
573 << network->service_path(); 591 network->error() == flimflam::kErrorOtaspFailed) &&
592 network->connection_state() == flimflam::kStateActivationFailure) {
593 LOG(WARNING) << "Activation failure detected " << network->path();
574 switch (state_) { 594 switch (state_) {
575 case PLAN_ACTIVATION_OTASP: 595 case PLAN_ACTIVATION_OTASP:
576 new_state = PLAN_ACTIVATION_DELAY_OTASP; 596 new_state = PLAN_ACTIVATION_DELAY_OTASP;
577 break; 597 break;
578 case PLAN_ACTIVATION_INITIATING_ACTIVATION: 598 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
579 case PLAN_ACTIVATION_TRYING_OTASP: 599 case PLAN_ACTIVATION_TRYING_OTASP:
580 new_state = PLAN_ACTIVATION_START; 600 new_state = PLAN_ACTIVATION_START;
581 break; 601 break;
582 case PLAN_ACTIVATION_START: 602 case PLAN_ACTIVATION_START:
583 // We are just starting, so this must be previous activation attempt 603 // We are just starting, so this must be previous activation attempt
584 // failure. 604 // failure.
585 new_state = PLAN_ACTIVATION_TRYING_OTASP; 605 new_state = PLAN_ACTIVATION_TRYING_OTASP;
586 break; 606 break;
587 case PLAN_ACTIVATION_DELAY_OTASP: 607 case PLAN_ACTIVATION_DELAY_OTASP:
588 new_state = state_; 608 new_state = state_;
589 break; 609 break;
590 default: 610 default:
591 new_state = PLAN_ACTIVATION_ERROR; 611 new_state = PLAN_ACTIVATION_ERROR;
592 break; 612 break;
593 } 613 }
594 } else { 614 } else {
595 LOG(WARNING) << "Unexpected activation failure for " 615 LOG(WARNING) << "Unexpected activation failure for " << network->path();
596 << network->service_path();
597 new_state = PLAN_ACTIVATION_ERROR; 616 new_state = PLAN_ACTIVATION_ERROR;
598 } 617 }
599 } 618 }
600 619
601 if (new_state == PLAN_ACTIVATION_ERROR && !error_description->length()) 620 if (new_state == PLAN_ACTIVATION_ERROR && !error_description->length())
602 *error_description = GetErrorMessage(kErrorDefault); 621 *error_description = GetErrorMessage(kErrorDefault);
603 return new_state; 622 return new_state;
604 } 623 }
605 624
606 MobileActivator::PlanActivationState MobileActivator::PickNextOfflineState( 625 MobileActivator::PlanActivationState MobileActivator::PickNextOfflineState(
607 CellularNetwork* network) const { 626 const NetworkState* network) const {
608 PlanActivationState new_state = state_; 627 PlanActivationState new_state = state_;
628 const std::string& activation = network->activation_state();
609 switch (state_) { 629 switch (state_) {
610 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: 630 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING:
611 case PLAN_ACTIVATION_SHOWING_PAYMENT: 631 case PLAN_ACTIVATION_SHOWING_PAYMENT:
612 if (!network->activate_over_non_cellular_network()) 632 if (!network->activate_over_non_cellular_networks())
613 new_state = PLAN_ACTIVATION_RECONNECTING; 633 new_state = PLAN_ACTIVATION_RECONNECTING;
614 break; 634 break;
615 case PLAN_ACTIVATION_START: 635 case PLAN_ACTIVATION_START:
616 switch (network->activation_state()) { 636 if (activation == flimflam::kActivationStateActivated) {
617 case ACTIVATION_STATE_ACTIVATED: 637 if (network->connection_state() == flimflam::kStatePortal)
618 if (network->restricted_pool()) 638 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING;
619 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; 639 else
620 else 640 new_state = PLAN_ACTIVATION_DONE;
621 new_state = PLAN_ACTIVATION_DONE; 641 } else if (activation == flimflam::kActivationStatePartiallyActivated) {
622 break; 642 new_state = PLAN_ACTIVATION_TRYING_OTASP;
623 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: 643 } else {
624 new_state = PLAN_ACTIVATION_TRYING_OTASP; 644 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION;
625 break;
626 default:
627 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION;
628 break;
629 } 645 }
630 break; 646 break;
631 default: { 647 default:
632 LOG(INFO) << "Waiting for cellular service to connect."; 648 LOG(INFO) << "Waiting for cellular service to connect.";
633 } break; 649 break;
634 } 650 }
635 return new_state; 651 return new_state;
636 } 652 }
637 653
638 MobileActivator::PlanActivationState MobileActivator::PickNextOnlineState( 654 MobileActivator::PlanActivationState MobileActivator::PickNextOnlineState(
639 CellularNetwork* network) const { 655 const NetworkState* network) const {
640 PlanActivationState new_state = state_; 656 PlanActivationState new_state = state_;
657 const std::string& activation = network->activation_state();
641 switch (state_) { 658 switch (state_) {
642 case PLAN_ACTIVATION_START: 659 case PLAN_ACTIVATION_START:
643 switch (network->activation_state()) { 660 if (activation == flimflam::kActivationStateActivated) {
644 case ACTIVATION_STATE_ACTIVATED: 661 if (network->connection_state() == flimflam::kStatePortal)
645 if (network->restricted_pool()) 662 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING;
646 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; 663 else
647 else 664 new_state = PLAN_ACTIVATION_DONE;
648 new_state = PLAN_ACTIVATION_DONE; 665 } else if (activation == flimflam::kActivationStatePartiallyActivated) {
649 break; 666 new_state = PLAN_ACTIVATION_TRYING_OTASP;
650 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: 667 } else {
651 new_state = PLAN_ACTIVATION_TRYING_OTASP; 668 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION;
652 break;
653 default:
654 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION;
655 break;
656 } 669 }
657 break; 670 break;
658 case PLAN_ACTIVATION_START_OTASP: { 671 case PLAN_ACTIVATION_START_OTASP: {
659 switch (network->activation_state()) { 672 if (activation == flimflam::kActivationStatePartiallyActivated) {
660 case ACTIVATION_STATE_PARTIALLY_ACTIVATED:
661 new_state = PLAN_ACTIVATION_OTASP; 673 new_state = PLAN_ACTIVATION_OTASP;
662 break; 674 } else if (activation == flimflam::kActivationStateActivated) {
663 case ACTIVATION_STATE_ACTIVATED: 675 new_state = PLAN_ACTIVATION_RECONNECTING;
664 new_state = PLAN_ACTIVATION_RECONNECTING; 676 } else {
665 break; 677 LOG(WARNING) << "Unexpected activation state for device "
666 default: { 678 << network->path();
667 LOG(WARNING) << "Unexpected activation state for device "
668 << network->service_path();
669 break;
670 }
671 } 679 }
672 break; 680 break;
673 } 681 }
674 case PLAN_ACTIVATION_DELAY_OTASP: 682 case PLAN_ACTIVATION_DELAY_OTASP:
675 // Just ignore any changes until the OTASP retry timer kicks in. 683 // Just ignore any changes until the OTASP retry timer kicks in.
676 break; 684 break;
677 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { 685 case PLAN_ACTIVATION_INITIATING_ACTIVATION: {
678 switch (network->activation_state()) { 686 if (activation == flimflam::kActivationStateActivated ||
679 case ACTIVATION_STATE_ACTIVATED: 687 activation == flimflam::kActivationStatePartiallyActivated) {
680 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: 688 new_state = PLAN_ACTIVATION_START;
681 new_state = PLAN_ACTIVATION_START; 689 } else if (activation == flimflam::kActivationStateNotActivated ||
682 break; 690 activation == flimflam::kActivationStateActivating) {
683 case ACTIVATION_STATE_NOT_ACTIVATED: 691 // Wait in this state until activation state changes.
684 case ACTIVATION_STATE_ACTIVATING: 692 } else {
685 // Wait in this state until activation state changes. 693 LOG(WARNING) << "Unknown transition";
686 break;
687 default:
688 LOG(WARNING) << "Unknown transition";
689 break;
690 } 694 }
691 break; 695 break;
692 } 696 }
693 case PLAN_ACTIVATION_OTASP: 697 case PLAN_ACTIVATION_OTASP:
694 case PLAN_ACTIVATION_TRYING_OTASP: 698 case PLAN_ACTIVATION_TRYING_OTASP:
695 if (network->activation_state() == ACTIVATION_STATE_NOT_ACTIVATED || 699 if (activation == flimflam::kActivationStateNotActivated ||
696 network->activation_state() == ACTIVATION_STATE_ACTIVATING) { 700 activation == flimflam::kActivationStateActivating) {
697 LOG(INFO) << "Waiting for the OTASP to finish and the service to " 701 LOG(INFO) << "Waiting for the OTASP to finish and the service to "
698 << "come back online"; 702 << "come back online";
699 } else if (network->activation_state() == ACTIVATION_STATE_ACTIVATED) { 703 } else if (activation == flimflam::kActivationStateActivated) {
700 new_state = PLAN_ACTIVATION_DONE; 704 new_state = PLAN_ACTIVATION_DONE;
701 } else { 705 } else {
702 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; 706 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING;
703 } 707 }
704 break; 708 break;
705 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: 709 case PLAN_ACTIVATION_RECONNECTING_PAYMENT:
706 if (!network->restricted_pool() && 710 if (network->connection_state() != flimflam::kStatePortal &&
707 network->activation_state() == ACTIVATION_STATE_ACTIVATED) 711 activation == flimflam::kActivationStateActivated)
708 // We're not portalled, and we're already activated, so we're online! 712 // We're not portalled, and we're already activated, so we're online!
709 new_state = PLAN_ACTIVATION_DONE; 713 new_state = PLAN_ACTIVATION_DONE;
710 else 714 else
711 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; 715 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING;
712 break; 716 break;
713 // Initial state 717 // Initial state
714 case PLAN_ACTIVATION_PAGE_LOADING: 718 case PLAN_ACTIVATION_PAGE_LOADING:
715 break; 719 break;
716 // Just ignore all signals until the site confirms payment. 720 // Just ignore all signals until the site confirms payment.
717 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: 721 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 return "ERROR"; 764 return "ERROR";
761 case PLAN_ACTIVATION_RECONNECTING: 765 case PLAN_ACTIVATION_RECONNECTING:
762 return "RECONNECTING"; 766 return "RECONNECTING";
763 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: 767 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION:
764 return "WAITING FOR CONNECTION"; 768 return "WAITING FOR CONNECTION";
765 } 769 }
766 return "UNKNOWN"; 770 return "UNKNOWN";
767 } 771 }
768 772
769 773
770 void MobileActivator::CompleteActivation( 774 void MobileActivator::CompleteActivation(const NetworkState* network) {
771 CellularNetwork* network) {
772 // Remove observers, we are done with this page. 775 // Remove observers, we are done with this page.
773 NetworkLibrary* lib = GetNetworkLibrary(); 776 NetworkHandler::Get()->network_state_handler()->RemoveObserver(
774 lib->RemoveNetworkManagerObserver(this); 777 this, FROM_HERE);
775 lib->RemoveObserverForAllNetworks(this); 778
776 // Reactivate other types of connections if we have 779 // Reactivate other types of connections if we have
777 // shut them down previously. 780 // shut them down previously.
778 ReEnableCertRevocationChecking(); 781 ReEnableCertRevocationChecking();
779 } 782 }
780 783
781 bool MobileActivator::RunningActivation() const { 784 bool MobileActivator::RunningActivation() const {
782 return !(state_ == PLAN_ACTIVATION_DONE || 785 return !(state_ == PLAN_ACTIVATION_DONE ||
783 state_ == PLAN_ACTIVATION_ERROR || 786 state_ == PLAN_ACTIVATION_ERROR ||
784 state_ == PLAN_ACTIVATION_PAGE_LOADING); 787 state_ == PLAN_ACTIVATION_PAGE_LOADING);
785 } 788 }
786 789
787 void MobileActivator::ChangeState(CellularNetwork* network, 790 void MobileActivator::HandleActivationFailure(
791 const std::string& service_path,
792 PlanActivationState new_state,
793 const std::string& error_name,
794 scoped_ptr<base::DictionaryValue> error_data) {
795 const NetworkState* network =
796 NetworkHandler::Get()->network_state_handler()->GetNetworkState(
797 service_path);
798 if (!network)
799 NET_LOG_ERROR("Cellular service no longer exists", service_path);
stevenjb 2013/08/14 21:58:35 Need to return here; ChangeState does not safely h
gauravsh 2013/08/15 01:46:35 Done.
800 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1);
801 NET_LOG_ERROR("Failed to call Activate() on service", service_path);
802 if (new_state == PLAN_ACTIVATION_OTASP) {
803 ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string());
804 } else {
805 ChangeState(network,
806 PLAN_ACTIVATION_ERROR,
807 GetErrorMessage(kFailedConnectivity));
808 }
809 }
810
811 void MobileActivator::ChangeState(const NetworkState* network,
788 PlanActivationState new_state, 812 PlanActivationState new_state,
789 const std::string& error_description) { 813 const std::string& error_description) {
790 static bool first_time = true; 814 static bool first_time = true;
791 LOG(INFO) << "Activation state flip old = " 815 LOG(INFO) << "Activation state flip old = "
792 << GetStateDescription(state_) 816 << GetStateDescription(state_)
793 << ", new = " << GetStateDescription(new_state); 817 << ", new = " << GetStateDescription(new_state);
794 if (state_ == new_state && !first_time) 818 if (state_ == new_state && !first_time)
795 return; 819 return;
796 first_time = false; 820 first_time = false;
797 LOG(INFO) << "Transitioning..."; 821 LOG(INFO) << "Transitioning...";
798 822
799 // Kill all the possible timers and callbacks we might have outstanding. 823 // Kill all the possible timers and callbacks we might have outstanding.
800 state_duration_timer_.Stop(); 824 state_duration_timer_.Stop();
801 continue_reconnect_timer_.Stop(); 825 continue_reconnect_timer_.Stop();
802 reconnect_timeout_timer_.Stop(); 826 reconnect_timeout_timer_.Stop();
803 const PlanActivationState old_state = state_; 827 const PlanActivationState old_state = state_;
804 state_ = new_state; 828 state_ = new_state;
805 829
806 // Signal to observers layer that the state is changing. 830 // Signal to observers layer that the state is changing.
807 FOR_EACH_OBSERVER(Observer, observers_, 831 FOR_EACH_OBSERVER(Observer, observers_,
808 OnActivationStateChanged(network, state_, error_description)); 832 OnActivationStateChanged(network, state_, error_description));
809 833
834 network_handler::ErrorCallback on_activation_error =
835 base::Bind(&MobileActivator::HandleActivationFailure, AsWeakPtr(),
836 network->path(),
837 new_state);
810 // Pick action that should happen on entering the new state. 838 // Pick action that should happen on entering the new state.
811 switch (new_state) { 839 switch (new_state) {
812 case PLAN_ACTIVATION_START: 840 case PLAN_ACTIVATION_START:
813 break; 841 break;
814 case PLAN_ACTIVATION_DELAY_OTASP: { 842 case PLAN_ACTIVATION_DELAY_OTASP: {
815 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); 843 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1);
816 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, 844 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
817 base::Bind(&MobileActivator::RetryOTASP, AsWeakPtr()), 845 base::Bind(&MobileActivator::RetryOTASP, AsWeakPtr()),
818 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay)); 846 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay));
819 break; 847 break;
820 } 848 }
821 case PLAN_ACTIVATION_START_OTASP: 849 case PLAN_ACTIVATION_START_OTASP:
822 break; 850 break;
823 case PLAN_ACTIVATION_INITIATING_ACTIVATION: 851 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
824 case PLAN_ACTIVATION_TRYING_OTASP: 852 case PLAN_ACTIVATION_TRYING_OTASP:
825 case PLAN_ACTIVATION_OTASP: 853 case PLAN_ACTIVATION_OTASP:
826 DCHECK(network); 854 DCHECK(network);
827 LOG(WARNING) << "Activating service " << network->service_path(); 855 NET_LOG_EVENT("Activating cellular service", network->path());
828 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); 856 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1);
829 if (!network->StartActivation()) { 857 NetworkHandler::Get()->network_activation_handler()->
830 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); 858 Activate(network->path(),
831 LOG(ERROR) << "Failed to call Activate() on service in shill."; 859 "", // carrier
832 if (new_state == PLAN_ACTIVATION_OTASP) { 860 base::Bind(&MobileActivator::StartOTASPTimer, AsWeakPtr()),
833 ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); 861 on_activation_error);
834 } else {
835 ChangeState(network,
836 PLAN_ACTIVATION_ERROR,
837 GetErrorMessage(kFailedConnectivity));
838 }
839 } else {
840 StartOTASPTimer();
841 }
842 break; 862 break;
843 case PLAN_ACTIVATION_PAGE_LOADING: 863 case PLAN_ACTIVATION_PAGE_LOADING:
844 return; 864 return;
845 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: 865 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING:
846 case PLAN_ACTIVATION_SHOWING_PAYMENT: 866 case PLAN_ACTIVATION_SHOWING_PAYMENT:
847 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: 867 case PLAN_ACTIVATION_RECONNECTING_PAYMENT:
848 // Fix for fix SSL for the walled gardens where cert chain verification 868 // Fix for fix SSL for the walled gardens where cert chain verification
849 // might not work. 869 // might not work.
850 break; 870 break;
851 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: 871 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION:
852 post_reconnect_state_ = old_state; 872 post_reconnect_state_ = old_state;
853 break; 873 break;
854 case PLAN_ACTIVATION_RECONNECTING: { 874 case PLAN_ACTIVATION_RECONNECTING: {
855 PlanActivationState next_state = old_state; 875 PlanActivationState next_state = old_state;
856 // Pick where we want to return to after we reconnect. 876 // Pick where we want to return to after we reconnect.
857 switch (old_state) { 877 switch (old_state) {
858 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: 878 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING:
859 case PLAN_ACTIVATION_SHOWING_PAYMENT: 879 case PLAN_ACTIVATION_SHOWING_PAYMENT:
860 // We decide here what to do next based on the state of the modem. 880 // We decide here what to do next based on the state of the modem.
861 next_state = PLAN_ACTIVATION_RECONNECTING_PAYMENT; 881 next_state = PLAN_ACTIVATION_RECONNECTING_PAYMENT;
862 break; 882 break;
863 case PLAN_ACTIVATION_INITIATING_ACTIVATION: 883 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
864 case PLAN_ACTIVATION_TRYING_OTASP: 884 case PLAN_ACTIVATION_TRYING_OTASP:
865 next_state = PLAN_ACTIVATION_START; 885 next_state = PLAN_ACTIVATION_START;
866 break; 886 break;
867 case PLAN_ACTIVATION_START_OTASP: 887 case PLAN_ACTIVATION_START_OTASP:
868 case PLAN_ACTIVATION_OTASP: 888 case PLAN_ACTIVATION_OTASP:
869 if (!network || !network->connected()) { 889 if (!network || !network->IsConnectedState()) {
870 next_state = PLAN_ACTIVATION_START_OTASP; 890 next_state = PLAN_ACTIVATION_START_OTASP;
871 } else { 891 } else {
872 // We're online, which means we've conspired with 892 // We're online, which means we've conspired with
873 // PickNextOnlineState to reconnect after activation (that's the 893 // PickNextOnlineState to reconnect after activation (that's the
874 // only way we see this transition). Thus, after we reconnect, we 894 // only way we see this transition). Thus, after we reconnect, we
875 // should be done. 895 // should be done.
876 next_state = PLAN_ACTIVATION_DONE; 896 next_state = PLAN_ACTIVATION_DONE;
877 } 897 }
878 break; 898 break;
879 default: 899 default:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 PrefService* prefs = g_browser_process->local_state(); 934 PrefService* prefs = g_browser_process->local_state();
915 if (!reenable_cert_check_ && 935 if (!reenable_cert_check_ &&
916 prefs->GetBoolean( 936 prefs->GetBoolean(
917 prefs::kCertRevocationCheckingEnabled)) { 937 prefs::kCertRevocationCheckingEnabled)) {
918 reenable_cert_check_ = true; 938 reenable_cert_check_ = true;
919 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); 939 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false);
920 } 940 }
921 } 941 }
922 942
923 bool MobileActivator::GotActivationError( 943 bool MobileActivator::GotActivationError(
924 CellularNetwork* network, std::string* error) const { 944 const NetworkState* network, std::string* error) const {
925 DCHECK(network); 945 DCHECK(network);
926 bool got_error = false; 946 bool got_error = false;
927 const char* error_code = kErrorDefault; 947 const char* error_code = kErrorDefault;
948 const std::string& activation = network->activation_state();
928 949
929 // This is the magic for detection of errors in during activation process. 950 // This is the magic for detection of errors in during activation process.
930 if (network->state() == STATE_FAILURE && 951 if (network->connection_state() == flimflam::kStateFailure &&
931 network->error() == ERROR_AAA_FAILED) { 952 network->error() == flimflam::kErrorAaaFailed) {
932 if (network->activation_state() == 953 if (activation == flimflam::kActivationStatePartiallyActivated) {
933 ACTIVATION_STATE_PARTIALLY_ACTIVATED) {
934 error_code = kErrorBadConnectionPartial; 954 error_code = kErrorBadConnectionPartial;
935 } else if (network->activation_state() == ACTIVATION_STATE_ACTIVATED) { 955 } else if (activation == flimflam::kActivationStateActivated) {
936 if (network->roaming_state() == ROAMING_STATE_HOME) 956 if (network->roaming() == flimflam::kRoamingStateHome)
937 error_code = kErrorBadConnectionActivated; 957 error_code = kErrorBadConnectionActivated;
938 else if (network->roaming_state() == ROAMING_STATE_ROAMING) 958 else if (network->roaming() == flimflam::kRoamingStateRoaming)
939 error_code = kErrorRoamingOnConnection; 959 error_code = kErrorRoamingOnConnection;
940 } 960 }
941 got_error = true; 961 got_error = true;
942 } else if (network->state() == STATE_ACTIVATION_FAILURE) { 962 } else if (network->connection_state() == flimflam::kStateActivationFailure) {
943 if (network->error() == ERROR_NEED_EVDO) { 963 if (network->error() == flimflam::kErrorNeedEvdo) {
944 if (network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) 964 if (activation == flimflam::kActivationStatePartiallyActivated)
945 error_code = kErrorNoEVDO; 965 error_code = kErrorNoEVDO;
946 } else if (network->error() == ERROR_NEED_HOME_NETWORK) { 966 } else if (network->error() == flimflam::kErrorNeedHomeNetwork) {
947 if (network->activation_state() == ACTIVATION_STATE_NOT_ACTIVATED) { 967 if (activation == flimflam::kActivationStateNotActivated) {
948 error_code = kErrorRoamingActivation; 968 error_code = kErrorRoamingActivation;
949 } else if (network->activation_state() == 969 } else if (activation == flimflam::kActivationStatePartiallyActivated) {
950 ACTIVATION_STATE_PARTIALLY_ACTIVATED) {
951 error_code = kErrorRoamingPartiallyActivated; 970 error_code = kErrorRoamingPartiallyActivated;
952 } 971 }
953 } 972 }
954 got_error = true; 973 got_error = true;
955 } 974 }
956 975
957 if (got_error) 976 if (got_error)
958 *error = GetErrorMessage(error_code); 977 *error = GetErrorMessage(error_code);
959 978
960 return got_error; 979 return got_error;
961 } 980 }
962 981
963 void MobileActivator::GetDeviceInfo(CellularNetwork* network, 982 void MobileActivator::GetDeviceInfo(const NetworkState* network,
964 DictionaryValue* value) { 983 DictionaryValue* value) {
965 DCHECK(network); 984 DCHECK(network);
966 NetworkLibrary* cros = NetworkLibrary::Get();
967 if (!cros)
968 return;
969 value->SetString("carrier", network->name()); 985 value->SetString("carrier", network->name());
970 value->SetString("payment_url", network->payment_url()); 986 value->SetString("payment_url", network->payment_url());
971 if (network->using_post() && network->post_data().length()) 987 if (network->post_method() == "post" && !network->post_data().empty())
972 value->SetString("post_data", network->post_data()); 988 value->SetString("post_data", network->post_data());
973 989
974 const NetworkDevice* device = 990 const DeviceState* device =
975 cros->FindNetworkDeviceByPath(network->device_path()); 991 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
992 network->device_path());
976 if (device) { 993 if (device) {
977 value->SetString("MEID", device->meid()); 994 value->SetString("MEID", device->meid());
978 value->SetString("IMEI", device->imei()); 995 value->SetString("IMEI", device->imei());
979 value->SetString("MDN", device->mdn()); 996 value->SetString("MDN", device->mdn());
980 } 997 }
981 } 998 }
982 999
983 std::string MobileActivator::GetErrorMessage(const std::string& code) const { 1000 std::string MobileActivator::GetErrorMessage(const std::string& code) const {
984 return cellular_config_->GetErrorMessage(code); 1001 return cellular_config_->GetErrorMessage(code);
985 } 1002 }
986 1003
987 NetworkLibrary* MobileActivator::GetNetworkLibrary() const { 1004 void MobileActivator::SignalCellularPlanPayment() {
988 return NetworkLibrary::Get(); 1005 DCHECK(!HasRecentCellularPlanPayment());
1006 cellular_plan_payment_time_ = base::Time::Now();
1007 }
1008
1009 bool MobileActivator::HasRecentCellularPlanPayment() const {
1010 const int kRecentPlanPaymentHours = 6;
1011 return (base::Time::Now() -
1012 cellular_plan_payment_time_).InHours() < kRecentPlanPaymentHours;
989 } 1013 }
990 1014
991 } // namespace chromeos 1015 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/mobile/mobile_activator.h ('k') | chrome/browser/chromeos/mobile/mobile_activator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698