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

Side by Side Diff: chrome/browser/chromeos/dom_ui/mobile_setup_ui.cc

Issue 5861001: Activation process improvements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/resources/mobile_setup.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 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/dom_ui/mobile_setup_ui.h" 5 #include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.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 "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
13 #include "base/callback.h" 13 #include "base/callback.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/json/json_writer.h" 16 #include "base/json/json_writer.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/string_piece.h" 19 #include "base/string_piece.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "base/timer.h"
22 #include "base/values.h" 23 #include "base/values.h"
23 #include "base/weak_ptr.h" 24 #include "base/weak_ptr.h"
24 #include "chrome/browser/browser_list.h" 25 #include "chrome/browser/browser_list.h"
25 #include "chrome/browser/browser_thread.h" 26 #include "chrome/browser/browser_thread.h"
26 #include "chrome/browser/chromeos/cros/cros_library.h" 27 #include "chrome/browser/chromeos/cros/cros_library.h"
27 #include "chrome/browser/chromeos/cros/network_library.h" 28 #include "chrome/browser/chromeos/cros/network_library.h"
28 #include "chrome/browser/chromeos/cros/system_library.h" 29 #include "chrome/browser/chromeos/cros/system_library.h"
29 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" 30 #include "chrome/browser/dom_ui/chrome_url_data_manager.h"
30 #include "chrome/browser/prefs/pref_service.h" 31 #include "chrome/browser/prefs/pref_service.h"
31 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 "/usr/share/chromeos-assets/mobile/mobile_config.json"; 67 "/usr/share/chromeos-assets/mobile/mobile_config.json";
67 68
68 // Cellular config file field names. 69 // Cellular config file field names.
69 const char kVersionField[] = "version"; 70 const char kVersionField[] = "version";
70 const char kErrorsField[] = "errors"; 71 const char kErrorsField[] = "errors";
71 72
72 // Number of times we will retry to restart the activation process in case 73 // Number of times we will retry to restart the activation process in case
73 // there is no connectivity in the restricted pool. 74 // there is no connectivity in the restricted pool.
74 const int kMaxActivationAttempt = 3; 75 const int kMaxActivationAttempt = 3;
75 // Number of times we will retry to reconnect if connection fails. 76 // Number of times we will retry to reconnect if connection fails.
76 const int kMaxConnectionRetry = 3; 77 const int kMaxConnectionRetry = 10;
78 // Number of times we will retry to reconnect if connection fails.
79 const int kMaxConnectionRetryOTASP = 30;
80 // Number of times we will retry to reconnect after payment is processed.
81 const int kMaxReconnectAttemptOTASP = 30;
82 // Reconnect retry delay (after payment is processed).
83 const int kPostPaymentReconnectDelayMS = 30000; // 30s.
77 // Connection timeout in seconds. 84 // Connection timeout in seconds.
78 const int kConnectionTimeoutSeconds = 30; 85 const int kConnectionTimeoutSeconds = 45;
86 // Reconnect delay.
87 const int kReconnectDelayMS = 3000;
88 // Reconnect timer delay.
89 const int kReconnectTimerDelayMS = 1000;
90 // Reconnect delay after previous failure.
91 const int kFailedReconnectDelayMS = 10000;
92 // Retry delay after failed OTASP attempt.
93 const int kOTASPRetryDelay = 10000;
79 94
80 chromeos::CellularNetwork* GetCellularNetwork() { 95 chromeos::CellularNetwork* GetCellularNetwork() {
81 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> 96 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->
82 GetNetworkLibrary(); 97 GetNetworkLibrary();
83 if (lib->cellular_networks().begin() != lib->cellular_networks().end()) { 98 if (lib->cellular_networks().begin() != lib->cellular_networks().end()) {
84 return *(lib->cellular_networks().begin()); 99 return *(lib->cellular_networks().begin());
85 } 100 }
86 return NULL; 101 return NULL;
87 } 102 }
88 103
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 virtual void RegisterMessages(); 165 virtual void RegisterMessages();
151 166
152 // NetworkLibrary::NetworkManagerObserver implementation. 167 // NetworkLibrary::NetworkManagerObserver implementation.
153 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* obj); 168 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* obj);
154 // NetworkLibrary::NetworkObserver implementation. 169 // NetworkLibrary::NetworkObserver implementation.
155 virtual void OnNetworkChanged(chromeos::NetworkLibrary* obj, 170 virtual void OnNetworkChanged(chromeos::NetworkLibrary* obj,
156 const chromeos::Network* network); 171 const chromeos::Network* network);
157 172
158 private: 173 private:
159 typedef enum PlanActivationState { 174 typedef enum PlanActivationState {
160 PLAN_ACTIVATION_PAGE_LOADING = -1, 175 PLAN_ACTIVATION_PAGE_LOADING = -1,
161 PLAN_ACTIVATION_START = 0, 176 PLAN_ACTIVATION_START = 0,
162 PLAN_ACTIVATION_INITIATING_ACTIVATION = 1, 177 PLAN_ACTIVATION_TRYING_OTASP = 1,
163 PLAN_ACTIVATION_RECONNECTING = 2, 178 PLAN_ACTIVATION_RECONNECTING_OTASP_TRY = 2,
164 PLAN_ACTIVATION_SHOWING_PAYMENT = 3, 179 PLAN_ACTIVATION_INITIATING_ACTIVATION = 3,
165 PLAN_ACTIVATION_DONE = 4, 180 PLAN_ACTIVATION_RECONNECTING = 4,
166 PLAN_ACTIVATION_ERROR = 5, 181 PLAN_ACTIVATION_SHOWING_PAYMENT = 5,
182 PLAN_ACTIVATION_DELAY_OTASP = 6,
183 PLAN_ACTIVATION_START_OTASP = 7,
184 PLAN_ACTIVATION_OTASP = 8,
185 PLAN_ACTIVATION_RECONNECTING_OTASP = 9,
186 PLAN_ACTIVATION_DONE = 10,
187 PLAN_ACTIVATION_ERROR = 0xFF,
167 } PlanActivationState; 188 } PlanActivationState;
168 189
169 class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { 190 class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> {
170 public: 191 public:
171 explicit TaskProxy(const base::WeakPtr<MobileSetupHandler>& handler) 192 TaskProxy(const base::WeakPtr<MobileSetupHandler>& handler, int delay)
172 : handler_(handler) { 193 : handler_(handler), delay_(delay) {
173 } 194 }
174 TaskProxy(const base::WeakPtr<MobileSetupHandler>& handler, 195 TaskProxy(const base::WeakPtr<MobileSetupHandler>& handler,
175 const std::string& status) 196 const std::string& status)
176 : handler_(handler), status_(status) { 197 : handler_(handler), status_(status) {
177 } 198 }
178 void HandleStartActivation() { 199 void HandleStartActivation() {
179 if (handler_) 200 if (handler_)
180 handler_->StartActivation(); 201 handler_->StartActivation();
181 } 202 }
182 void HandleSetTransactionStatus() { 203 void HandleSetTransactionStatus() {
183 if (handler_) 204 if (handler_)
184 handler_->SetTransactionStatus(status_); 205 handler_->SetTransactionStatus(status_);
185 } 206 }
186 void ContinueActivation() { 207 void ContinueConnecting() {
187 if (handler_) 208 if (handler_)
188 handler_->ContinueActivation(); 209 handler_->ContinueConnecting(delay_);
210 }
211 void RetryOTASP() {
212 if (handler_)
213 handler_->RetryOTASP();
189 } 214 }
190 private: 215 private:
191 base::WeakPtr<MobileSetupHandler> handler_; 216 base::WeakPtr<MobileSetupHandler> handler_;
192 std::string status_; 217 std::string status_;
218 int delay_;
193 DISALLOW_COPY_AND_ASSIGN(TaskProxy); 219 DISALLOW_COPY_AND_ASSIGN(TaskProxy);
194 }; 220 };
195 221
196 // Handlers for JS DOMUI messages. 222 // Handlers for JS DOMUI messages.
197 void HandleSetTransactionStatus(const ListValue* args); 223 void HandleSetTransactionStatus(const ListValue* args);
198 void HandleStartActivation(const ListValue* args); 224 void HandleStartActivation(const ListValue* args);
199 void SetTransactionStatus(const std::string& status); 225 void SetTransactionStatus(const std::string& status);
200 // Schedules activation process via task proxy. 226 // Schedules activation process via task proxy.
201 void InitiateActivation(); 227 void InitiateActivation();
202 // Starts activation. 228 // Starts activation.
203 void StartActivation(); 229 void StartActivation();
230 // Retried OTASP.
231 void RetryOTASP();
204 // Continues activation process. This method is called after we disconnect 232 // Continues activation process. This method is called after we disconnect
205 // due to detected connectivity issue to kick off reconnection. 233 // due to detected connectivity issue to kick off reconnection.
206 void ContinueActivation(); 234 void ContinueConnecting(int delay);
207 235
208 // Sends message to host registration page with system/user info data. 236 // Sends message to host registration page with system/user info data.
209 void SendDeviceInfo(); 237 void SendDeviceInfo();
210 238
239 // Callback for when |reconnect_timer_| fires.
240 void ReconnectTimerFired();
241 // Starts OTASP process.
242 void StartOTASP();
243 // Checks if we need to reconnect due to failed connection attempt.
244 bool NeedsReconnecting(chromeos::CellularNetwork* network,
245 PlanActivationState* new_state,
246 std::string* error_description);
247 // Disconnect from network.
248 void DisconnectFromNetwork(chromeos::CellularNetwork* network);
211 // Connects to cellular network, resets connection timer. 249 // Connects to cellular network, resets connection timer.
212 void ConnectToNetwork(chromeos::CellularNetwork* network); 250 bool ConnectToNetwork(chromeos::CellularNetwork* network, int delay);
213 // Forces disconnect / reconnect when we detect portal connectivity issues. 251 // Forces disconnect / reconnect when we detect portal connectivity issues.
214 void ForceReconnect(chromeos::CellularNetwork* network); 252 void ForceReconnect(chromeos::CellularNetwork* network, int delay);
215 // Reports connection timeout. 253 // Reports connection timeout.
216 bool ConnectionTimeout(); 254 bool ConnectionTimeout();
217 // Verify the state of cellular network and modify internal state. 255 // Verify the state of cellular network and modify internal state.
218 void EvaluateCellularNetwork(chromeos::CellularNetwork* network); 256 void EvaluateCellularNetwork(chromeos::CellularNetwork* network);
219 // Check the current cellular network for error conditions. 257 // Check the current cellular network for error conditions.
220 bool GotActivationError(const chromeos::CellularNetwork* network, 258 bool GotActivationError(const chromeos::CellularNetwork* network,
221 std::string* error); 259 std::string* error);
222 // Sends status updates to DOMUI page. 260 // Sends status updates to DOMUI page.
223 void UpdatePage(chromeos::CellularNetwork* network, 261 void UpdatePage(chromeos::CellularNetwork* network,
224 const std::string& error_description); 262 const std::string& error_description);
(...skipping 22 matching lines...) Expand all
247 // Returns false if device activation failed. In this case |error| 285 // Returns false if device activation failed. In this case |error|
248 // will contain error message to be reported to DOM UI. 286 // will contain error message to be reported to DOM UI.
249 static bool EvaluateCellularDeviceState(bool* report_status, 287 static bool EvaluateCellularDeviceState(bool* report_status,
250 std::string* state, 288 std::string* state,
251 std::string* error); 289 std::string* error);
252 290
253 // Return error message for a given code. 291 // Return error message for a given code.
254 static std::string GetErrorMessage(const std::string& code); 292 static std::string GetErrorMessage(const std::string& code);
255 static void LoadCellularConfig(); 293 static void LoadCellularConfig();
256 294
295 // Returns next reconnection state based on the current activation phase.
296 static PlanActivationState GetNextReconnectState(PlanActivationState state);
257 static const char* GetStateDescription(PlanActivationState state); 297 static const char* GetStateDescription(PlanActivationState state);
258 298
259 static scoped_ptr<CellularConfigDocument> cellular_config_; 299 static scoped_ptr<CellularConfigDocument> cellular_config_;
260 300
261 TabContents* tab_contents_; 301 TabContents* tab_contents_;
262 // Internal handler state. 302 // Internal handler state.
263 PlanActivationState state_; 303 PlanActivationState state_;
264 std::string service_path_; 304 std::string service_path_;
265 // Flags that control if wifi and ethernet connection needs to be restored 305 // Flags that control if wifi and ethernet connection needs to be restored
266 // after the activation of cellular network. 306 // after the activation of cellular network.
267 bool reenable_wifi_; 307 bool reenable_wifi_;
268 bool reenable_ethernet_; 308 bool reenable_ethernet_;
269 bool reenable_cert_check_; 309 bool reenable_cert_check_;
270 bool transaction_complete_signalled_;
271 bool activation_status_test_;
272 bool evaluating_; 310 bool evaluating_;
273 // Connection retry counter. 311 // Connection retry counter.
274 int connection_retry_count_; 312 int connection_retry_count_;
313 // Post payment reconnect wait counters.
314 int reconnect_wait_count_;
275 // Activation retry attempt count; 315 // Activation retry attempt count;
276 int activation_attempt_; 316 int activation_attempt_;
277 // Connection start time. 317 // Connection start time.
278 base::Time connection_start_time_; 318 base::Time connection_start_time_;
319 // Timer that monitors reconnection timeouts.
320 base::RepeatingTimer<MobileSetupHandler> reconnect_timer_;
321
279 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); 322 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler);
280 }; 323 };
281 324
282 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_; 325 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_;
283 326
284 //////////////////////////////////////////////////////////////////////////////// 327 ////////////////////////////////////////////////////////////////////////////////
285 // 328 //
286 // CellularConfigDocument 329 // CellularConfigDocument
287 // 330 //
288 //////////////////////////////////////////////////////////////////////////////// 331 ////////////////////////////////////////////////////////////////////////////////
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT)); 406 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT));
364 strings.SetString("completed_text", 407 strings.SetString("completed_text",
365 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT)); 408 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT));
366 strings.SetString("close_button", 409 strings.SetString("close_button",
367 l10n_util::GetStringUTF16(IDS_CLOSE)); 410 l10n_util::GetStringUTF16(IDS_CLOSE));
368 SetFontAndTextDirection(&strings); 411 SetFontAndTextDirection(&strings);
369 412
370 static const base::StringPiece html( 413 static const base::StringPiece html(
371 ResourceBundle::GetSharedInstance().GetRawDataResource( 414 ResourceBundle::GetSharedInstance().GetRawDataResource(
372 IDR_MOBILE_SETUP_PAGE_HTML)); 415 IDR_MOBILE_SETUP_PAGE_HTML));
373 const std::string full_html = jstemplate_builder::GetTemplatesHtml( 416
374 html, &strings, "t" /* template root node id */); 417 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
418 html, &strings);
375 419
376 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 420 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
377 html_bytes->data.resize(full_html.size()); 421 html_bytes->data.resize(full_html.size());
378 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); 422 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
379 423
380 SendResponse(request_id, html_bytes); 424 SendResponse(request_id, html_bytes);
381 } 425 }
382 426
383 //////////////////////////////////////////////////////////////////////////////// 427 ////////////////////////////////////////////////////////////////////////////////
384 // 428 //
385 // MobileSetupHandler 429 // MobileSetupHandler
386 // 430 //
387 //////////////////////////////////////////////////////////////////////////////// 431 ////////////////////////////////////////////////////////////////////////////////
388 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) 432 MobileSetupHandler::MobileSetupHandler(const std::string& service_path)
389 : tab_contents_(NULL), 433 : tab_contents_(NULL),
390 state_(PLAN_ACTIVATION_PAGE_LOADING), 434 state_(PLAN_ACTIVATION_PAGE_LOADING),
391 service_path_(service_path), 435 service_path_(service_path),
392 reenable_wifi_(false), 436 reenable_wifi_(false),
393 reenable_ethernet_(false), 437 reenable_ethernet_(false),
394 reenable_cert_check_(false), 438 reenable_cert_check_(false),
395 transaction_complete_signalled_(false),
396 activation_status_test_(false),
397 evaluating_(false), 439 evaluating_(false),
398 connection_retry_count_(0), 440 connection_retry_count_(0),
441 reconnect_wait_count_(0),
399 activation_attempt_(0) { 442 activation_attempt_(0) {
400 } 443 }
401 444
402 MobileSetupHandler::~MobileSetupHandler() { 445 MobileSetupHandler::~MobileSetupHandler() {
446 reconnect_timer_.Stop();
403 chromeos::NetworkLibrary* lib = 447 chromeos::NetworkLibrary* lib =
404 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 448 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
405 lib->RemoveNetworkManagerObserver(this); 449 lib->RemoveNetworkManagerObserver(this);
406 lib->RemoveObserverForAllNetworks(this); 450 lib->RemoveObserverForAllNetworks(this);
407 ReEnableOtherConnections(); 451 ReEnableOtherConnections();
408 } 452 }
409 453
410 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { 454 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) {
411 return DOMMessageHandler::Attach(dom_ui); 455 return DOMMessageHandler::Attach(dom_ui);
412 } 456 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 // Get change callback function name. 501 // Get change callback function name.
458 std::string status; 502 std::string status;
459 if (!args->GetString(0, &status)) 503 if (!args->GetString(0, &status))
460 return; 504 return;
461 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), status); 505 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), status);
462 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 506 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
463 NewRunnableMethod(task.get(), &TaskProxy::HandleSetTransactionStatus)); 507 NewRunnableMethod(task.get(), &TaskProxy::HandleSetTransactionStatus));
464 } 508 }
465 509
466 void MobileSetupHandler::InitiateActivation() { 510 void MobileSetupHandler::InitiateActivation() {
467 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr()); 511 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0);
468 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 512 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
469 NewRunnableMethod(task.get(), &TaskProxy::HandleStartActivation)); 513 NewRunnableMethod(task.get(), &TaskProxy::HandleStartActivation));
470 } 514 }
471 515
472 void MobileSetupHandler::StartActivation() { 516 void MobileSetupHandler::StartActivation() {
473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
474 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); 518 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_);
475 if (!network) { 519 if (!network) {
476 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string()); 520 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string());
477 return; 521 return;
478 } 522 }
479 // Start monitoring network property changes. 523 // Start monitoring network property changes.
480 chromeos::NetworkLibrary* lib = 524 chromeos::NetworkLibrary* lib =
481 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 525 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
482 lib->AddNetworkManagerObserver(this); 526 lib->AddNetworkManagerObserver(this);
483 lib->RemoveObserverForAllNetworks(this); 527 lib->RemoveObserverForAllNetworks(this);
484 lib->AddNetworkObserver(network->service_path(), this); 528 lib->AddNetworkObserver(network->service_path(), this);
485 state_ = PLAN_ACTIVATION_START; 529 // Try to start with OTASP immediately if we have received payment recently.
530 state_ = lib->HasRecentCellularPlanPayment() ?
531 PLAN_ACTIVATION_START_OTASP :
532 PLAN_ACTIVATION_START;
486 EvaluateCellularNetwork(network); 533 EvaluateCellularNetwork(network);
487 } 534 }
488 535
489 void MobileSetupHandler::ContinueActivation() { 536 void MobileSetupHandler::RetryOTASP() {
537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
538 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP);
539 StartOTASP();
540 }
541
542 void MobileSetupHandler::ContinueConnecting(int delay) {
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
491 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); 544 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_);
492 EvaluateCellularNetwork(network); 545 if (network && network->connecting_or_connected()) {
546 EvaluateCellularNetwork(network);
547 } else {
548 ConnectToNetwork(network, delay);
549 }
493 } 550 }
494 551
495 void MobileSetupHandler::SetTransactionStatus(const std::string& status) { 552 void MobileSetupHandler::SetTransactionStatus(const std::string& status) {
496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 553 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
497 // The payment is received, try to reconnect and check the status all over 554 // The payment is received, try to reconnect and check the status all over
498 // again. 555 // again.
499 if (LowerCaseEqualsASCII(status, "ok") && 556 if (LowerCaseEqualsASCII(status, "ok") &&
500 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { 557 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) {
558 chromeos::NetworkLibrary* lib =
559 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
560 lib->SignalCellularPlanPayment();
501 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); 561 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1);
502 if (transaction_complete_signalled_) { 562 StartOTASP();
503 LOG(WARNING) << "Transaction completion signaled more than once!?";
504 return;
505 }
506 transaction_complete_signalled_ = true;
507 activation_status_test_ = false;
508 state_ = PLAN_ACTIVATION_START;
509 chromeos::CellularNetwork* network = GetCellularNetwork();
510 if (network &&
511 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED) {
512 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
513 DisconnectFromWirelessNetwork(network);
514 } else {
515 EvaluateCellularNetwork(network);
516 }
517 } else { 563 } else {
518 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); 564 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1);
519 } 565 }
520 } 566 }
521 567
568 void MobileSetupHandler::StartOTASP() {
569 state_ = PLAN_ACTIVATION_START_OTASP;
570 chromeos::CellularNetwork* network = GetCellularNetwork();
571 if (network &&
572 network->connected() &&
573 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED) {
574 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
575 DisconnectFromWirelessNetwork(network);
576 } else {
577 EvaluateCellularNetwork(network);
578 }
579 }
522 580
523 void MobileSetupHandler::ConnectToNetwork(chromeos::CellularNetwork* network) { 581 void MobileSetupHandler::ReconnectTimerFired() {
524 DCHECK(network); 582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
525 LOG(INFO) << "Connecting to " << 583 if (state_ != PLAN_ACTIVATION_RECONNECTING_OTASP_TRY &&
584 state_ != PLAN_ACTIVATION_RECONNECTING &&
585 state_ != PLAN_ACTIVATION_RECONNECTING_OTASP)
586 return;
587 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_);
588 if (!network) {
589 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string());
590 return;
591 }
592 EvaluateCellularNetwork(network);
593 }
594
595 void MobileSetupHandler::DisconnectFromNetwork(
596 chromeos::CellularNetwork* network) {
597 LOG(INFO) << "Disconnecting from " <<
526 network->service_path().c_str(); 598 network->service_path().c_str();
599 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
600 DisconnectFromWirelessNetwork(network);
601 // Disconnect will force networks to be reevaluated, so
602 // we don't want to continue processing on this path anymore.
603 evaluating_ = false;
604 }
605
606 bool MobileSetupHandler::NeedsReconnecting(chromeos::CellularNetwork* network,
607 PlanActivationState* new_state,
608 std::string* error_description) {
609 if (!network->failed() && !ConnectionTimeout())
610 return false;
611
612 // Try to reconnect again if reconnect failed, or if for some
613 // reasons we are still not connected after 45 seconds.
614 int max_retries = (state_ == PLAN_ACTIVATION_RECONNECTING_OTASP) ?
615 kMaxConnectionRetryOTASP : kMaxConnectionRetry;
616 if (connection_retry_count_ < max_retries) {
617 UMA_HISTOGRAM_COUNTS("Cellular.ConnectionRetry", 1);
618 ConnectToNetwork(network, kFailedReconnectDelayMS);
619 return true;
620 }
621 // We simply can't connect anymore after all these tries.
622 UMA_HISTOGRAM_COUNTS("Cellular.ConnectionFailed", 1);
623 *new_state = PLAN_ACTIVATION_ERROR;
624 *error_description = GetErrorMessage(kFailedConnectivity);
625 return false;
626 }
627
628 bool MobileSetupHandler::ConnectToNetwork(chromeos::CellularNetwork* network,
629 int delay) {
630 if (network && network->connecting_or_connected())
631 return true;
632 if (state_ != PLAN_ACTIVATION_RECONNECTING_OTASP_TRY &&
633 state_ != PLAN_ACTIVATION_RECONNECTING &&
634 state_ != PLAN_ACTIVATION_RECONNECTING_OTASP)
635 return false;
636 if (network) {
637 LOG(INFO) << "Connecting to " <<
638 network->service_path().c_str();
639 }
527 connection_retry_count_++; 640 connection_retry_count_++;
528 connection_start_time_ = base::Time::Now(); 641 connection_start_time_ = base::Time::Now();
529 if (!chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 642 if (!network || !chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
530 ConnectToCellularNetwork(network)) { 643 ConnectToCellularNetwork(network)) {
531 LOG(WARNING) << "Connect failed for service " 644 LOG(WARNING) << "Connect failed for service "
532 << network->service_path().c_str(); 645 << network->service_path().c_str();
Jason Glasgow 2011/01/14 07:58:42 network can be NULL, so it is not okay to log netw
zel 2011/01/14 17:35:02 Done.
646 // If we coudn't connect during reconnection phase, try to reconnect
647 // with a delay (and try to reconnect if needed).
648 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(),
649 delay);
650 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
651 NewRunnableMethod(task.get(), &TaskProxy::ContinueConnecting),
652 delay);
653 return false;
533 } 654 }
655 return true;
534 } 656 }
535 657
536 void MobileSetupHandler::ForceReconnect(chromeos::CellularNetwork* network) { 658 void MobileSetupHandler::ForceReconnect(chromeos::CellularNetwork* network,
659 int delay) {
537 DCHECK(network); 660 DCHECK(network);
538 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); 661 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1);
539 // Reset reconnect metrics. 662 // Reset reconnect metrics.
540 connection_retry_count_ = 0; 663 connection_retry_count_ = 0;
541 connection_start_time_ = base::Time(); 664 connection_start_time_ = base::Time();
542 // First, disconnect... 665 // First, disconnect...
543 LOG(INFO) << "Disconnecting from " << 666 LOG(INFO) << "Disconnecting from " <<
544 network->service_path().c_str(); 667 network->service_path().c_str();
545 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 668 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
546 DisconnectFromWirelessNetwork(network); 669 DisconnectFromWirelessNetwork(network);
547 // Check the network state 3s after we disconnect to make sure. 670 // Check the network state 3s after we disconnect to make sure.
548 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 671 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(),
549 std::string()); 672 delay);
550 const int kReconnectDelayMS = 3000;
551 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, 673 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
552 NewRunnableMethod(task.get(), &TaskProxy::ContinueActivation), 674 NewRunnableMethod(task.get(), &TaskProxy::ContinueConnecting),
553 kReconnectDelayMS); 675 delay);
554 } 676 }
555 677
556 bool MobileSetupHandler::ConnectionTimeout() { 678 bool MobileSetupHandler::ConnectionTimeout() {
557 return (base::Time::Now() - 679 return (base::Time::Now() -
558 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds; 680 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds;
559 } 681 }
560 682
561 void MobileSetupHandler::EvaluateCellularNetwork( 683 void MobileSetupHandler::EvaluateCellularNetwork(
562 chromeos::CellularNetwork* network) { 684 chromeos::CellularNetwork* network) {
563 if (!dom_ui_) 685 if (!dom_ui_)
564 return; 686 return;
565 687
566 PlanActivationState new_state = state_; 688 PlanActivationState new_state = state_;
567 if (!network) { 689 if (!network) {
568 LOG(WARNING) << "Cellular service lost"; 690 LOG(WARNING) << "Cellular service lost";
569 if (state_ == PLAN_ACTIVATION_RECONNECTING) { 691 if (state_ == PLAN_ACTIVATION_RECONNECTING_OTASP_TRY ||
692 state_ == PLAN_ACTIVATION_RECONNECTING ||
693 state_ == PLAN_ACTIVATION_RECONNECTING_OTASP) {
570 // This might be the legit case when service is lost after activation. 694 // This might be the legit case when service is lost after activation.
571 // We need to make sure we force reconnection as soon as it shows up. 695 // We need to make sure we force reconnection as soon as it shows up.
572 LOG(INFO) << "Force service reconnection"; 696 LOG(INFO) << "Force service reconnection";
573 connection_start_time_ = base::Time(); 697 connection_start_time_ = base::Time();
574 } 698 }
575 return; 699 return;
576 } 700 }
577 701
578 // Prevent this method from being called if it is already on the stack. 702 // Prevent this method from being called if it is already on the stack.
579 // This might happen on some state transitions (ie. connect, disconnect). 703 // This might happen on some state transitions (ie. connect, disconnect).
580 if (evaluating_) 704 if (evaluating_)
581 return; 705 return;
582 evaluating_ = true; 706 evaluating_ = true;
583 std::string error_description; 707 std::string error_description;
584 708
585 LOG(INFO) << "Cellular:\n service=" << network->GetStateString().c_str() 709 LOG(WARNING) << "Cellular:\n service=" << network->GetStateString().c_str()
586 << "\n ui=" << GetStateDescription(state_) 710 << "\n ui=" << GetStateDescription(state_)
587 << "\n activation=" << network->GetActivationStateString().c_str() 711 << "\n activation=" << network->GetActivationStateString().c_str()
588 << "\n connectivity=" 712 << "\n connectivity="
589 << network->GetConnectivityStateString().c_str() 713 << network->GetConnectivityStateString().c_str()
590 << "\n error=" << network->GetErrorString().c_str() 714 << "\n error=" << network->GetErrorString().c_str()
591 << "\n setvice_path=" << network->service_path().c_str(); 715 << "\n setvice_path=" << network->service_path().c_str();
592 switch (state_) { 716 switch (state_) {
593 case PLAN_ACTIVATION_START: { 717 case PLAN_ACTIVATION_START: {
594 switch (network->activation_state()) { 718 switch (network->activation_state()) {
595 case chromeos::ACTIVATION_STATE_ACTIVATED: { 719 case chromeos::ACTIVATION_STATE_ACTIVATED: {
596 if (network->failed_or_disconnected()) { 720 if (network->failed_or_disconnected()) {
597 new_state = PLAN_ACTIVATION_RECONNECTING; 721 new_state = PLAN_ACTIVATION_RECONNECTING;
598 } else if (network->connected()) { 722 } else if (network->connected()) {
599 if (network->restricted_pool()) { 723 if (network->restricted_pool()) {
600 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 724 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
601 } else { 725 } else {
602 new_state = PLAN_ACTIVATION_DONE; 726 new_state = PLAN_ACTIVATION_DONE;
603 } 727 }
604 } 728 }
605 break; 729 break;
606 } 730 }
607 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: { 731 default: {
608 if (!activation_status_test_) {
609 if (network->failed_or_disconnected()) {
610 activation_status_test_ = true;
611 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION;
612 } else if (network->connected()) {
613 LOG(INFO) << "Disconnecting from " <<
614 network->service_path().c_str();
615 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
616 DisconnectFromWirelessNetwork(network);
617 // Disconnect will force networks to be reevaluated, so
618 // we don't want to continue processing on this path anymore.
619 evaluating_ = false;
620 return;
621 }
622 } else {
623 if (network->connected()) {
624 if (network->restricted_pool())
625 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
626 } else {
627 new_state = PLAN_ACTIVATION_RECONNECTING;
628 }
629 break;
630 }
631 break;
632 }
633 case chromeos::ACTIVATION_STATE_UNKNOWN:
634 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: {
635 if (network->failed_or_disconnected()) { 732 if (network->failed_or_disconnected()) {
636 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; 733 new_state = (network->activation_state() ==
734 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) ?
735 PLAN_ACTIVATION_TRYING_OTASP :
736 PLAN_ACTIVATION_INITIATING_ACTIVATION;
637 } else if (network->connected()) { 737 } else if (network->connected()) {
638 LOG(INFO) << "Disconnecting from " << 738 DisconnectFromNetwork(network);
639 network->service_path().c_str();
640 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
641 DisconnectFromWirelessNetwork(network);
642 // Disconnect will force networks to be reevaluated, so
643 // we don't want to continue processing on this path anymore.
644 evaluating_ = false;
645 return; 739 return;
646 } 740 }
647 break; 741 break;
648 } 742 }
649 default:
650 break;
651 } 743 }
652 break; 744 break;
653 } 745 }
654 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { 746 case PLAN_ACTIVATION_START_OTASP: {
747 switch (network->activation_state()) {
748 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: {
749 if (network->failed_or_disconnected()) {
750 new_state = PLAN_ACTIVATION_OTASP;
751 } else if (network->connected()) {
752 DisconnectFromNetwork(network);
753 return;
754 }
755 break;
756 }
757 case chromeos::ACTIVATION_STATE_ACTIVATED:
758 new_state = PLAN_ACTIVATION_RECONNECTING_OTASP;
759 break;
760 default: {
761 LOG(WARNING) << "Unexpected activation state for device "
762 << network->service_path().c_str();
763 break;
764 }
765 }
766 break;
767 }
768 case PLAN_ACTIVATION_DELAY_OTASP:
769 // Just ignore any changes until the OTASP retry timer kicks in.
770 evaluating_ = false;
771 return;
772 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
773 case PLAN_ACTIVATION_OTASP:
774 case PLAN_ACTIVATION_TRYING_OTASP: {
655 switch (network->activation_state()) { 775 switch (network->activation_state()) {
656 case chromeos::ACTIVATION_STATE_ACTIVATED: 776 case chromeos::ACTIVATION_STATE_ACTIVATED:
657 if (network->failed_or_disconnected()) { 777 if (network->failed_or_disconnected()) {
658 new_state = PLAN_ACTIVATION_RECONNECTING; 778 new_state = GetNextReconnectState(state_);
659 } else if (network->connected()) { 779 } else if (network->connected()) {
660 if (network->restricted_pool()) { 780 if (network->restricted_pool()) {
661 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 781 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
662 } else { 782 } else {
663 new_state = PLAN_ACTIVATION_DONE; 783 new_state = PLAN_ACTIVATION_DONE;
664 } 784 }
665 } 785 }
666 break; 786 break;
667 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: 787 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
668 if (network->connected()) { 788 if (network->connected()) {
669 if (network->restricted_pool()) 789 if (network->restricted_pool())
670 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 790 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
671 } else { 791 } else {
672 new_state = PLAN_ACTIVATION_RECONNECTING; 792 new_state = GetNextReconnectState(state_);
673 } 793 }
674 break; 794 break;
675 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: 795 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED:
796 case chromeos::ACTIVATION_STATE_ACTIVATING:
676 // Wait in this state until activation state changes. 797 // Wait in this state until activation state changes.
677 break; 798 break;
678 case chromeos::ACTIVATION_STATE_ACTIVATING:
679 break;
680 default: 799 default:
681 break; 800 break;
682 } 801 }
683 break; 802 break;
684 } 803 }
685 case PLAN_ACTIVATION_RECONNECTING: { 804 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
805 case PLAN_ACTIVATION_RECONNECTING: {
686 if (network->connected()) { 806 if (network->connected()) {
687 // Make sure other networks are not interfering with our detection of 807 // Make sure other networks are not interfering with our detection of
688 // restricted pool. 808 // restricted pool.
689 DisableOtherNetworks(); 809 DisableOtherNetworks();
690 // Wait until the service shows up and gets activated. 810 // Wait until the service shows up and gets activated.
691 switch (network->activation_state()) { 811 switch (network->activation_state()) {
692 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: 812 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
693 case chromeos::ACTIVATION_STATE_ACTIVATED: 813 case chromeos::ACTIVATION_STATE_ACTIVATED:
694 if (network->connectivity_state() == 814 if (network->connectivity_state() ==
695 chromeos::CONN_STATE_NONE) { 815 chromeos::CONN_STATE_NONE) {
696 LOG(WARNING) << "No connectivity for device " 816 LOG(WARNING) << "No connectivity for device "
697 << network->service_path().c_str(); 817 << network->service_path().c_str();
698 // If we are connected but there is no connectivity at all, 818 // If we are connected but there is no connectivity at all,
699 // restart the whole process again. 819 // restart the whole process again.
700 new_state = PLAN_ACTIVATION_ERROR;
701 if (activation_attempt_ < kMaxActivationAttempt) { 820 if (activation_attempt_ < kMaxActivationAttempt) {
702 activation_attempt_++; 821 activation_attempt_++;
703 ForceReconnect(network); 822 ForceReconnect(network, kFailedReconnectDelayMS);
704 evaluating_ = false; 823 evaluating_ = false;
705 return; 824 return;
706 } else { 825 } else {
826 new_state = PLAN_ACTIVATION_ERROR;
707 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetryFailure", 1); 827 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetryFailure", 1);
708 error_description = GetErrorMessage(kFailedConnectivity); 828 error_description = GetErrorMessage(kFailedConnectivity);
709 } 829 }
710 } else if (network->connectivity_state() == 830 } else if (network->connectivity_state() ==
711 chromeos::CONN_STATE_RESTRICTED) { 831 chromeos::CONN_STATE_RESTRICTED) {
832 // If we have already received payment, don't show the payment
833 // page again. We should try to reconnect after some time instead.
712 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 834 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
713 } else if (network->activation_state() == 835 } else if (network->activation_state() ==
714 chromeos::ACTIVATION_STATE_ACTIVATED) { 836 chromeos::ACTIVATION_STATE_ACTIVATED) {
715 new_state = PLAN_ACTIVATION_DONE; 837 new_state = PLAN_ACTIVATION_DONE;
716 } 838 }
717 break; 839 break;
718 default: 840 default:
719 break; 841 break;
720 } 842 }
721 } else if (network->failed() || ConnectionTimeout()) { 843 } else if (NeedsReconnecting(network, &new_state, &error_description)) {
722 // Try to reconnect again if reconnect failed, or if for some 844 evaluating_ = false;
723 // reasons we are still not connected after 30 seconds. 845 return;
724 if (connection_retry_count_ < kMaxConnectionRetry) {
725 UMA_HISTOGRAM_COUNTS("Cellular.ConnectionRetry", 1);
726 ConnectToNetwork(network);
727 evaluating_ = false;
728 return;
729 } else {
730 // We simply can't connect anymore after all these tries.
731 UMA_HISTOGRAM_COUNTS("Cellular.ConnectionFailed", 1);
732 new_state = PLAN_ACTIVATION_ERROR;
733 error_description = GetErrorMessage(kFailedConnectivity);
734 }
735 } 846 }
736 break; 847 break;
737 } 848 }
849 case PLAN_ACTIVATION_RECONNECTING_OTASP: {
850 if (network->connected()) {
851 // Make sure other networks are not interfering with our detection of
852 // restricted pool.
853 DisableOtherNetworks();
854 // Wait until the service shows up and gets activated.
855 switch (network->activation_state()) {
856 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
857 case chromeos::ACTIVATION_STATE_ACTIVATED:
858 if (network->connectivity_state() == chromeos::CONN_STATE_NONE ||
859 network->connectivity_state() ==
860 chromeos::CONN_STATE_RESTRICTED) {
861 LOG(WARNING) << "Still no connectivity after OTASP for device "
862 << network->service_path().c_str();
863 // If we have already received payment, don't show the payment
864 // page again. We should try to reconnect after some time instead.
865 if (reconnect_wait_count_ < kMaxReconnectAttemptOTASP) {
866 reconnect_wait_count_++;
867 ForceReconnect(network, kPostPaymentReconnectDelayMS);
868 evaluating_ = false;
869 return;
870 } else {
871 new_state = PLAN_ACTIVATION_ERROR;
872 UMA_HISTOGRAM_COUNTS("Cellular.PostPaymentConnectFailure", 1);
873 error_description = GetErrorMessage(kFailedConnectivity);
874 }
875 } else if (network->connectivity_state() ==
876 chromeos::CONN_STATE_UNRESTRICTED) {
877 new_state = PLAN_ACTIVATION_DONE;
878 }
879 break;
880 default:
881 break;
882 }
883 } else if (NeedsReconnecting(network, &new_state, &error_description)) {
884 evaluating_ = false;
885 return;
886 }
887 break;
888 }
738 case PLAN_ACTIVATION_PAGE_LOADING: 889 case PLAN_ACTIVATION_PAGE_LOADING:
739 break; 890 break;
740 // Just ignore all signals until the site confirms payment. 891 // Just ignore all signals until the site confirms payment.
741 case PLAN_ACTIVATION_SHOWING_PAYMENT: 892 case PLAN_ACTIVATION_SHOWING_PAYMENT:
742 // Activation completed/failed, ignore network changes. 893 // Activation completed/failed, ignore network changes.
743 case PLAN_ACTIVATION_DONE: 894 case PLAN_ACTIVATION_DONE:
744 case PLAN_ACTIVATION_ERROR: 895 case PLAN_ACTIVATION_ERROR:
745 break; 896 break;
746 } 897 }
747 898
748 if (new_state != PLAN_ACTIVATION_ERROR && 899 if (new_state != PLAN_ACTIVATION_ERROR &&
749 GotActivationError(network, &error_description)) { 900 GotActivationError(network, &error_description)) {
750 // Check for this special case when we try to do activate partially 901 // Check for this special case when we try to do activate partially
751 // activated device. If that attempt failed, try to disconnect to clear the 902 // activated device. If that attempt failed, try to disconnect to clear the
752 // state and reconnect again. 903 // state and reconnect again.
753 if ((network->activation_state() == 904 if ((network->activation_state() ==
754 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED || 905 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED ||
755 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING) && 906 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING) &&
756 (network->error() == chromeos::ERROR_UNKNOWN || 907 (network->error() == chromeos::ERROR_UNKNOWN ||
757 network->error() == chromeos::ERROR_OTASP_FAILED)&& 908 network->error() == chromeos::ERROR_OTASP_FAILED) &&
758 (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION ||
759 state_ == PLAN_ACTIVATION_RECONNECTING) &&
760 activation_status_test_ &&
761 network->connection_state() == chromeos::STATE_ACTIVATION_FAILURE) { 909 network->connection_state() == chromeos::STATE_ACTIVATION_FAILURE) {
762 new_state = PLAN_ACTIVATION_RECONNECTING; 910 LOG(WARNING) << "Activation failure detected "
911 << network->service_path().c_str();
912 switch (state_) {
913 case PLAN_ACTIVATION_OTASP:
914 case PLAN_ACTIVATION_RECONNECTING_OTASP:
915 new_state = PLAN_ACTIVATION_DELAY_OTASP;
916 break;
917 case PLAN_ACTIVATION_TRYING_OTASP:
918 new_state = PLAN_ACTIVATION_RECONNECTING_OTASP_TRY;
919 break;
920 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
921 new_state = PLAN_ACTIVATION_RECONNECTING;
922 break;
923 case PLAN_ACTIVATION_DELAY_OTASP:
924 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
925 case PLAN_ACTIVATION_RECONNECTING:
926 new_state = state_;
927 break;
928 default:
929 new_state = PLAN_ACTIVATION_ERROR;
930 break;
931 }
763 } else { 932 } else {
764 new_state = PLAN_ACTIVATION_ERROR; 933 new_state = PLAN_ACTIVATION_ERROR;
765 } 934 }
766 } 935 }
936
937 if (new_state == PLAN_ACTIVATION_ERROR && !error_description.length())
938 error_description = GetErrorMessage(kFailedConnectivity);
939
767 ChangeState(network, new_state, error_description); 940 ChangeState(network, new_state, error_description);
768 evaluating_ = false; 941 evaluating_ = false;
769 } 942 }
770 943
944 MobileSetupHandler::PlanActivationState
945 MobileSetupHandler::GetNextReconnectState(
946 MobileSetupHandler::PlanActivationState state) {
947 switch (state) {
948 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
949 return PLAN_ACTIVATION_RECONNECTING;
950 case PLAN_ACTIVATION_OTASP:
951 return PLAN_ACTIVATION_RECONNECTING_OTASP;
952 case PLAN_ACTIVATION_TRYING_OTASP:
953 return PLAN_ACTIVATION_RECONNECTING_OTASP_TRY;
954 default:
955 return PLAN_ACTIVATION_RECONNECTING;
956 }
957 }
958
771 // Debugging helper function, will take it out at the end. 959 // Debugging helper function, will take it out at the end.
772 const char* MobileSetupHandler::GetStateDescription( 960 const char* MobileSetupHandler::GetStateDescription(
773 PlanActivationState state) { 961 PlanActivationState state) {
774 switch (state) { 962 switch (state) {
775 case PLAN_ACTIVATION_PAGE_LOADING: 963 case PLAN_ACTIVATION_PAGE_LOADING:
776 return "PAGE_LOADING"; 964 return "PAGE_LOADING";
777 case PLAN_ACTIVATION_START: 965 case PLAN_ACTIVATION_START:
778 return "ACTIVATION_START"; 966 return "ACTIVATION_START";
967 case PLAN_ACTIVATION_TRYING_OTASP:
968 return "TRYING_OTASP";
969 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
970 return "RECONNECTING_OTASP_TRY";
779 case PLAN_ACTIVATION_INITIATING_ACTIVATION: 971 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
780 return "INITIATING_ACTIVATION"; 972 return "INITIATING_ACTIVATION";
781 case PLAN_ACTIVATION_RECONNECTING: 973 case PLAN_ACTIVATION_RECONNECTING:
782 return "RECONNECTING"; 974 return "RECONNECTING";
783 case PLAN_ACTIVATION_SHOWING_PAYMENT: 975 case PLAN_ACTIVATION_SHOWING_PAYMENT:
784 return "SHOWING_PAYMENT"; 976 return "SHOWING_PAYMENT";
977 case PLAN_ACTIVATION_START_OTASP:
978 return "START_OTASP";
979 case PLAN_ACTIVATION_DELAY_OTASP:
980 return "DELAY_OTASP";
981 case PLAN_ACTIVATION_OTASP:
982 return "OTASP";
983 case PLAN_ACTIVATION_RECONNECTING_OTASP:
984 return "RECONNECTING_OTASP";
785 case PLAN_ACTIVATION_DONE: 985 case PLAN_ACTIVATION_DONE:
786 return "DONE"; 986 return "DONE";
787 case PLAN_ACTIVATION_ERROR: 987 case PLAN_ACTIVATION_ERROR:
788 return "ERROR"; 988 return "ERROR";
789 } 989 }
790 return "UNKNOWN"; 990 return "UNKNOWN";
791 } 991 }
792 992
793 993
794 void MobileSetupHandler::CompleteActivation( 994 void MobileSetupHandler::CompleteActivation(
(...skipping 18 matching lines...) Expand all
813 DictionaryValue device_dict; 1013 DictionaryValue device_dict;
814 if (network) 1014 if (network)
815 GetDeviceInfo(network, &device_dict); 1015 GetDeviceInfo(network, &device_dict);
816 device_dict.SetInteger("state", state_); 1016 device_dict.SetInteger("state", state_);
817 if (error_description.length()) 1017 if (error_description.length())
818 device_dict.SetString("error", error_description); 1018 device_dict.SetString("error", error_description);
819 dom_ui_->CallJavascriptFunction( 1019 dom_ui_->CallJavascriptFunction(
820 kJsDeviceStatusChangedHandler, device_dict); 1020 kJsDeviceStatusChangedHandler, device_dict);
821 } 1021 }
822 1022
1023
823 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, 1024 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network,
824 PlanActivationState new_state, 1025 PlanActivationState new_state,
825 const std::string& error_description) { 1026 const std::string& error_description) {
826 static bool first_time = true; 1027 static bool first_time = true;
827 if (state_ == new_state && !first_time) 1028 if (state_ == new_state && !first_time)
828 return; 1029 return;
829 LOG(INFO) << "Activation state flip old = " << 1030 LOG(WARNING) << "Activation state flip old = "
830 GetStateDescription(state_) << ", new = " << 1031 << GetStateDescription(state_)
831 GetStateDescription(new_state); 1032 << ", new = " << GetStateDescription(new_state);
832 first_time = false; 1033 first_time = false;
1034
1035 // Pick action that should happen on leaving the old state.
1036 switch (state_) {
1037 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
1038 case PLAN_ACTIVATION_RECONNECTING:
1039 case PLAN_ACTIVATION_RECONNECTING_OTASP:
1040 if (reconnect_timer_.IsRunning()) {
1041 reconnect_timer_.Stop();
1042 }
1043 break;
1044 default:
1045 break;
1046 }
833 state_ = new_state; 1047 state_ = new_state;
834 1048
835 // Signal to JS layer that the state is changing. 1049 // Signal to JS layer that the state is changing.
836 UpdatePage(network, error_description); 1050 UpdatePage(network, error_description);
837 1051
838 // Decide what to do with network object as a result of the new state. 1052 // Pick action that should happen on entering the new state.
839 switch (new_state) { 1053 switch (new_state) {
840 case PLAN_ACTIVATION_START: 1054 case PLAN_ACTIVATION_START:
841 break; 1055 break;
1056 case PLAN_ACTIVATION_DELAY_OTASP: {
1057 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1);
1058 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0);
1059 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
1060 NewRunnableMethod(task.get(), &TaskProxy::RetryOTASP),
1061 kOTASPRetryDelay);
1062 break;
1063 }
842 case PLAN_ACTIVATION_INITIATING_ACTIVATION: 1064 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
1065 case PLAN_ACTIVATION_TRYING_OTASP:
1066 case PLAN_ACTIVATION_OTASP:
843 DCHECK(network); 1067 DCHECK(network);
844 LOG(INFO) << "Activating service " << network->service_path().c_str(); 1068 LOG(WARNING) << "Activating service " << network->service_path().c_str();
845 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); 1069 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1);
846 if (!network->StartActivation()) { 1070 if (!network->StartActivation()) {
847 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); 1071 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1);
848 ChangeState(network, PLAN_ACTIVATION_ERROR, std::string()); 1072 ChangeState(network, PLAN_ACTIVATION_ERROR, std::string());
849 } 1073 }
850 break; 1074 break;
851 case PLAN_ACTIVATION_RECONNECTING: { 1075 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
1076 case PLAN_ACTIVATION_RECONNECTING:
1077 case PLAN_ACTIVATION_RECONNECTING_OTASP: {
1078 // Start reconnect timer. This will ensure that we are not left in
1079 // limbo by the network library.
1080 if (!reconnect_timer_.IsRunning()) {
1081 reconnect_timer_.Start(
1082 base::TimeDelta::FromMilliseconds(kReconnectTimerDelayMS),
1083 this, &MobileSetupHandler::ReconnectTimerFired);
1084 }
852 // Reset connection metrics and try to connect. 1085 // Reset connection metrics and try to connect.
1086 reconnect_wait_count_ = 0;
853 connection_retry_count_ = 0; 1087 connection_retry_count_ = 0;
854 connection_start_time_ = base::Time::Now(); 1088 connection_start_time_ = base::Time::Now();
855 ConnectToNetwork(network); 1089 ConnectToNetwork(network, kReconnectDelayMS);
856 break; 1090 break;
857 } 1091 }
858 case PLAN_ACTIVATION_PAGE_LOADING: 1092 case PLAN_ACTIVATION_PAGE_LOADING:
859 return; 1093 return;
860 case PLAN_ACTIVATION_SHOWING_PAYMENT: 1094 case PLAN_ACTIVATION_SHOWING_PAYMENT:
861 // Fix for fix SSL for the walled gardens where cert chain verification 1095 // Fix for fix SSL for the walled gardens where cert chain verification
862 // might not work. 1096 // might not work.
863 break; 1097 break;
864 case PLAN_ACTIVATION_DONE: 1098 case PLAN_ACTIVATION_DONE:
865 DCHECK(network); 1099 DCHECK(network);
866 CompleteActivation(network); 1100 CompleteActivation(network);
867 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupSucceeded", 1); 1101 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupSucceeded", 1);
868 break; 1102 break;
869 case PLAN_ACTIVATION_ERROR: { 1103 case PLAN_ACTIVATION_ERROR:
870 CompleteActivation(NULL); 1104 CompleteActivation(NULL);
871 UMA_HISTOGRAM_COUNTS("Cellular.PlanFailed", 1); 1105 UMA_HISTOGRAM_COUNTS("Cellular.PlanFailed", 1);
872 break; 1106 break;
873 }
874 default: 1107 default:
875 break; 1108 break;
876 } 1109 }
877 } 1110 }
878 1111
879 void MobileSetupHandler::ReEnableOtherConnections() { 1112 void MobileSetupHandler::ReEnableOtherConnections() {
880 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> 1113 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->
881 GetNetworkLibrary(); 1114 GetNetworkLibrary();
882 if (reenable_ethernet_) { 1115 if (reenable_ethernet_) {
883 reenable_ethernet_ = false; 1116 reenable_ethernet_ = false;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 new MobileSetupUIHTMLSource(service_path); 1265 new MobileSetupUIHTMLSource(service_path);
1033 1266
1034 // Set up the chrome://mobilesetup/ source. 1267 // Set up the chrome://mobilesetup/ source.
1035 BrowserThread::PostTask( 1268 BrowserThread::PostTask(
1036 BrowserThread::IO, FROM_HERE, 1269 BrowserThread::IO, FROM_HERE,
1037 NewRunnableMethod( 1270 NewRunnableMethod(
1038 ChromeURLDataManager::GetInstance(), 1271 ChromeURLDataManager::GetInstance(),
1039 &ChromeURLDataManager::AddDataSource, 1272 &ChromeURLDataManager::AddDataSource,
1040 make_scoped_refptr(html_source))); 1273 make_scoped_refptr(html_source)));
1041 } 1274 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/mobile_setup.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698