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

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

Powered by Google App Engine
This is Rietveld 408576698