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

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
522 568 void MobileSetupHandler::StartOTASP() {
523 void MobileSetupHandler::ConnectToNetwork(chromeos::CellularNetwork* network) { 569 state_ = PLAN_ACTIVATION_START_OTASP;
524 DCHECK(network); 570 chromeos::CellularNetwork* network = GetCellularNetwork();
525 LOG(INFO) << "Connecting to " << 571 if (network &&
526 network->service_path().c_str(); 572 network->connected() &&
527 connection_retry_count_++; 573 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED) {
528 connection_start_time_ = base::Time::Now(); 574 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
529 if (!chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 575 DisconnectFromWirelessNetwork(network);
530 ConnectToCellularNetwork(network)) { 576 } else {
531 LOG(WARNING) << "Connect failed for service " 577 EvaluateCellularNetwork(network);
532 << network->service_path().c_str();
533 } 578 }
534 } 579 }
535 580
536 void MobileSetupHandler::ForceReconnect(chromeos::CellularNetwork* network) { 581 void MobileSetupHandler::ReconnectTimerFired() {
582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
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 " <<
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 &&
Charlie Lee 2011/01/14 19:26:05 Why we are returning false if state is not equal t
zel 2011/01/14 20:26:54 Connection business should only happen in one of R
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 }
640 connection_retry_count_++;
641 connection_start_time_ = base::Time::Now();
642 if (!network || !chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
643 ConnectToCellularNetwork(network)) {
644 LOG(WARNING) << "Connect attempt failed";
645 // If we coudn't connect during reconnection phase, try to reconnect
646 // with a delay (and try to reconnect if needed).
647 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(),
648 delay);
649 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
650 NewRunnableMethod(task.get(), &TaskProxy::ContinueConnecting),
651 delay);
652 return false;
653 }
654 return true;
655 }
656
657 void MobileSetupHandler::ForceReconnect(chromeos::CellularNetwork* network,
658 int delay) {
537 DCHECK(network); 659 DCHECK(network);
538 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); 660 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1);
539 // Reset reconnect metrics. 661 // Reset reconnect metrics.
540 connection_retry_count_ = 0; 662 connection_retry_count_ = 0;
541 connection_start_time_ = base::Time(); 663 connection_start_time_ = base::Time();
542 // First, disconnect... 664 // First, disconnect...
543 LOG(INFO) << "Disconnecting from " << 665 LOG(INFO) << "Disconnecting from " <<
544 network->service_path().c_str(); 666 network->service_path().c_str();
545 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 667 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
546 DisconnectFromWirelessNetwork(network); 668 DisconnectFromWirelessNetwork(network);
547 // Check the network state 3s after we disconnect to make sure. 669 // Check the network state 3s after we disconnect to make sure.
548 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 670 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(),
549 std::string()); 671 delay);
550 const int kReconnectDelayMS = 3000;
551 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, 672 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
552 NewRunnableMethod(task.get(), &TaskProxy::ContinueActivation), 673 NewRunnableMethod(task.get(), &TaskProxy::ContinueConnecting),
553 kReconnectDelayMS); 674 delay);
554 } 675 }
555 676
556 bool MobileSetupHandler::ConnectionTimeout() { 677 bool MobileSetupHandler::ConnectionTimeout() {
557 return (base::Time::Now() - 678 return (base::Time::Now() -
558 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds; 679 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds;
559 } 680 }
560 681
561 void MobileSetupHandler::EvaluateCellularNetwork( 682 void MobileSetupHandler::EvaluateCellularNetwork(
562 chromeos::CellularNetwork* network) { 683 chromeos::CellularNetwork* network) {
563 if (!dom_ui_) 684 if (!dom_ui_)
564 return; 685 return;
565 686
566 PlanActivationState new_state = state_; 687 PlanActivationState new_state = state_;
567 if (!network) { 688 if (!network) {
568 LOG(WARNING) << "Cellular service lost"; 689 LOG(WARNING) << "Cellular service lost";
569 if (state_ == PLAN_ACTIVATION_RECONNECTING) { 690 if (state_ == PLAN_ACTIVATION_RECONNECTING_OTASP_TRY ||
691 state_ == PLAN_ACTIVATION_RECONNECTING ||
692 state_ == PLAN_ACTIVATION_RECONNECTING_OTASP) {
570 // This might be the legit case when service is lost after activation. 693 // 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. 694 // We need to make sure we force reconnection as soon as it shows up.
572 LOG(INFO) << "Force service reconnection"; 695 LOG(INFO) << "Force service reconnection";
573 connection_start_time_ = base::Time(); 696 connection_start_time_ = base::Time();
574 } 697 }
575 return; 698 return;
576 } 699 }
577 700
578 // Prevent this method from being called if it is already on the stack. 701 // Prevent this method from being called if it is already on the stack.
579 // This might happen on some state transitions (ie. connect, disconnect). 702 // This might happen on some state transitions (ie. connect, disconnect).
580 if (evaluating_) 703 if (evaluating_)
581 return; 704 return;
582 evaluating_ = true; 705 evaluating_ = true;
583 std::string error_description; 706 std::string error_description;
584 707
585 LOG(INFO) << "Cellular:\n service=" << network->GetStateString().c_str() 708 LOG(WARNING) << "Cellular:\n service=" << network->GetStateString().c_str()
586 << "\n ui=" << GetStateDescription(state_) 709 << "\n ui=" << GetStateDescription(state_)
587 << "\n activation=" << network->GetActivationStateString().c_str() 710 << "\n activation=" << network->GetActivationStateString().c_str()
588 << "\n connectivity=" 711 << "\n connectivity="
589 << network->GetConnectivityStateString().c_str() 712 << network->GetConnectivityStateString().c_str()
590 << "\n error=" << network->GetErrorString().c_str() 713 << "\n error=" << network->GetErrorString().c_str()
591 << "\n setvice_path=" << network->service_path().c_str(); 714 << "\n setvice_path=" << network->service_path().c_str();
592 switch (state_) { 715 switch (state_) {
593 case PLAN_ACTIVATION_START: { 716 case PLAN_ACTIVATION_START: {
594 switch (network->activation_state()) { 717 switch (network->activation_state()) {
595 case chromeos::ACTIVATION_STATE_ACTIVATED: { 718 case chromeos::ACTIVATION_STATE_ACTIVATED: {
596 if (network->failed_or_disconnected()) { 719 if (network->failed_or_disconnected()) {
597 new_state = PLAN_ACTIVATION_RECONNECTING; 720 new_state = PLAN_ACTIVATION_RECONNECTING;
598 } else if (network->connected()) { 721 } else if (network->connected()) {
599 if (network->restricted_pool()) { 722 if (network->restricted_pool()) {
600 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 723 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
601 } else { 724 } else {
602 new_state = PLAN_ACTIVATION_DONE; 725 new_state = PLAN_ACTIVATION_DONE;
603 } 726 }
604 } 727 }
605 break; 728 break;
606 } 729 }
607 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: { 730 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()) { 731 if (network->failed_or_disconnected()) {
636 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; 732 new_state = (network->activation_state() ==
733 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) ?
734 PLAN_ACTIVATION_TRYING_OTASP :
735 PLAN_ACTIVATION_INITIATING_ACTIVATION;
637 } else if (network->connected()) { 736 } else if (network->connected()) {
638 LOG(INFO) << "Disconnecting from " << 737 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; 738 return;
646 } 739 }
647 break; 740 break;
648 } 741 }
649 default:
650 break;
651 } 742 }
652 break; 743 break;
653 } 744 }
654 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { 745 case PLAN_ACTIVATION_START_OTASP: {
746 switch (network->activation_state()) {
747 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: {
748 if (network->failed_or_disconnected()) {
749 new_state = PLAN_ACTIVATION_OTASP;
750 } else if (network->connected()) {
751 DisconnectFromNetwork(network);
752 return;
753 }
754 break;
755 }
756 case chromeos::ACTIVATION_STATE_ACTIVATED:
757 new_state = PLAN_ACTIVATION_RECONNECTING_OTASP;
758 break;
759 default: {
760 LOG(WARNING) << "Unexpected activation state for device "
761 << network->service_path().c_str();
762 break;
763 }
764 }
765 break;
766 }
767 case PLAN_ACTIVATION_DELAY_OTASP:
768 // Just ignore any changes until the OTASP retry timer kicks in.
769 evaluating_ = false;
770 return;
771 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
772 case PLAN_ACTIVATION_OTASP:
773 case PLAN_ACTIVATION_TRYING_OTASP: {
655 switch (network->activation_state()) { 774 switch (network->activation_state()) {
656 case chromeos::ACTIVATION_STATE_ACTIVATED: 775 case chromeos::ACTIVATION_STATE_ACTIVATED:
657 if (network->failed_or_disconnected()) { 776 if (network->failed_or_disconnected()) {
658 new_state = PLAN_ACTIVATION_RECONNECTING; 777 new_state = GetNextReconnectState(state_);
659 } else if (network->connected()) { 778 } else if (network->connected()) {
660 if (network->restricted_pool()) { 779 if (network->restricted_pool()) {
661 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 780 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
662 } else { 781 } else {
663 new_state = PLAN_ACTIVATION_DONE; 782 new_state = PLAN_ACTIVATION_DONE;
664 } 783 }
665 } 784 }
666 break; 785 break;
667 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: 786 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
668 if (network->connected()) { 787 if (network->connected()) {
669 if (network->restricted_pool()) 788 if (network->restricted_pool())
670 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 789 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
671 } else { 790 } else {
672 new_state = PLAN_ACTIVATION_RECONNECTING; 791 new_state = GetNextReconnectState(state_);
673 } 792 }
674 break; 793 break;
675 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: 794 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED:
795 case chromeos::ACTIVATION_STATE_ACTIVATING:
676 // Wait in this state until activation state changes. 796 // Wait in this state until activation state changes.
677 break; 797 break;
678 case chromeos::ACTIVATION_STATE_ACTIVATING:
679 break;
680 default: 798 default:
681 break; 799 break;
682 } 800 }
683 break; 801 break;
684 } 802 }
685 case PLAN_ACTIVATION_RECONNECTING: { 803 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
804 case PLAN_ACTIVATION_RECONNECTING: {
Charlie Lee 2011/01/14 19:26:05 nit: don't need this extra space
zel 2011/01/14 20:26:54 Done.
686 if (network->connected()) { 805 if (network->connected()) {
687 // Make sure other networks are not interfering with our detection of 806 // Make sure other networks are not interfering with our detection of
688 // restricted pool. 807 // restricted pool.
689 DisableOtherNetworks(); 808 DisableOtherNetworks();
690 // Wait until the service shows up and gets activated. 809 // Wait until the service shows up and gets activated.
691 switch (network->activation_state()) { 810 switch (network->activation_state()) {
692 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: 811 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
693 case chromeos::ACTIVATION_STATE_ACTIVATED: 812 case chromeos::ACTIVATION_STATE_ACTIVATED:
694 if (network->connectivity_state() == 813 if (network->connectivity_state() ==
695 chromeos::CONN_STATE_NONE) { 814 chromeos::CONN_STATE_NONE) {
696 LOG(WARNING) << "No connectivity for device " 815 LOG(WARNING) << "No connectivity for device "
697 << network->service_path().c_str(); 816 << network->service_path().c_str();
698 // If we are connected but there is no connectivity at all, 817 // If we are connected but there is no connectivity at all,
699 // restart the whole process again. 818 // restart the whole process again.
700 new_state = PLAN_ACTIVATION_ERROR;
701 if (activation_attempt_ < kMaxActivationAttempt) { 819 if (activation_attempt_ < kMaxActivationAttempt) {
702 activation_attempt_++; 820 activation_attempt_++;
703 ForceReconnect(network); 821 ForceReconnect(network, kFailedReconnectDelayMS);
704 evaluating_ = false; 822 evaluating_ = false;
705 return; 823 return;
706 } else { 824 } else {
825 new_state = PLAN_ACTIVATION_ERROR;
707 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetryFailure", 1); 826 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetryFailure", 1);
708 error_description = GetErrorMessage(kFailedConnectivity); 827 error_description = GetErrorMessage(kFailedConnectivity);
709 } 828 }
710 } else if (network->connectivity_state() == 829 } else if (network->connectivity_state() ==
711 chromeos::CONN_STATE_RESTRICTED) { 830 chromeos::CONN_STATE_RESTRICTED) {
831 // If we have already received payment, don't show the payment
832 // page again. We should try to reconnect after some time instead.
712 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; 833 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT;
713 } else if (network->activation_state() == 834 } else if (network->activation_state() ==
714 chromeos::ACTIVATION_STATE_ACTIVATED) { 835 chromeos::ACTIVATION_STATE_ACTIVATED) {
715 new_state = PLAN_ACTIVATION_DONE; 836 new_state = PLAN_ACTIVATION_DONE;
716 } 837 }
717 break; 838 break;
718 default: 839 default:
719 break; 840 break;
720 } 841 }
721 } else if (network->failed() || ConnectionTimeout()) { 842 } else if (NeedsReconnecting(network, &new_state, &error_description)) {
722 // Try to reconnect again if reconnect failed, or if for some 843 evaluating_ = false;
723 // reasons we are still not connected after 30 seconds. 844 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 } 845 }
736 break; 846 break;
737 } 847 }
848 case PLAN_ACTIVATION_RECONNECTING_OTASP: {
849 if (network->connected()) {
850 // Make sure other networks are not interfering with our detection of
851 // restricted pool.
852 DisableOtherNetworks();
853 // Wait until the service shows up and gets activated.
854 switch (network->activation_state()) {
855 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
856 case chromeos::ACTIVATION_STATE_ACTIVATED:
857 if (network->connectivity_state() == chromeos::CONN_STATE_NONE ||
858 network->connectivity_state() ==
859 chromeos::CONN_STATE_RESTRICTED) {
860 LOG(WARNING) << "Still no connectivity after OTASP for device "
861 << network->service_path().c_str();
862 // If we have already received payment, don't show the payment
863 // page again. We should try to reconnect after some time instead.
864 if (reconnect_wait_count_ < kMaxReconnectAttemptOTASP) {
865 reconnect_wait_count_++;
866 ForceReconnect(network, kPostPaymentReconnectDelayMS);
867 evaluating_ = false;
868 return;
869 } else {
870 new_state = PLAN_ACTIVATION_ERROR;
871 UMA_HISTOGRAM_COUNTS("Cellular.PostPaymentConnectFailure", 1);
872 error_description = GetErrorMessage(kFailedConnectivity);
873 }
874 } else if (network->connectivity_state() ==
875 chromeos::CONN_STATE_UNRESTRICTED) {
876 new_state = PLAN_ACTIVATION_DONE;
877 }
878 break;
879 default:
880 break;
881 }
882 } else if (NeedsReconnecting(network, &new_state, &error_description)) {
883 evaluating_ = false;
884 return;
885 }
886 break;
887 }
738 case PLAN_ACTIVATION_PAGE_LOADING: 888 case PLAN_ACTIVATION_PAGE_LOADING:
739 break; 889 break;
740 // Just ignore all signals until the site confirms payment. 890 // Just ignore all signals until the site confirms payment.
741 case PLAN_ACTIVATION_SHOWING_PAYMENT: 891 case PLAN_ACTIVATION_SHOWING_PAYMENT:
742 // Activation completed/failed, ignore network changes. 892 // Activation completed/failed, ignore network changes.
743 case PLAN_ACTIVATION_DONE: 893 case PLAN_ACTIVATION_DONE:
744 case PLAN_ACTIVATION_ERROR: 894 case PLAN_ACTIVATION_ERROR:
745 break; 895 break;
746 } 896 }
747 897
748 if (new_state != PLAN_ACTIVATION_ERROR && 898 if (new_state != PLAN_ACTIVATION_ERROR &&
749 GotActivationError(network, &error_description)) { 899 GotActivationError(network, &error_description)) {
750 // Check for this special case when we try to do activate partially 900 // 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 901 // activated device. If that attempt failed, try to disconnect to clear the
752 // state and reconnect again. 902 // state and reconnect again.
753 if ((network->activation_state() == 903 if ((network->activation_state() ==
754 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED || 904 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED ||
755 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING) && 905 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING) &&
756 (network->error() == chromeos::ERROR_UNKNOWN || 906 (network->error() == chromeos::ERROR_UNKNOWN ||
757 network->error() == chromeos::ERROR_OTASP_FAILED)&& 907 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) { 908 network->connection_state() == chromeos::STATE_ACTIVATION_FAILURE) {
762 new_state = PLAN_ACTIVATION_RECONNECTING; 909 LOG(WARNING) << "Activation failure detected "
910 << network->service_path().c_str();
911 switch (state_) {
912 case PLAN_ACTIVATION_OTASP:
913 case PLAN_ACTIVATION_RECONNECTING_OTASP:
914 new_state = PLAN_ACTIVATION_DELAY_OTASP;
915 break;
916 case PLAN_ACTIVATION_TRYING_OTASP:
917 new_state = PLAN_ACTIVATION_RECONNECTING_OTASP_TRY;
918 break;
919 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
920 new_state = PLAN_ACTIVATION_RECONNECTING;
921 break;
922 case PLAN_ACTIVATION_DELAY_OTASP:
923 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
924 case PLAN_ACTIVATION_RECONNECTING:
925 new_state = state_;
926 break;
927 default:
928 new_state = PLAN_ACTIVATION_ERROR;
929 break;
930 }
763 } else { 931 } else {
764 new_state = PLAN_ACTIVATION_ERROR; 932 new_state = PLAN_ACTIVATION_ERROR;
765 } 933 }
766 } 934 }
935
936 if (new_state == PLAN_ACTIVATION_ERROR && !error_description.length())
937 error_description = GetErrorMessage(kFailedConnectivity);
938
767 ChangeState(network, new_state, error_description); 939 ChangeState(network, new_state, error_description);
768 evaluating_ = false; 940 evaluating_ = false;
769 } 941 }
770 942
943 MobileSetupHandler::PlanActivationState
944 MobileSetupHandler::GetNextReconnectState(
945 MobileSetupHandler::PlanActivationState state) {
946 switch (state) {
947 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
948 return PLAN_ACTIVATION_RECONNECTING;
949 case PLAN_ACTIVATION_OTASP:
950 return PLAN_ACTIVATION_RECONNECTING_OTASP;
951 case PLAN_ACTIVATION_TRYING_OTASP:
952 return PLAN_ACTIVATION_RECONNECTING_OTASP_TRY;
953 default:
954 return PLAN_ACTIVATION_RECONNECTING;
955 }
956 }
957
771 // Debugging helper function, will take it out at the end. 958 // Debugging helper function, will take it out at the end.
772 const char* MobileSetupHandler::GetStateDescription( 959 const char* MobileSetupHandler::GetStateDescription(
773 PlanActivationState state) { 960 PlanActivationState state) {
774 switch (state) { 961 switch (state) {
775 case PLAN_ACTIVATION_PAGE_LOADING: 962 case PLAN_ACTIVATION_PAGE_LOADING:
776 return "PAGE_LOADING"; 963 return "PAGE_LOADING";
777 case PLAN_ACTIVATION_START: 964 case PLAN_ACTIVATION_START:
778 return "ACTIVATION_START"; 965 return "ACTIVATION_START";
966 case PLAN_ACTIVATION_TRYING_OTASP:
967 return "TRYING_OTASP";
968 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
969 return "RECONNECTING_OTASP_TRY";
779 case PLAN_ACTIVATION_INITIATING_ACTIVATION: 970 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
780 return "INITIATING_ACTIVATION"; 971 return "INITIATING_ACTIVATION";
781 case PLAN_ACTIVATION_RECONNECTING: 972 case PLAN_ACTIVATION_RECONNECTING:
782 return "RECONNECTING"; 973 return "RECONNECTING";
783 case PLAN_ACTIVATION_SHOWING_PAYMENT: 974 case PLAN_ACTIVATION_SHOWING_PAYMENT:
784 return "SHOWING_PAYMENT"; 975 return "SHOWING_PAYMENT";
976 case PLAN_ACTIVATION_START_OTASP:
977 return "START_OTASP";
978 case PLAN_ACTIVATION_DELAY_OTASP:
979 return "DELAY_OTASP";
980 case PLAN_ACTIVATION_OTASP:
981 return "OTASP";
982 case PLAN_ACTIVATION_RECONNECTING_OTASP:
983 return "RECONNECTING_OTASP";
785 case PLAN_ACTIVATION_DONE: 984 case PLAN_ACTIVATION_DONE:
786 return "DONE"; 985 return "DONE";
787 case PLAN_ACTIVATION_ERROR: 986 case PLAN_ACTIVATION_ERROR:
788 return "ERROR"; 987 return "ERROR";
789 } 988 }
790 return "UNKNOWN"; 989 return "UNKNOWN";
791 } 990 }
792 991
793 992
794 void MobileSetupHandler::CompleteActivation( 993 void MobileSetupHandler::CompleteActivation(
(...skipping 18 matching lines...) Expand all
813 DictionaryValue device_dict; 1012 DictionaryValue device_dict;
814 if (network) 1013 if (network)
815 GetDeviceInfo(network, &device_dict); 1014 GetDeviceInfo(network, &device_dict);
816 device_dict.SetInteger("state", state_); 1015 device_dict.SetInteger("state", state_);
817 if (error_description.length()) 1016 if (error_description.length())
818 device_dict.SetString("error", error_description); 1017 device_dict.SetString("error", error_description);
819 dom_ui_->CallJavascriptFunction( 1018 dom_ui_->CallJavascriptFunction(
820 kJsDeviceStatusChangedHandler, device_dict); 1019 kJsDeviceStatusChangedHandler, device_dict);
821 } 1020 }
822 1021
1022
823 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, 1023 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network,
824 PlanActivationState new_state, 1024 PlanActivationState new_state,
825 const std::string& error_description) { 1025 const std::string& error_description) {
826 static bool first_time = true; 1026 static bool first_time = true;
827 if (state_ == new_state && !first_time) 1027 if (state_ == new_state && !first_time)
828 return; 1028 return;
829 LOG(INFO) << "Activation state flip old = " << 1029 LOG(WARNING) << "Activation state flip old = "
830 GetStateDescription(state_) << ", new = " << 1030 << GetStateDescription(state_)
831 GetStateDescription(new_state); 1031 << ", new = " << GetStateDescription(new_state);
832 first_time = false; 1032 first_time = false;
1033
1034 // Pick action that should happen on leaving the old state.
1035 switch (state_) {
1036 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
1037 case PLAN_ACTIVATION_RECONNECTING:
1038 case PLAN_ACTIVATION_RECONNECTING_OTASP:
1039 if (reconnect_timer_.IsRunning()) {
1040 reconnect_timer_.Stop();
1041 }
1042 break;
1043 default:
1044 break;
1045 }
833 state_ = new_state; 1046 state_ = new_state;
834 1047
835 // Signal to JS layer that the state is changing. 1048 // Signal to JS layer that the state is changing.
836 UpdatePage(network, error_description); 1049 UpdatePage(network, error_description);
837 1050
838 // Decide what to do with network object as a result of the new state. 1051 // Pick action that should happen on entering the new state.
839 switch (new_state) { 1052 switch (new_state) {
840 case PLAN_ACTIVATION_START: 1053 case PLAN_ACTIVATION_START:
841 break; 1054 break;
1055 case PLAN_ACTIVATION_DELAY_OTASP: {
1056 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1);
1057 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0);
1058 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
1059 NewRunnableMethod(task.get(), &TaskProxy::RetryOTASP),
1060 kOTASPRetryDelay);
1061 break;
1062 }
842 case PLAN_ACTIVATION_INITIATING_ACTIVATION: 1063 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
1064 case PLAN_ACTIVATION_TRYING_OTASP:
1065 case PLAN_ACTIVATION_OTASP:
843 DCHECK(network); 1066 DCHECK(network);
844 LOG(INFO) << "Activating service " << network->service_path().c_str(); 1067 LOG(WARNING) << "Activating service " << network->service_path().c_str();
845 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); 1068 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1);
846 if (!network->StartActivation()) { 1069 if (!network->StartActivation()) {
847 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); 1070 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1);
848 ChangeState(network, PLAN_ACTIVATION_ERROR, std::string()); 1071 ChangeState(network, PLAN_ACTIVATION_ERROR, std::string());
849 } 1072 }
850 break; 1073 break;
851 case PLAN_ACTIVATION_RECONNECTING: { 1074 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
1075 case PLAN_ACTIVATION_RECONNECTING:
1076 case PLAN_ACTIVATION_RECONNECTING_OTASP: {
1077 // Start reconnect timer. This will ensure that we are not left in
1078 // limbo by the network library.
1079 if (!reconnect_timer_.IsRunning()) {
1080 reconnect_timer_.Start(
1081 base::TimeDelta::FromMilliseconds(kReconnectTimerDelayMS),
1082 this, &MobileSetupHandler::ReconnectTimerFired);
1083 }
852 // Reset connection metrics and try to connect. 1084 // Reset connection metrics and try to connect.
1085 reconnect_wait_count_ = 0;
853 connection_retry_count_ = 0; 1086 connection_retry_count_ = 0;
854 connection_start_time_ = base::Time::Now(); 1087 connection_start_time_ = base::Time::Now();
855 ConnectToNetwork(network); 1088 ConnectToNetwork(network, kReconnectDelayMS);
856 break; 1089 break;
857 } 1090 }
858 case PLAN_ACTIVATION_PAGE_LOADING: 1091 case PLAN_ACTIVATION_PAGE_LOADING:
859 return; 1092 return;
860 case PLAN_ACTIVATION_SHOWING_PAYMENT: 1093 case PLAN_ACTIVATION_SHOWING_PAYMENT:
861 // Fix for fix SSL for the walled gardens where cert chain verification 1094 // Fix for fix SSL for the walled gardens where cert chain verification
862 // might not work. 1095 // might not work.
863 break; 1096 break;
864 case PLAN_ACTIVATION_DONE: 1097 case PLAN_ACTIVATION_DONE:
865 DCHECK(network); 1098 DCHECK(network);
866 CompleteActivation(network); 1099 CompleteActivation(network);
867 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupSucceeded", 1); 1100 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupSucceeded", 1);
868 break; 1101 break;
869 case PLAN_ACTIVATION_ERROR: { 1102 case PLAN_ACTIVATION_ERROR:
870 CompleteActivation(NULL); 1103 CompleteActivation(NULL);
871 UMA_HISTOGRAM_COUNTS("Cellular.PlanFailed", 1); 1104 UMA_HISTOGRAM_COUNTS("Cellular.PlanFailed", 1);
872 break; 1105 break;
873 }
874 default: 1106 default:
875 break; 1107 break;
876 } 1108 }
877 } 1109 }
878 1110
879 void MobileSetupHandler::ReEnableOtherConnections() { 1111 void MobileSetupHandler::ReEnableOtherConnections() {
880 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> 1112 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()->
881 GetNetworkLibrary(); 1113 GetNetworkLibrary();
882 if (reenable_ethernet_) { 1114 if (reenable_ethernet_) {
883 reenable_ethernet_ = false; 1115 reenable_ethernet_ = false;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 new MobileSetupUIHTMLSource(service_path); 1264 new MobileSetupUIHTMLSource(service_path);
1033 1265
1034 // Set up the chrome://mobilesetup/ source. 1266 // Set up the chrome://mobilesetup/ source.
1035 BrowserThread::PostTask( 1267 BrowserThread::PostTask(
1036 BrowserThread::IO, FROM_HERE, 1268 BrowserThread::IO, FROM_HERE,
1037 NewRunnableMethod( 1269 NewRunnableMethod(
1038 ChromeURLDataManager::GetInstance(), 1270 ChromeURLDataManager::GetInstance(),
1039 &ChromeURLDataManager::AddDataSource, 1271 &ChromeURLDataManager::AddDataSource,
1040 make_scoped_refptr(html_source))); 1272 make_scoped_refptr(html_source)));
1041 } 1273 }
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