| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h" | 5 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 15 #include "base/json/json_writer.h" | |
| 16 #include "base/logging.h" | 15 #include "base/logging.h" |
| 17 #include "base/memory/ref_counted_memory.h" | 16 #include "base/memory/ref_counted_memory.h" |
| 18 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 19 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/observer_list_threadsafe.h" |
| 20 #include "base/string_piece.h" | 20 #include "base/string_piece.h" |
| 21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 22 #include "base/timer.h" | 22 #include "base/timer.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chromeos/cros/cros_library.h" | 26 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 27 #include "chrome/browser/chromeos/cros/network_library.h" | 27 #include "chrome/browser/chromeos/cros/network_library.h" |
| 28 #include "chrome/browser/prefs/pref_service.h" | 28 #include "chrome/browser/prefs/pref_service.h" |
| 29 #include "chrome/browser/profiles/profile.h" | |
| 30 #include "chrome/browser/ui/browser_list.h" | |
| 31 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
| 32 #include "chrome/common/jstemplate_builder.h" | |
| 33 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/common/render_messages.h" | |
| 35 #include "chrome/common/url_constants.h" | |
| 36 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/render_view_host_observer.h" | |
| 38 #include "content/public/browser/web_contents.h" | |
| 39 #include "content/public/browser/web_ui.h" | |
| 40 #include "content/public/browser/web_ui_message_handler.h" | |
| 41 #include "googleurl/src/gurl.h" | |
| 42 #include "grit/browser_resources.h" | |
| 43 #include "grit/chromium_strings.h" | |
| 44 #include "grit/generated_resources.h" | |
| 45 #include "grit/locale_settings.h" | |
| 46 #include "ui/base/l10n/l10n_util.h" | |
| 47 #include "ui/base/layout.h" | |
| 48 #include "ui/base/resource/resource_bundle.h" | |
| 49 | 31 |
| 50 using content::BrowserThread; | 32 using content::BrowserThread; |
| 51 using content::RenderViewHost; | |
| 52 using content::WebContents; | |
| 53 using content::WebUIMessageHandler; | |
| 54 | 33 |
| 55 namespace { | 34 namespace { |
| 56 | 35 |
| 57 // Host page JS API function names. | |
| 58 const char kJsApiStartActivation[] = "startActivation"; | |
| 59 const char kJsApiSetTransactionStatus[] = "setTransactionStatus"; | |
| 60 const char kJsApiPaymentPortalLoad[] = "paymentPortalLoad"; | |
| 61 const char kJsApiResultOK[] = "ok"; | |
| 62 | |
| 63 const char kJsDeviceStatusChangedCallback[] = | |
| 64 "mobile.MobileSetup.deviceStateChanged"; | |
| 65 const char kJsPortalFrameLoadFailedCallback[] = | |
| 66 "mobile.MobileSetup.portalFrameLoadError"; | |
| 67 const char kJsPortalFrameLoadCompletedCallback[] = | |
| 68 "mobile.MobileSetup.portalFrameLoadCompleted"; | |
| 69 | |
| 70 // Error codes matching codes defined in the cellular config file. | |
| 71 const char kErrorDefault[] = "default"; | |
| 72 const char kErrorBadConnectionPartial[] = "bad_connection_partial"; | |
| 73 const char kErrorBadConnectionActivated[] = "bad_connection_activated"; | |
| 74 const char kErrorRoamingOnConnection[] = "roaming_connection"; | |
| 75 const char kErrorNoEVDO[] = "no_evdo"; | |
| 76 const char kErrorRoamingActivation[] = "roaming_activation"; | |
| 77 const char kErrorRoamingPartiallyActivated[] = "roaming_partially_activated"; | |
| 78 const char kErrorNoService[] = "no_service"; | |
| 79 const char kErrorDisabled[] = "disabled"; | |
| 80 const char kErrorNoDevice[] = "no_device"; | |
| 81 const char kFailedPaymentError[] = "failed_payment"; | |
| 82 const char kFailedConnectivity[] = "connectivity"; | |
| 83 const char kErrorAlreadyRunning[] = "already_running"; | |
| 84 | |
| 85 // Cellular configuration file path. | 36 // Cellular configuration file path. |
| 86 const char kCellularConfigPath[] = | 37 const char kCellularConfigPath[] = |
| 87 "/usr/share/chromeos-assets/mobile/mobile_config.json"; | 38 "/usr/share/chromeos-assets/mobile/mobile_config.json"; |
| 88 | 39 |
| 89 // Cellular config file field names. | 40 // Cellular config file field names. |
| 90 const char kVersionField[] = "version"; | 41 const char kVersionField[] = "version"; |
| 91 const char kErrorsField[] = "errors"; | 42 const char kErrorsField[] = "errors"; |
| 92 | 43 |
| 93 // Number of times we will retry to restart the activation process in case | 44 // Number of times we will retry to restart the activation process in case |
| 94 // there is no connectivity in the restricted pool. | 45 // there is no connectivity in the restricted pool. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 107 const int kConnectionTimeoutSeconds = 45; | 58 const int kConnectionTimeoutSeconds = 45; |
| 108 // Reconnect delay. | 59 // Reconnect delay. |
| 109 const int kReconnectDelayMS = 3000; | 60 const int kReconnectDelayMS = 3000; |
| 110 // Reconnect timer delay. | 61 // Reconnect timer delay. |
| 111 const int kReconnectTimerDelayMS = 5000; | 62 const int kReconnectTimerDelayMS = 5000; |
| 112 // Reconnect delay after previous failure. | 63 // Reconnect delay after previous failure. |
| 113 const int kFailedReconnectDelayMS = 10000; | 64 const int kFailedReconnectDelayMS = 10000; |
| 114 // Retry delay after failed OTASP attempt. | 65 // Retry delay after failed OTASP attempt. |
| 115 const int kOTASPRetryDelay = 20000; | 66 const int kOTASPRetryDelay = 20000; |
| 116 | 67 |
| 117 chromeos::CellularNetwork* GetCellularNetwork() { | 68 // Error codes matching codes defined in the cellular config file. |
| 118 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 69 const char kErrorDefault[] = "default"; |
| 119 GetNetworkLibrary(); | 70 const char kErrorBadConnectionPartial[] = "bad_connection_partial"; |
| 120 if (lib->cellular_networks().begin() != lib->cellular_networks().end()) { | 71 const char kErrorBadConnectionActivated[] = "bad_connection_activated"; |
| 121 return *(lib->cellular_networks().begin()); | 72 const char kErrorRoamingOnConnection[] = "roaming_connection"; |
| 122 } | 73 const char kErrorNoEVDO[] = "no_evdo"; |
| 123 return NULL; | 74 const char kErrorRoamingActivation[] = "roaming_activation"; |
| 124 } | 75 const char kErrorRoamingPartiallyActivated[] = "roaming_partially_activated"; |
| 76 const char kErrorNoService[] = "no_service"; |
| 77 const char kErrorDisabled[] = "disabled"; |
| 78 const char kErrorNoDevice[] = "no_device"; |
| 79 const char kFailedPaymentError[] = "failed_payment"; |
| 80 const char kFailedConnectivity[] = "connectivity"; |
| 125 | 81 |
| 126 } // namespace | 82 } // namespace |
| 127 | 83 |
| 128 // Observes IPC messages from the rederer and notifies JS if frame loading error | 84 namespace chromeos { |
| 129 // appears. | |
| 130 class PortalFrameLoadObserver : public content::RenderViewHostObserver { | |
| 131 public: | |
| 132 PortalFrameLoadObserver(const base::WeakPtr<MobileSetupUI>& parent, | |
| 133 RenderViewHost* host) | |
| 134 : content::RenderViewHostObserver(host), parent_(parent) { | |
| 135 Send(new ChromeViewMsg_StartFrameSniffer(routing_id(), | |
| 136 UTF8ToUTF16("paymentForm"))); | |
| 137 } | |
| 138 | |
| 139 // IPC::Channel::Listener implementation. | |
| 140 virtual bool OnMessageReceived(const IPC::Message& message) { | |
| 141 bool handled = true; | |
| 142 IPC_BEGIN_MESSAGE_MAP(PortalFrameLoadObserver, message) | |
| 143 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FrameLoadingError, OnFrameLoadError) | |
| 144 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FrameLoadingCompleted, | |
| 145 OnFrameLoadCompleted) | |
| 146 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 147 IPC_END_MESSAGE_MAP() | |
| 148 return handled; | |
| 149 } | |
| 150 | |
| 151 private: | |
| 152 void OnFrameLoadError(int error) { | |
| 153 if (!parent_.get()) | |
| 154 return; | |
| 155 | |
| 156 base::FundamentalValue result_value(error); | |
| 157 parent_->web_ui()->CallJavascriptFunction(kJsPortalFrameLoadFailedCallback, | |
| 158 result_value); | |
| 159 } | |
| 160 | |
| 161 void OnFrameLoadCompleted() { | |
| 162 if (!parent_.get()) | |
| 163 return; | |
| 164 | |
| 165 parent_->web_ui()->CallJavascriptFunction( | |
| 166 kJsPortalFrameLoadCompletedCallback); | |
| 167 } | |
| 168 | |
| 169 base::WeakPtr<MobileSetupUI> parent_; | |
| 170 DISALLOW_COPY_AND_ASSIGN(PortalFrameLoadObserver); | |
| 171 }; | |
| 172 | |
| 173 class CellularConfigDocument | |
| 174 : public base::RefCountedThreadSafe<CellularConfigDocument> { | |
| 175 public: | |
| 176 CellularConfigDocument() {} | |
| 177 | |
| 178 // Return error message for a given code. | |
| 179 std::string GetErrorMessage(const std::string& code); | |
| 180 void LoadCellularConfigFile(); | |
| 181 const std::string& version() { return version_; } | |
| 182 | |
| 183 private: | |
| 184 typedef std::map<std::string, std::string> ErrorMap; | |
| 185 | |
| 186 void SetErrorMap(const ErrorMap& map); | |
| 187 bool LoadFromFile(const FilePath& config_path); | |
| 188 | |
| 189 std::string version_; | |
| 190 ErrorMap error_map_; | |
| 191 base::Lock config_lock_; | |
| 192 | |
| 193 DISALLOW_COPY_AND_ASSIGN(CellularConfigDocument); | |
| 194 }; | |
| 195 | |
| 196 class MobileSetupUIHTMLSource : public ChromeURLDataManager::DataSource { | |
| 197 public: | |
| 198 explicit MobileSetupUIHTMLSource(const std::string& service_path); | |
| 199 | |
| 200 // Called when the network layer has requested a resource underneath | |
| 201 // the path we registered. | |
| 202 virtual void StartDataRequest(const std::string& path, | |
| 203 bool is_incognito, | |
| 204 int request_id); | |
| 205 virtual std::string GetMimeType(const std::string&) const { | |
| 206 return "text/html"; | |
| 207 } | |
| 208 | |
| 209 private: | |
| 210 virtual ~MobileSetupUIHTMLSource() {} | |
| 211 | |
| 212 std::string service_path_; | |
| 213 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); | |
| 214 }; | |
| 215 | |
| 216 // The handler for Javascript messages related to the "register" view. | |
| 217 class MobileSetupHandler | |
| 218 : public WebUIMessageHandler, | |
| 219 public chromeos::NetworkLibrary::NetworkManagerObserver, | |
| 220 public chromeos::NetworkLibrary::NetworkObserver, | |
| 221 public base::SupportsWeakPtr<MobileSetupHandler> { | |
| 222 public: | |
| 223 explicit MobileSetupHandler(const std::string& service_path); | |
| 224 virtual ~MobileSetupHandler(); | |
| 225 | |
| 226 // Init work after Attach. | |
| 227 void StartActivationOnUIThread(); | |
| 228 | |
| 229 // WebUIMessageHandler implementation. | |
| 230 virtual void RegisterMessages() OVERRIDE; | |
| 231 | |
| 232 // NetworkLibrary::NetworkManagerObserver implementation. | |
| 233 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* obj) OVERRIDE; | |
| 234 // NetworkLibrary::NetworkObserver implementation. | |
| 235 virtual void OnNetworkChanged(chromeos::NetworkLibrary* obj, | |
| 236 const chromeos::Network* network) OVERRIDE; | |
| 237 | |
| 238 private: | |
| 239 typedef enum PlanActivationState { | |
| 240 PLAN_ACTIVATION_PAGE_LOADING = -1, | |
| 241 PLAN_ACTIVATION_START = 0, | |
| 242 PLAN_ACTIVATION_TRYING_OTASP = 1, | |
| 243 PLAN_ACTIVATION_RECONNECTING_OTASP_TRY = 2, | |
| 244 PLAN_ACTIVATION_INITIATING_ACTIVATION = 3, | |
| 245 PLAN_ACTIVATION_RECONNECTING = 4, | |
| 246 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING = 5, | |
| 247 PLAN_ACTIVATION_SHOWING_PAYMENT = 6, | |
| 248 PLAN_ACTIVATION_RECONNECTING_PAYMENT = 7, | |
| 249 PLAN_ACTIVATION_DELAY_OTASP = 8, | |
| 250 PLAN_ACTIVATION_START_OTASP = 9, | |
| 251 PLAN_ACTIVATION_OTASP = 10, | |
| 252 PLAN_ACTIVATION_RECONNECTING_OTASP = 11, | |
| 253 PLAN_ACTIVATION_DONE = 12, | |
| 254 PLAN_ACTIVATION_ERROR = 0xFF, | |
| 255 } PlanActivationState; | |
| 256 | |
| 257 // Handlers for JS WebUI messages. | |
| 258 void HandleSetTransactionStatus(const ListValue* args); | |
| 259 void HandleStartActivation(const ListValue* args); | |
| 260 void HandlePaymentPortalLoad(const ListValue* args); | |
| 261 void SetTransactionStatus(const std::string& status); | |
| 262 // Starts activation. | |
| 263 void StartActivation(); | |
| 264 // Retried OTASP. | |
| 265 void RetryOTASP(); | |
| 266 // Continues activation process. This method is called after we disconnect | |
| 267 // due to detected connectivity issue to kick off reconnection. | |
| 268 void ContinueConnecting(int delay); | |
| 269 | |
| 270 // Sends message to host registration page with system/user info data. | |
| 271 void SendDeviceInfo(); | |
| 272 | |
| 273 // Callback for when |reconnect_timer_| fires. | |
| 274 void ReconnectTimerFired(); | |
| 275 // Starts OTASP process. | |
| 276 void StartOTASP(); | |
| 277 // Checks if we need to reconnect due to failed connection attempt. | |
| 278 bool NeedsReconnecting(chromeos::CellularNetwork* network, | |
| 279 PlanActivationState* new_state, | |
| 280 std::string* error_description); | |
| 281 // Disconnect from network. | |
| 282 void DisconnectFromNetwork(chromeos::CellularNetwork* network); | |
| 283 // Connects to cellular network, resets connection timer. | |
| 284 bool ConnectToNetwork(chromeos::CellularNetwork* network, int delay); | |
| 285 // Forces disconnect / reconnect when we detect portal connectivity issues. | |
| 286 void ForceReconnect(chromeos::CellularNetwork* network, int delay); | |
| 287 // Reports connection timeout. | |
| 288 bool ConnectionTimeout(); | |
| 289 // Verify the state of cellular network and modify internal state. | |
| 290 void EvaluateCellularNetwork(chromeos::CellularNetwork* network); | |
| 291 // Finds cellular network given device |meid|, reattach network change | |
| 292 // observer if |reattach_observer| flag is set. | |
| 293 chromeos::CellularNetwork* FindCellularNetworkByMeid(const std::string& meid, | |
| 294 bool reattach_observer); | |
| 295 // Check the current cellular network for error conditions. | |
| 296 bool GotActivationError(chromeos::CellularNetwork* network, | |
| 297 std::string* error); | |
| 298 // Sends status updates to WebUI page. | |
| 299 void UpdatePage(chromeos::CellularNetwork* network, | |
| 300 const std::string& error_description); | |
| 301 // Changes internal state. | |
| 302 void ChangeState(chromeos::CellularNetwork* network, | |
| 303 PlanActivationState new_state, | |
| 304 const std::string& error_description); | |
| 305 // Prepares network devices for cellular activation process. | |
| 306 void SetupActivationProcess(chromeos::CellularNetwork* network); | |
| 307 // Disables ethernet and wifi newtorks since they interefere with | |
| 308 // detection of restricted pool on cellular side. | |
| 309 void DisableOtherNetworks(); | |
| 310 // Resets network devices after cellular activation process. | |
| 311 // |network| should be NULL if the activation process failed. | |
| 312 void CompleteActivation(chromeos::CellularNetwork* network); | |
| 313 // Control routines for handling other types of connections during | |
| 314 // cellular activation. | |
| 315 void ReEnableOtherConnections(); | |
| 316 // Return error message for a given code. | |
| 317 std::string GetErrorMessage(const std::string& code); | |
| 318 | |
| 319 // Converts the currently active CellularNetwork device into a JS object. | |
| 320 static void GetDeviceInfo(chromeos::CellularNetwork* network, | |
| 321 DictionaryValue* value); | |
| 322 static bool ShouldReportDeviceState(std::string* state, std::string* error); | |
| 323 | |
| 324 // Performs activation state cellular device evaluation. | |
| 325 // Returns false if device activation failed. In this case |error| | |
| 326 // will contain error message to be reported to Web UI. | |
| 327 static bool EvaluateCellularDeviceState(bool* report_status, | |
| 328 std::string* state, | |
| 329 std::string* error); | |
| 330 | |
| 331 // Returns next reconnection state based on the current activation phase. | |
| 332 static PlanActivationState GetNextReconnectState(PlanActivationState state); | |
| 333 static const char* GetStateDescription(PlanActivationState state); | |
| 334 | |
| 335 scoped_refptr<CellularConfigDocument> cellular_config_; | |
| 336 // Internal handler state. | |
| 337 PlanActivationState state_; | |
| 338 std::string meid_; | |
| 339 std::string service_path_; | |
| 340 // Flags that control if wifi and ethernet connection needs to be restored | |
| 341 // after the activation of cellular network. | |
| 342 bool reenable_wifi_; | |
| 343 bool reenable_ethernet_; | |
| 344 bool reenable_cert_check_; | |
| 345 bool evaluating_; | |
| 346 // True if we think that another tab is already running activation. | |
| 347 bool already_running_; | |
| 348 // Connection retry counter. | |
| 349 int connection_retry_count_; | |
| 350 // Post payment reconnect wait counters. | |
| 351 int reconnect_wait_count_; | |
| 352 // Payment portal reload/reconnect attempt count. | |
| 353 int payment_reconnect_count_; | |
| 354 // Activation retry attempt count; | |
| 355 int activation_attempt_; | |
| 356 // Connection start time. | |
| 357 base::Time connection_start_time_; | |
| 358 // Timer that monitors reconnection timeouts. | |
| 359 base::RepeatingTimer<MobileSetupHandler> reconnect_timer_; | |
| 360 | |
| 361 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); | |
| 362 }; | |
| 363 | 85 |
| 364 //////////////////////////////////////////////////////////////////////////////// | 86 //////////////////////////////////////////////////////////////////////////////// |
| 365 // | 87 // |
| 366 // CellularConfigDocument | 88 // CellularConfigDocument |
| 367 // | 89 // |
| 368 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
| 91 CellularConfigDocument::CellularConfigDocument() { |
| 92 } |
| 93 |
| 94 CellularConfigDocument::~CellularConfigDocument() { |
| 95 } |
| 369 | 96 |
| 370 std::string CellularConfigDocument::GetErrorMessage(const std::string& code) { | 97 std::string CellularConfigDocument::GetErrorMessage(const std::string& code) { |
| 371 base::AutoLock create(config_lock_); | 98 base::AutoLock create(config_lock_); |
| 372 ErrorMap::iterator iter = error_map_.find(code); | 99 ErrorMap::iterator iter = error_map_.find(code); |
| 373 if (iter == error_map_.end()) | 100 if (iter == error_map_.end()) |
| 374 return code; | 101 return code; |
| 375 return iter->second; | 102 return iter->second; |
| 376 } | 103 } |
| 377 | 104 |
| 378 void CellularConfigDocument::LoadCellularConfigFile() { | 105 void CellularConfigDocument::LoadCellularConfigFile() { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 155 |
| 429 void CellularConfigDocument::SetErrorMap( | 156 void CellularConfigDocument::SetErrorMap( |
| 430 const ErrorMap& map) { | 157 const ErrorMap& map) { |
| 431 base::AutoLock create(config_lock_); | 158 base::AutoLock create(config_lock_); |
| 432 error_map_.clear(); | 159 error_map_.clear(); |
| 433 error_map_.insert(map.begin(), map.end()); | 160 error_map_.insert(map.begin(), map.end()); |
| 434 } | 161 } |
| 435 | 162 |
| 436 //////////////////////////////////////////////////////////////////////////////// | 163 //////////////////////////////////////////////////////////////////////////////// |
| 437 // | 164 // |
| 438 // MobileSetupUIHTMLSource | 165 // MobileActivator |
| 439 // | 166 // |
| 440 //////////////////////////////////////////////////////////////////////////////// | 167 //////////////////////////////////////////////////////////////////////////////// |
| 441 | 168 MobileActivator::MobileActivator() |
| 442 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource( | |
| 443 const std::string& service_path) | |
| 444 : DataSource(chrome::kChromeUIMobileSetupHost, MessageLoop::current()), | |
| 445 service_path_(service_path) { | |
| 446 } | |
| 447 | |
| 448 void MobileSetupUIHTMLSource::StartDataRequest(const std::string& path, | |
| 449 bool is_incognito, | |
| 450 int request_id) { | |
| 451 chromeos::CellularNetwork* network = | |
| 452 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | |
| 453 FindCellularNetworkByPath(service_path_); | |
| 454 | |
| 455 // If we are activating, shutting down, or logging in, |network| may not | |
| 456 // be available. | |
| 457 if (!network || !network->SupportsActivation()) { | |
| 458 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes); | |
| 459 SendResponse(request_id, html_bytes); | |
| 460 return; | |
| 461 } | |
| 462 DictionaryValue strings; | |
| 463 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE)); | |
| 464 strings.SetString("connecting_header", | |
| 465 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER, | |
| 466 network ? UTF8ToUTF16(network->name()) : string16())); | |
| 467 strings.SetString("error_header", | |
| 468 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER)); | |
| 469 strings.SetString("activating_header", | |
| 470 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER)); | |
| 471 strings.SetString("completed_header", | |
| 472 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER)); | |
| 473 strings.SetString("please_wait", | |
| 474 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT)); | |
| 475 strings.SetString("completed_text", | |
| 476 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT)); | |
| 477 strings.SetString("close_button", | |
| 478 l10n_util::GetStringUTF16(IDS_CLOSE)); | |
| 479 strings.SetString("cancel_button", | |
| 480 l10n_util::GetStringUTF16(IDS_CANCEL)); | |
| 481 strings.SetString("ok_button", | |
| 482 l10n_util::GetStringUTF16(IDS_OK)); | |
| 483 SetFontAndTextDirection(&strings); | |
| 484 | |
| 485 static const base::StringPiece html( | |
| 486 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 487 IDR_MOBILE_SETUP_PAGE_HTML, ui::SCALE_FACTOR_NONE)); | |
| 488 | |
| 489 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, | |
| 490 &strings); | |
| 491 | |
| 492 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); | |
| 493 } | |
| 494 | |
| 495 //////////////////////////////////////////////////////////////////////////////// | |
| 496 // | |
| 497 // MobileSetupHandler | |
| 498 // | |
| 499 //////////////////////////////////////////////////////////////////////////////// | |
| 500 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) | |
| 501 : cellular_config_(new CellularConfigDocument()), | 169 : cellular_config_(new CellularConfigDocument()), |
| 502 state_(PLAN_ACTIVATION_PAGE_LOADING), | 170 state_(PLAN_ACTIVATION_PAGE_LOADING), |
| 503 service_path_(service_path), | |
| 504 reenable_wifi_(false), | 171 reenable_wifi_(false), |
| 505 reenable_ethernet_(false), | 172 reenable_ethernet_(false), |
| 506 reenable_cert_check_(false), | 173 reenable_cert_check_(false), |
| 507 evaluating_(false), | 174 evaluating_(false), |
| 508 already_running_(false), | 175 terminated_(true), |
| 509 connection_retry_count_(0), | 176 connection_retry_count_(0), |
| 510 reconnect_wait_count_(0), | 177 reconnect_wait_count_(0), |
| 511 payment_reconnect_count_(0), | 178 payment_reconnect_count_(0), |
| 512 activation_attempt_(0) { | 179 activation_attempt_(0) { |
| 513 } | 180 } |
| 514 | 181 |
| 515 MobileSetupHandler::~MobileSetupHandler() { | 182 MobileActivator::~MobileActivator() { |
| 183 TerminateActivation(); |
| 184 } |
| 185 |
| 186 MobileActivator* MobileActivator::GetInstance() { |
| 187 return Singleton<MobileActivator>::get(); |
| 188 } |
| 189 |
| 190 void MobileActivator::TerminateActivation() { |
| 516 reconnect_timer_.Stop(); | 191 reconnect_timer_.Stop(); |
| 517 chromeos::NetworkLibrary* lib = | 192 NetworkLibrary* lib = |
| 518 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 193 CrosLibrary::Get()->GetNetworkLibrary(); |
| 519 lib->RemoveNetworkManagerObserver(this); | 194 lib->RemoveNetworkManagerObserver(this); |
| 520 lib->RemoveObserverForAllNetworks(this); | 195 lib->RemoveObserverForAllNetworks(this); |
| 521 if (lib->IsLocked()) | 196 if (lib->IsLocked()) |
| 522 lib->Unlock(); | 197 lib->Unlock(); |
| 523 ReEnableOtherConnections(); | 198 ReEnableOtherConnections(); |
| 199 meid_.clear(); |
| 200 service_path_.clear(); |
| 201 state_ = PLAN_ACTIVATION_PAGE_LOADING; |
| 202 reconnect_wait_count_ = 0; |
| 203 evaluating_ = false; |
| 204 reenable_wifi_ = false; |
| 205 reenable_ethernet_ = false; |
| 206 reenable_cert_check_ = false; |
| 207 terminated_ = true; |
| 208 cellular_config_ = NULL; |
| 524 } | 209 } |
| 525 | 210 |
| 526 void MobileSetupHandler::RegisterMessages() { | 211 void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) { |
| 527 web_ui()->RegisterMessageCallback(kJsApiStartActivation, | |
| 528 base::Bind(&MobileSetupHandler::HandleStartActivation, | |
| 529 base::Unretained(this))); | |
| 530 web_ui()->RegisterMessageCallback(kJsApiSetTransactionStatus, | |
| 531 base::Bind(&MobileSetupHandler::HandleSetTransactionStatus, | |
| 532 base::Unretained(this))); | |
| 533 web_ui()->RegisterMessageCallback(kJsApiPaymentPortalLoad, | |
| 534 base::Bind(&MobileSetupHandler::HandlePaymentPortalLoad, | |
| 535 base::Unretained(this))); | |
| 536 } | |
| 537 | |
| 538 void MobileSetupHandler::OnNetworkManagerChanged( | |
| 539 chromeos::NetworkLibrary* cros) { | |
| 540 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 212 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
| 541 return; | 213 return; |
| 542 // Note that even though we get here when the service has | |
| 543 // reappeared after disappearing earlier in the activation | |
| 544 // process, there's no need to re-establish the NetworkObserver, | |
| 545 // because the service path remains the same. | |
| 546 EvaluateCellularNetwork(FindCellularNetworkByMeid(meid_, true)); | 214 EvaluateCellularNetwork(FindCellularNetworkByMeid(meid_, true)); |
| 547 } | 215 } |
| 548 | 216 |
| 549 void MobileSetupHandler::OnNetworkChanged(chromeos::NetworkLibrary* cros, | 217 void MobileActivator::OnNetworkChanged(NetworkLibrary* cros, |
| 550 const chromeos::Network* network) { | 218 const Network* network) { |
| 551 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 219 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
| 552 return; | 220 return; |
| 553 DCHECK(network && network->type() == chromeos::TYPE_CELLULAR); | 221 |
| 222 if (!network || network->type() != TYPE_CELLULAR) { |
| 223 NOTREACHED(); |
| 224 return; |
| 225 } |
| 226 |
| 554 EvaluateCellularNetwork( | 227 EvaluateCellularNetwork( |
| 555 static_cast<chromeos::CellularNetwork*>( | 228 static_cast<CellularNetwork*>(const_cast<Network*>(network))); |
| 556 const_cast<chromeos::Network*>(network))); | |
| 557 } | 229 } |
| 558 | 230 |
| 559 void MobileSetupHandler::HandleStartActivation(const ListValue* args) { | 231 void MobileActivator::AddObserver(MobileActivator::Observer* observer) { |
| 232 observers_.AddObserver(observer); |
| 233 } |
| 234 |
| 235 void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) { |
| 236 observers_.RemoveObserver(observer); |
| 237 } |
| 238 |
| 239 void MobileActivator::InitiateActivation(const std::string& service_path) { |
| 240 NetworkLibrary* lib = CrosLibrary::Get()->GetNetworkLibrary(); |
| 241 CellularNetwork* network = lib->FindCellularNetworkByPath(service_path); |
| 242 if (!network) { |
| 243 LOG(ERROR) << "Cellular service can't be found: " << service_path; |
| 244 return; |
| 245 } |
| 246 |
| 247 const chromeos::NetworkDevice* device = |
| 248 lib->FindNetworkDeviceByPath(network->device_path()); |
| 249 if (!device) { |
| 250 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); |
| 251 return; |
| 252 } |
| 253 |
| 254 terminated_ = false; |
| 255 meid_ = device->meid(); |
| 256 service_path_ = service_path; |
| 560 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 257 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| 561 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, | 258 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, |
| 562 cellular_config_.get()), | 259 cellular_config_.get()), |
| 563 base::Bind(&MobileSetupHandler::StartActivationOnUIThread, AsWeakPtr())); | 260 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); |
| 564 } | 261 } |
| 565 | 262 |
| 566 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { | 263 void MobileActivator::ContinueActivation() { |
| 567 const size_t kSetTransactionStatusParamCount = 1; | 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 568 if (args->GetSize() != kSetTransactionStatusParamCount) | 265 CellularNetwork* network = FindCellularNetworkByMeid(meid_, false); |
| 266 if (!network || !network->SupportsActivation()) |
| 569 return; | 267 return; |
| 570 // Get change callback function name. | 268 |
| 571 std::string status; | 269 DCHECK(!CrosLibrary::Get()->GetNetworkLibrary()->IsLocked()); |
| 572 if (!args->GetString(0, &status)) | 270 SetupActivationProcess(network); |
| 573 return; | 271 |
| 574 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 272 StartActivation(); |
| 575 base::Bind(&MobileSetupHandler::SetTransactionStatus, AsWeakPtr(), | |
| 576 status)); | |
| 577 } | 273 } |
| 578 | 274 |
| 579 void MobileSetupHandler::HandlePaymentPortalLoad(const ListValue* args) { | 275 void MobileActivator::OnSetTransactionStatus(bool success) { |
| 580 const size_t kPaymentPortalLoadParamCount = 1; | 276 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 581 if (args->GetSize() != kPaymentPortalLoadParamCount) | 277 base::Bind(&MobileActivator::SetTransactionStatus, |
| 582 return; | 278 AsWeakPtr(), success)); |
| 583 // Get change callback function name. | 279 } |
| 584 std::string result; | 280 |
| 585 if (!args->GetString(0, &result)) | 281 void MobileActivator::OnPortalLoaded(bool success) { |
| 586 return; | 282 CellularNetwork* network = FindCellularNetworkByMeid(meid_, true); |
| 587 chromeos::CellularNetwork* network = FindCellularNetworkByMeid(meid_, true); | |
| 588 if (!network) { | 283 if (!network) { |
| 589 ChangeState(NULL, PLAN_ACTIVATION_ERROR, | 284 ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
| 590 GetErrorMessage(kErrorNoService)); | 285 GetErrorMessage(kErrorNoService)); |
| 591 return; | 286 return; |
| 592 } | 287 } |
| 593 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || | 288 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || |
| 594 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 289 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
| 595 if (LowerCaseEqualsASCII(result, kJsApiResultOK)) { | 290 if (success) { |
| 596 payment_reconnect_count_ = 0; | 291 payment_reconnect_count_ = 0; |
| 597 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); | 292 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); |
| 598 } else { | 293 } else { |
| 599 payment_reconnect_count_++; | 294 payment_reconnect_count_++; |
| 600 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { | 295 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { |
| 601 ChangeState(NULL, PLAN_ACTIVATION_ERROR, | 296 ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
| 602 GetErrorMessage(kErrorNoService)); | 297 GetErrorMessage(kErrorNoService)); |
| 603 return; | 298 return; |
| 604 } | 299 } |
| 605 // Disconnect now, this should force reconnection and we will retry to | 300 // Disconnect now, this should force reconnection and we will retry to |
| 606 // load the frame containing payment portal again. | 301 // load the frame containing payment portal again. |
| 607 DisconnectFromNetwork(network); | 302 DisconnectFromNetwork(network); |
| 608 } | 303 } |
| 609 } else { | 304 } else { |
| 610 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: " | 305 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: " |
| 611 << GetStateDescription(state_); | 306 << GetStateDescription(state_); |
| 612 } | 307 } |
| 613 } | 308 } |
| 614 | 309 |
| 615 chromeos::CellularNetwork* MobileSetupHandler::FindCellularNetworkByMeid( | 310 CellularNetwork* MobileActivator::FindCellularNetworkByMeid( |
| 616 const std::string& meid, bool reattach_observer) { | 311 const std::string& meid, bool reattach_observer) { |
| 617 chromeos::NetworkLibrary* lib = | 312 NetworkLibrary* lib = CrosLibrary::Get()->GetNetworkLibrary(); |
| 618 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 313 for (CellularNetworkVector::const_iterator it = |
| 619 for (chromeos::CellularNetworkVector::const_iterator it = | |
| 620 lib->cellular_networks().begin(); | 314 lib->cellular_networks().begin(); |
| 621 it != lib->cellular_networks().end(); ++it) { | 315 it != lib->cellular_networks().end(); ++it) { |
| 622 const chromeos::NetworkDevice* device = | 316 const chromeos::NetworkDevice* device = |
| 623 lib->FindNetworkDeviceByPath((*it)->device_path()); | 317 lib->FindNetworkDeviceByPath((*it)->device_path()); |
| 624 if (device && meid == device->meid()) { | 318 if (device && meid == device->meid()) { |
| 625 chromeos::CellularNetwork* network = *it; | 319 CellularNetwork* network = *it; |
| 626 // If service path has changed, reattach the event observer for this | 320 // If service path has changed, reattach the event observer for this |
| 627 // network service. | 321 // network service. |
| 628 if (reattach_observer && service_path_ != network->service_path()) { | 322 if (reattach_observer && service_path_ != network->service_path()) { |
| 629 lib->RemoveObserverForAllNetworks(this); | 323 lib->RemoveObserverForAllNetworks(this); |
| 630 lib->AddNetworkObserver(network->service_path(), this); | 324 lib->AddNetworkObserver(network->service_path(), this); |
| 631 service_path_ = network->service_path(); | 325 service_path_ = network->service_path(); |
| 632 } | 326 } |
| 633 return network; | 327 return network; |
| 634 } | 328 } |
| 635 } | 329 } |
| 636 return NULL; | 330 return NULL; |
| 637 } | 331 } |
| 638 | 332 |
| 639 void MobileSetupHandler::StartActivation() { | 333 void MobileActivator::StartActivation() { |
| 640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 641 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); | 335 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); |
| 642 chromeos::NetworkLibrary* lib = | 336 NetworkLibrary* lib = |
| 643 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 337 CrosLibrary::Get()->GetNetworkLibrary(); |
| 644 chromeos::CellularNetwork* network = FindCellularNetworkByMeid(meid_, true); | 338 CellularNetwork* network = FindCellularNetworkByMeid(meid_, true); |
| 645 // Check if we can start activation process. | 339 // Check if we can start activation process. |
| 646 if (!network || already_running_) { | 340 if (!network) { |
| 647 std::string error; | 341 std::string error; |
| 648 if (already_running_) | 342 if (!lib->cellular_available()) |
| 649 error = kErrorAlreadyRunning; | |
| 650 else if (!lib->cellular_available()) | |
| 651 error = kErrorNoDevice; | 343 error = kErrorNoDevice; |
| 652 else if (!lib->cellular_enabled()) | 344 else if (!lib->cellular_enabled()) |
| 653 error = kErrorDisabled; | 345 error = kErrorDisabled; |
| 654 else | 346 else |
| 655 error = kErrorNoService; | 347 error = kErrorNoService; |
| 656 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); | 348 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); |
| 657 return; | 349 return; |
| 658 } | 350 } |
| 659 | 351 |
| 660 // Start monitoring network property changes. | 352 // Start monitoring network property changes. |
| 661 lib->AddNetworkManagerObserver(this); | 353 lib->AddNetworkManagerObserver(this); |
| 662 lib->RemoveObserverForAllNetworks(this); | 354 lib->RemoveObserverForAllNetworks(this); |
| 663 lib->AddNetworkObserver(network->service_path(), this); | 355 lib->AddNetworkObserver(network->service_path(), this); |
| 664 // Try to start with OTASP immediately if we have received payment recently. | 356 // Try to start with OTASP immediately if we have received payment recently. |
| 665 state_ = lib->HasRecentCellularPlanPayment() ? | 357 state_ = lib->HasRecentCellularPlanPayment() ? |
| 666 PLAN_ACTIVATION_START_OTASP : | 358 PLAN_ACTIVATION_START_OTASP : |
| 667 PLAN_ACTIVATION_START; | 359 PLAN_ACTIVATION_START; |
| 668 EvaluateCellularNetwork(network); | 360 EvaluateCellularNetwork(network); |
| 669 } | 361 } |
| 670 | 362 |
| 671 void MobileSetupHandler::RetryOTASP() { | 363 void MobileActivator::RetryOTASP() { |
| 672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 673 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP); | 365 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP); |
| 674 StartOTASP(); | 366 StartOTASP(); |
| 675 } | 367 } |
| 676 | 368 |
| 677 void MobileSetupHandler::ContinueConnecting(int delay) { | 369 void MobileActivator::ContinueConnecting(int delay) { |
| 678 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 679 chromeos::CellularNetwork* network = FindCellularNetworkByMeid(meid_, true); | 371 CellularNetwork* network = FindCellularNetworkByMeid(meid_, true); |
| 680 if (network && network->connecting_or_connected()) { | 372 if (network && network->connecting_or_connected()) { |
| 681 EvaluateCellularNetwork(network); | 373 EvaluateCellularNetwork(network); |
| 682 } else { | 374 } else { |
| 683 ConnectToNetwork(network, delay); | 375 ConnectToNetwork(network, delay); |
| 684 } | 376 } |
| 685 } | 377 } |
| 686 | 378 |
| 687 void MobileSetupHandler::SetTransactionStatus(const std::string& status) { | 379 void MobileActivator::SetTransactionStatus(bool success) { |
| 688 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 689 // The payment is received, try to reconnect and check the status all over | 381 // The payment is received, try to reconnect and check the status all over |
| 690 // again. | 382 // again. |
| 691 if (LowerCaseEqualsASCII(status, kJsApiResultOK) && | 383 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
| 692 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 384 NetworkLibrary* lib = |
| 693 chromeos::NetworkLibrary* lib = | 385 CrosLibrary::Get()->GetNetworkLibrary(); |
| 694 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | |
| 695 lib->SignalCellularPlanPayment(); | 386 lib->SignalCellularPlanPayment(); |
| 696 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); | 387 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); |
| 697 StartOTASP(); | 388 StartOTASP(); |
| 698 } else { | 389 } else { |
| 699 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); | 390 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); |
| 700 } | 391 } |
| 701 } | 392 } |
| 702 | 393 |
| 703 void MobileSetupHandler::StartOTASP() { | 394 void MobileActivator::StartOTASP() { |
| 704 state_ = PLAN_ACTIVATION_START_OTASP; | 395 state_ = PLAN_ACTIVATION_START_OTASP; |
| 705 chromeos::CellularNetwork* network = FindCellularNetworkByMeid(meid_, true); | 396 CellularNetwork* network = FindCellularNetworkByMeid(meid_, true); |
| 706 if (network && | 397 if (network && |
| 707 network->connected() && | 398 network->connected() && |
| 708 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED) { | 399 network->activation_state() == ACTIVATION_STATE_ACTIVATED) { |
| 709 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 400 CrosLibrary::Get()->GetNetworkLibrary()-> |
| 710 DisconnectFromNetwork(network); | 401 DisconnectFromNetwork(network); |
| 711 } else { | 402 } else { |
| 712 EvaluateCellularNetwork(network); | 403 EvaluateCellularNetwork(network); |
| 713 } | 404 } |
| 714 } | 405 } |
| 715 | 406 |
| 716 void MobileSetupHandler::ReconnectTimerFired() { | 407 void MobileActivator::ReconnectTimerFired() { |
| 717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 718 // Permit network connection changes only in reconnecting states. | 409 // Permit network connection changes only in reconnecting states. |
| 719 if (state_ != PLAN_ACTIVATION_RECONNECTING_OTASP_TRY && | 410 if (state_ != PLAN_ACTIVATION_RECONNECTING_OTASP_TRY && |
| 720 state_ != PLAN_ACTIVATION_RECONNECTING && | 411 state_ != PLAN_ACTIVATION_RECONNECTING && |
| 721 state_ != PLAN_ACTIVATION_RECONNECTING_PAYMENT && | 412 state_ != PLAN_ACTIVATION_RECONNECTING_PAYMENT && |
| 722 state_ != PLAN_ACTIVATION_RECONNECTING_OTASP) | 413 state_ != PLAN_ACTIVATION_RECONNECTING_OTASP) |
| 723 return; | 414 return; |
| 724 chromeos::CellularNetwork* network = FindCellularNetworkByMeid(meid_, true); | 415 CellularNetwork* network = FindCellularNetworkByMeid(meid_, true); |
| 725 if (!network) { | 416 if (!network) { |
| 726 // No service, try again since this is probably just transient condition. | 417 // No service, try again since this is probably just transient condition. |
| 727 LOG(WARNING) << "Service not present at reconnect attempt."; | 418 LOG(WARNING) << "Service not present at reconnect attempt."; |
| 728 } | 419 } |
| 729 EvaluateCellularNetwork(network); | 420 EvaluateCellularNetwork(network); |
| 730 } | 421 } |
| 731 | 422 |
| 732 void MobileSetupHandler::DisconnectFromNetwork( | 423 void MobileActivator::DisconnectFromNetwork(CellularNetwork* network) { |
| 733 chromeos::CellularNetwork* network) { | |
| 734 DCHECK(network); | 424 DCHECK(network); |
| 735 LOG(INFO) << "Disconnecting from: " << network->service_path(); | 425 LOG(INFO) << "Disconnecting from: " << network->service_path(); |
| 736 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 426 CrosLibrary::Get()->GetNetworkLibrary()-> |
| 737 DisconnectFromNetwork(network); | 427 DisconnectFromNetwork(network); |
| 738 // Disconnect will force networks to be reevaluated, so | 428 // Disconnect will force networks to be reevaluated, so |
| 739 // we don't want to continue processing on this path anymore. | 429 // we don't want to continue processing on this path anymore. |
| 740 evaluating_ = false; | 430 evaluating_ = false; |
| 741 } | 431 } |
| 742 | 432 |
| 743 bool MobileSetupHandler::NeedsReconnecting( | 433 bool MobileActivator::NeedsReconnecting(CellularNetwork* network, |
| 744 chromeos::CellularNetwork* network, | 434 PlanActivationState* new_state, |
| 745 PlanActivationState* new_state, | 435 std::string* error_description) { |
| 746 std::string* error_description) { | |
| 747 DCHECK(network); | 436 DCHECK(network); |
| 748 if (!network->failed() && !ConnectionTimeout()) | 437 if (!network->failed() && !ConnectionTimeout()) |
| 749 return false; | 438 return false; |
| 750 | 439 |
| 751 // Try to reconnect again if reconnect failed, or if for some | 440 // Try to reconnect again if reconnect failed, or if for some |
| 752 // reasons we are still not connected after 45 seconds. | 441 // reasons we are still not connected after 45 seconds. |
| 753 int max_retries = (state_ == PLAN_ACTIVATION_RECONNECTING_OTASP) ? | 442 int max_retries = (state_ == PLAN_ACTIVATION_RECONNECTING_OTASP) ? |
| 754 kMaxConnectionRetryOTASP : kMaxConnectionRetry; | 443 kMaxConnectionRetryOTASP : kMaxConnectionRetry; |
| 755 if (connection_retry_count_ < max_retries) { | 444 if (connection_retry_count_ < max_retries) { |
| 756 UMA_HISTOGRAM_COUNTS("Cellular.ConnectionRetry", 1); | 445 UMA_HISTOGRAM_COUNTS("Cellular.ConnectionRetry", 1); |
| 757 ConnectToNetwork(network, kFailedReconnectDelayMS); | 446 ConnectToNetwork(network, kFailedReconnectDelayMS); |
| 758 return true; | 447 return true; |
| 759 } | 448 } |
| 760 // We simply can't connect anymore after all these tries. | 449 // We simply can't connect anymore after all these tries. |
| 761 UMA_HISTOGRAM_COUNTS("Cellular.ConnectionFailed", 1); | 450 UMA_HISTOGRAM_COUNTS("Cellular.ConnectionFailed", 1); |
| 762 *new_state = PLAN_ACTIVATION_ERROR; | 451 *new_state = PLAN_ACTIVATION_ERROR; |
| 763 *error_description = GetErrorMessage(kFailedConnectivity); | 452 *error_description = GetErrorMessage(kFailedConnectivity); |
| 764 return false; | 453 return false; |
| 765 } | 454 } |
| 766 | 455 |
| 767 bool MobileSetupHandler::ConnectToNetwork( | 456 bool MobileActivator::ConnectToNetwork(CellularNetwork* network, int delay) { |
| 768 chromeos::CellularNetwork* network, | |
| 769 int delay) { | |
| 770 if (network && network->connecting_or_connected()) | 457 if (network && network->connecting_or_connected()) |
| 771 return true; | 458 return true; |
| 772 // Permit network connection changes only in reconnecting states. | 459 // Permit network connection changes only in reconnecting states. |
| 773 if (state_ != PLAN_ACTIVATION_RECONNECTING_OTASP_TRY && | 460 if (state_ != PLAN_ACTIVATION_RECONNECTING_OTASP_TRY && |
| 774 state_ != PLAN_ACTIVATION_RECONNECTING && | 461 state_ != PLAN_ACTIVATION_RECONNECTING && |
| 775 state_ != PLAN_ACTIVATION_RECONNECTING_PAYMENT && | 462 state_ != PLAN_ACTIVATION_RECONNECTING_PAYMENT && |
| 776 state_ != PLAN_ACTIVATION_RECONNECTING_OTASP) return false; | 463 state_ != PLAN_ACTIVATION_RECONNECTING_OTASP) return false; |
| 777 if (network) | 464 if (network) |
| 778 LOG(INFO) << "Connecting to: " << network->service_path(); | 465 LOG(INFO) << "Connecting to: " << network->service_path(); |
| 779 connection_retry_count_++; | 466 connection_retry_count_++; |
| 780 connection_start_time_ = base::Time::Now(); | 467 connection_start_time_ = base::Time::Now(); |
| 781 if (!network) { | 468 if (!network || state_ == PLAN_ACTIVATION_RECONNECTING_OTASP) { |
| 782 LOG(WARNING) << "Connect failed." | 469 LOG(WARNING) << "Delaying reconnect to " |
| 783 << (network ? network->service_path().c_str() : "no service"); | 470 << (network ? network->service_path().c_str() : "no service"); |
| 784 // If we coudn't connect during reconnection phase, try to reconnect | 471 // If we coudn't connect during reconnection phase, try to reconnect |
| 785 // with a delay (and try to reconnect if needed). | 472 // with a delay (and try to reconnect if needed). |
| 786 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 473 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
| 787 base::Bind(&MobileSetupHandler::ContinueConnecting, AsWeakPtr(), delay), | 474 base::Bind(&MobileActivator::ContinueConnecting, AsWeakPtr(), delay), |
| 788 base::TimeDelta::FromMilliseconds(delay)); | 475 base::TimeDelta::FromMilliseconds(delay)); |
| 789 return false; | 476 return false; |
| 790 } | 477 } |
| 791 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 478 CrosLibrary::Get()->GetNetworkLibrary()-> |
| 792 ConnectToCellularNetwork(network); | 479 ConnectToCellularNetwork(network); |
| 793 return true; | 480 return true; |
| 794 } | 481 } |
| 795 | 482 |
| 796 void MobileSetupHandler::ForceReconnect( | 483 void MobileActivator::ForceReconnect(CellularNetwork* network, int delay) { |
| 797 chromeos::CellularNetwork* network, | |
| 798 int delay) { | |
| 799 DCHECK(network); | 484 DCHECK(network); |
| 800 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); | 485 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); |
| 801 // Reset reconnect metrics. | 486 // Reset reconnect metrics. |
| 802 connection_retry_count_ = 0; | 487 connection_retry_count_ = 0; |
| 803 connection_start_time_ = base::Time(); | 488 connection_start_time_ = base::Time(); |
| 804 // First, disconnect... | 489 // First, disconnect... |
| 805 LOG(INFO) << "Disconnecting from " << network->service_path(); | 490 LOG(INFO) << "Disconnecting from " << network->service_path(); |
| 806 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 491 CrosLibrary::Get()->GetNetworkLibrary()-> |
| 807 DisconnectFromNetwork(network); | 492 DisconnectFromNetwork(network); |
| 808 // Check the network state 3s after we disconnect to make sure. | 493 // Check the network state 3s after we disconnect to make sure. |
| 809 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 494 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
| 810 base::Bind(&MobileSetupHandler::ContinueConnecting, AsWeakPtr(), delay), | 495 base::Bind(&MobileActivator::ContinueConnecting, AsWeakPtr(), delay), |
| 811 base::TimeDelta::FromMilliseconds(delay)); | 496 base::TimeDelta::FromMilliseconds(delay)); |
| 812 } | 497 } |
| 813 | 498 |
| 814 bool MobileSetupHandler::ConnectionTimeout() { | 499 bool MobileActivator::ConnectionTimeout() { |
| 815 return (base::Time::Now() - | 500 return (base::Time::Now() - |
| 816 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds; | 501 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds; |
| 817 } | 502 } |
| 818 | 503 |
| 819 void MobileSetupHandler::EvaluateCellularNetwork( | 504 void MobileActivator::EvaluateCellularNetwork(CellularNetwork* network) { |
| 820 chromeos::CellularNetwork* network) { | 505 if (terminated_) |
| 821 if (!web_ui()) | |
| 822 return; | 506 return; |
| 823 | 507 |
| 824 PlanActivationState new_state = state_; | 508 PlanActivationState new_state = state_; |
| 825 if (!network) { | 509 if (!network) { |
| 826 LOG(WARNING) << "Cellular service lost"; | 510 LOG(WARNING) << "Cellular service lost"; |
| 827 if (state_ == PLAN_ACTIVATION_RECONNECTING_OTASP_TRY || | 511 if (state_ == PLAN_ACTIVATION_RECONNECTING_OTASP_TRY || |
| 828 state_ == PLAN_ACTIVATION_RECONNECTING || | 512 state_ == PLAN_ACTIVATION_RECONNECTING || |
| 829 state_ == PLAN_ACTIVATION_RECONNECTING_PAYMENT || | 513 state_ == PLAN_ACTIVATION_RECONNECTING_PAYMENT || |
| 830 state_ == PLAN_ACTIVATION_RECONNECTING_OTASP) { | 514 state_ == PLAN_ACTIVATION_RECONNECTING_OTASP) { |
| 831 // This might be the legit case when service is lost after activation. | 515 // This might be the legit case when service is lost after activation. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 844 std::string error_description; | 528 std::string error_description; |
| 845 | 529 |
| 846 LOG(WARNING) << "Cellular:\n service=" << network->GetStateString().c_str() | 530 LOG(WARNING) << "Cellular:\n service=" << network->GetStateString().c_str() |
| 847 << "\n ui=" << GetStateDescription(state_) | 531 << "\n ui=" << GetStateDescription(state_) |
| 848 << "\n activation=" << network->GetActivationStateString().c_str() | 532 << "\n activation=" << network->GetActivationStateString().c_str() |
| 849 << "\n error=" << network->GetErrorString().c_str() | 533 << "\n error=" << network->GetErrorString().c_str() |
| 850 << "\n setvice_path=" << network->service_path().c_str(); | 534 << "\n setvice_path=" << network->service_path().c_str(); |
| 851 switch (state_) { | 535 switch (state_) { |
| 852 case PLAN_ACTIVATION_START: { | 536 case PLAN_ACTIVATION_START: { |
| 853 switch (network->activation_state()) { | 537 switch (network->activation_state()) { |
| 854 case chromeos::ACTIVATION_STATE_ACTIVATED: { | 538 case ACTIVATION_STATE_ACTIVATED: { |
| 855 if (network->disconnected()) { | 539 if (network->disconnected()) { |
| 856 new_state = PLAN_ACTIVATION_RECONNECTING; | 540 new_state = PLAN_ACTIVATION_RECONNECTING; |
| 857 } else if (network->connected()) { | 541 } else if (network->connected()) { |
| 858 if (network->restricted_pool()) { | 542 if (network->restricted_pool()) { |
| 859 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 543 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
| 860 } else { | 544 } else { |
| 861 new_state = PLAN_ACTIVATION_DONE; | 545 new_state = PLAN_ACTIVATION_DONE; |
| 862 } | 546 } |
| 863 } | 547 } |
| 864 break; | 548 break; |
| 865 } | 549 } |
| 866 default: { | 550 default: { |
| 867 if (network->disconnected() || | 551 if (network->disconnected() || |
| 868 network->state() == chromeos::STATE_ACTIVATION_FAILURE) { | 552 network->state() == STATE_ACTIVATION_FAILURE) { |
| 869 new_state = (network->activation_state() == | 553 new_state = (network->activation_state() == |
| 870 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) ? | 554 ACTIVATION_STATE_PARTIALLY_ACTIVATED) ? |
| 871 PLAN_ACTIVATION_TRYING_OTASP : | 555 PLAN_ACTIVATION_TRYING_OTASP : |
| 872 PLAN_ACTIVATION_INITIATING_ACTIVATION; | 556 PLAN_ACTIVATION_INITIATING_ACTIVATION; |
| 873 } else if (network->connected()) { | 557 } else if (network->connected()) { |
| 874 DisconnectFromNetwork(network); | 558 DisconnectFromNetwork(network); |
| 875 return; | 559 return; |
| 876 } | 560 } |
| 877 break; | 561 break; |
| 878 } | 562 } |
| 879 } | 563 } |
| 880 break; | 564 break; |
| 881 } | 565 } |
| 882 case PLAN_ACTIVATION_START_OTASP: { | 566 case PLAN_ACTIVATION_START_OTASP: { |
| 883 switch (network->activation_state()) { | 567 switch (network->activation_state()) { |
| 884 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: { | 568 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: { |
| 885 if (network->disconnected()) { | 569 if (network->disconnected()) { |
| 886 new_state = PLAN_ACTIVATION_OTASP; | 570 new_state = PLAN_ACTIVATION_OTASP; |
| 887 } else if (network->connected()) { | 571 } else if (network->connected()) { |
| 888 DisconnectFromNetwork(network); | 572 DisconnectFromNetwork(network); |
| 889 return; | 573 return; |
| 890 } | 574 } |
| 891 break; | 575 break; |
| 892 } | 576 } |
| 893 case chromeos::ACTIVATION_STATE_ACTIVATED: | 577 case ACTIVATION_STATE_ACTIVATED: |
| 894 new_state = PLAN_ACTIVATION_RECONNECTING_OTASP; | 578 new_state = PLAN_ACTIVATION_RECONNECTING_OTASP; |
| 895 break; | 579 break; |
| 896 default: { | 580 default: { |
| 897 LOG(WARNING) << "Unexpected activation state for device " | 581 LOG(WARNING) << "Unexpected activation state for device " |
| 898 << network->service_path().c_str(); | 582 << network->service_path().c_str(); |
| 899 break; | 583 break; |
| 900 } | 584 } |
| 901 } | 585 } |
| 902 break; | 586 break; |
| 903 } | 587 } |
| 904 case PLAN_ACTIVATION_DELAY_OTASP: | 588 case PLAN_ACTIVATION_DELAY_OTASP: |
| 905 // Just ignore any changes until the OTASP retry timer kicks in. | 589 // Just ignore any changes until the OTASP retry timer kicks in. |
| 906 evaluating_ = false; | 590 evaluating_ = false; |
| 907 return; | 591 return; |
| 908 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { | 592 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { |
| 909 switch (network->activation_state()) { | 593 switch (network->activation_state()) { |
| 910 case chromeos::ACTIVATION_STATE_ACTIVATED: | 594 case ACTIVATION_STATE_ACTIVATED: |
| 911 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 595 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
| 912 new_state = PLAN_ACTIVATION_START; | 596 new_state = PLAN_ACTIVATION_START; |
| 913 break; | 597 break; |
| 914 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: | 598 case ACTIVATION_STATE_NOT_ACTIVATED: |
| 915 case chromeos::ACTIVATION_STATE_ACTIVATING: | 599 case ACTIVATION_STATE_ACTIVATING: |
| 916 // Wait in this state until activation state changes. | 600 // Wait in this state until activation state changes. |
| 917 break; | 601 break; |
| 918 default: | 602 default: |
| 919 break; | 603 break; |
| 920 } | 604 } |
| 921 break; | 605 break; |
| 922 } | 606 } |
| 923 case PLAN_ACTIVATION_OTASP: | 607 case PLAN_ACTIVATION_OTASP: |
| 924 case PLAN_ACTIVATION_TRYING_OTASP: { | 608 case PLAN_ACTIVATION_TRYING_OTASP: { |
| 925 switch (network->activation_state()) { | 609 switch (network->activation_state()) { |
| 926 case chromeos::ACTIVATION_STATE_ACTIVATED: | 610 case ACTIVATION_STATE_ACTIVATED: |
| 927 if (network->disconnected()) { | 611 if (network->disconnected()) { |
| 928 new_state = GetNextReconnectState(state_); | 612 new_state = GetNextReconnectState(state_); |
| 929 } else if (network->connected()) { | 613 } else if (network->connected()) { |
| 930 if (network->restricted_pool()) { | 614 if (network->restricted_pool()) { |
| 931 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 615 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
| 932 } else { | 616 } else { |
| 933 new_state = PLAN_ACTIVATION_DONE; | 617 new_state = PLAN_ACTIVATION_DONE; |
| 934 } | 618 } |
| 935 } | 619 } |
| 936 break; | 620 break; |
| 937 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 621 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
| 938 if (network->connected()) { | 622 if (network->connected()) { |
| 939 if (network->restricted_pool()) | 623 if (network->restricted_pool()) |
| 940 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 624 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
| 941 } else { | 625 } else { |
| 942 new_state = GetNextReconnectState(state_); | 626 new_state = GetNextReconnectState(state_); |
| 943 } | 627 } |
| 944 break; | 628 break; |
| 945 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: | 629 case ACTIVATION_STATE_NOT_ACTIVATED: |
| 946 case chromeos::ACTIVATION_STATE_ACTIVATING: | 630 case ACTIVATION_STATE_ACTIVATING: |
| 947 // Wait in this state until activation state changes. | 631 // Wait in this state until activation state changes. |
| 948 break; | 632 break; |
| 949 default: | 633 default: |
| 950 break; | 634 break; |
| 951 } | 635 } |
| 952 break; | 636 break; |
| 953 } | 637 } |
| 954 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: | 638 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: |
| 955 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: | 639 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: |
| 956 case PLAN_ACTIVATION_RECONNECTING: { | 640 case PLAN_ACTIVATION_RECONNECTING: { |
| 957 if (network->connected()) { | 641 if (network->connected()) { |
| 958 // Make sure other networks are not interfering with our detection of | 642 // Make sure other networks are not interfering with our detection of |
| 959 // restricted pool. | 643 // restricted pool. |
| 960 DisableOtherNetworks(); | 644 DisableOtherNetworks(); |
| 961 // Wait until the service shows up and gets activated. | 645 // Wait until the service shows up and gets activated. |
| 962 switch (network->activation_state()) { | 646 switch (network->activation_state()) { |
| 963 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 647 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
| 964 case chromeos::ACTIVATION_STATE_ACTIVATED: | 648 case ACTIVATION_STATE_ACTIVATED: |
| 965 if (network->restricted_pool()) { | 649 if (network->restricted_pool()) { |
| 966 if (network->error() == chromeos::ERROR_DNS_LOOKUP_FAILED) { | 650 if (network->error() == ERROR_DNS_LOOKUP_FAILED) { |
| 967 LOG(WARNING) << "No connectivity for device " | 651 LOG(WARNING) << "No connectivity for device " |
| 968 << network->service_path().c_str(); | 652 << network->service_path().c_str(); |
| 969 // If we are connected but there is no connectivity at all, | 653 // If we are connected but there is no connectivity at all, |
| 970 // restart the whole process again. | 654 // restart the whole process again. |
| 971 if (activation_attempt_ < kMaxActivationAttempt) { | 655 if (activation_attempt_ < kMaxActivationAttempt) { |
| 972 activation_attempt_++; | 656 activation_attempt_++; |
| 973 LOG(WARNING) << "Reconnect attempt #" | 657 LOG(WARNING) << "Reconnect attempt #" |
| 974 << activation_attempt_; | 658 << activation_attempt_; |
| 975 ForceReconnect(network, kFailedReconnectDelayMS); | 659 ForceReconnect(network, kFailedReconnectDelayMS); |
| 976 evaluating_ = false; | 660 evaluating_ = false; |
| 977 return; | 661 return; |
| 978 } else { | 662 } else { |
| 979 new_state = PLAN_ACTIVATION_ERROR; | 663 new_state = PLAN_ACTIVATION_ERROR; |
| 980 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetryFailure", 1); | 664 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetryFailure", 1); |
| 981 error_description = GetErrorMessage(kFailedConnectivity); | 665 error_description = GetErrorMessage(kFailedConnectivity); |
| 982 } | 666 } |
| 983 } else { | 667 } else { |
| 984 // If we have already received payment, don't show the payment | 668 // If we have already received payment, don't show the payment |
| 985 // page again. We should try to reconnect after some | 669 // page again. We should try to reconnect after some |
| 986 // time instead. | 670 // time instead. |
| 987 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 671 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
| 988 } | 672 } |
| 989 } else if (network->activation_state() == | 673 } else if (network->activation_state() == |
| 990 chromeos::ACTIVATION_STATE_ACTIVATED) { | 674 ACTIVATION_STATE_ACTIVATED) { |
| 991 new_state = PLAN_ACTIVATION_DONE; | 675 new_state = PLAN_ACTIVATION_DONE; |
| 992 } | 676 } |
| 993 break; | 677 break; |
| 994 default: | 678 default: |
| 995 break; | 679 break; |
| 996 } | 680 } |
| 997 } else if (NeedsReconnecting(network, &new_state, &error_description)) { | 681 } else if (NeedsReconnecting(network, &new_state, &error_description)) { |
| 998 evaluating_ = false; | 682 evaluating_ = false; |
| 999 return; | 683 return; |
| 1000 } | 684 } |
| 1001 break; | 685 break; |
| 1002 } | 686 } |
| 1003 case PLAN_ACTIVATION_RECONNECTING_OTASP: { | 687 case PLAN_ACTIVATION_RECONNECTING_OTASP: { |
| 1004 if (network->connected()) { | 688 if (network->connected()) { |
| 1005 // Make sure other networks are not interfering with our detection of | 689 // Make sure other networks are not interfering with our detection of |
| 1006 // restricted pool. | 690 // restricted pool. |
| 1007 DisableOtherNetworks(); | 691 DisableOtherNetworks(); |
| 1008 // Wait until the service shows up and gets activated. | 692 // Wait until the service shows up and gets activated. |
| 1009 switch (network->activation_state()) { | 693 switch (network->activation_state()) { |
| 1010 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 694 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
| 1011 case chromeos::ACTIVATION_STATE_ACTIVATED: | 695 case ACTIVATION_STATE_ACTIVATED: |
| 1012 if (network->restricted_pool()) { | 696 if (network->restricted_pool()) { |
| 1013 LOG(WARNING) << "Still no connectivity after OTASP for device " | 697 LOG(WARNING) << "Still no connectivity after OTASP for device " |
| 1014 << network->service_path().c_str(); | 698 << network->service_path().c_str(); |
| 1015 // If we have already received payment, don't show the payment | 699 // If we have already received payment, don't show the payment |
| 1016 // page again. We should try to reconnect after some time instead. | 700 // page again. We should try to reconnect after some time instead. |
| 1017 if (reconnect_wait_count_ < kMaxReconnectAttemptOTASP) { | 701 if (reconnect_wait_count_ < kMaxReconnectAttemptOTASP) { |
| 1018 reconnect_wait_count_++; | 702 reconnect_wait_count_++; |
| 1019 LOG(WARNING) << "OTASP reconnect attempt #" | 703 LOG(WARNING) << "OTASP reconnect attempt #" |
| 1020 << reconnect_wait_count_; | 704 << reconnect_wait_count_; |
| 1021 ForceReconnect(network, kPostPaymentReconnectDelayMS); | 705 ForceReconnect(network, kPostPaymentReconnectDelayMS); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 case PLAN_ACTIVATION_ERROR: | 737 case PLAN_ACTIVATION_ERROR: |
| 1054 break; | 738 break; |
| 1055 } | 739 } |
| 1056 | 740 |
| 1057 if (new_state != PLAN_ACTIVATION_ERROR && | 741 if (new_state != PLAN_ACTIVATION_ERROR && |
| 1058 GotActivationError(network, &error_description)) { | 742 GotActivationError(network, &error_description)) { |
| 1059 // Check for this special case when we try to do activate partially | 743 // Check for this special case when we try to do activate partially |
| 1060 // activated device. If that attempt failed, try to disconnect to clear the | 744 // activated device. If that attempt failed, try to disconnect to clear the |
| 1061 // state and reconnect again. | 745 // state and reconnect again. |
| 1062 if ((network->activation_state() == | 746 if ((network->activation_state() == |
| 1063 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED || | 747 ACTIVATION_STATE_PARTIALLY_ACTIVATED || |
| 1064 network->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATING) && | 748 network->activation_state() == ACTIVATION_STATE_ACTIVATING) && |
| 1065 (network->error() == chromeos::ERROR_NO_ERROR || | 749 (network->error() == ERROR_NO_ERROR || |
| 1066 network->error() == chromeos::ERROR_OTASP_FAILED) && | 750 network->error() == ERROR_OTASP_FAILED) && |
| 1067 network->state() == chromeos::STATE_ACTIVATION_FAILURE) { | 751 network->state() == STATE_ACTIVATION_FAILURE) { |
| 1068 LOG(WARNING) << "Activation failure detected " | 752 LOG(WARNING) << "Activation failure detected " |
| 1069 << network->service_path().c_str(); | 753 << network->service_path().c_str(); |
| 1070 switch (state_) { | 754 switch (state_) { |
| 1071 case PLAN_ACTIVATION_OTASP: | 755 case PLAN_ACTIVATION_OTASP: |
| 1072 case PLAN_ACTIVATION_RECONNECTING_OTASP: | 756 case PLAN_ACTIVATION_RECONNECTING_OTASP: |
| 1073 new_state = PLAN_ACTIVATION_DELAY_OTASP; | 757 new_state = PLAN_ACTIVATION_DELAY_OTASP; |
| 1074 break; | 758 break; |
| 1075 case PLAN_ACTIVATION_TRYING_OTASP: | 759 case PLAN_ACTIVATION_TRYING_OTASP: |
| 1076 new_state = PLAN_ACTIVATION_RECONNECTING_OTASP_TRY; | 760 new_state = PLAN_ACTIVATION_RECONNECTING_OTASP_TRY; |
| 1077 break; | 761 break; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1099 } | 783 } |
| 1100 } | 784 } |
| 1101 | 785 |
| 1102 if (new_state == PLAN_ACTIVATION_ERROR && !error_description.length()) | 786 if (new_state == PLAN_ACTIVATION_ERROR && !error_description.length()) |
| 1103 error_description = GetErrorMessage(kErrorDefault); | 787 error_description = GetErrorMessage(kErrorDefault); |
| 1104 | 788 |
| 1105 ChangeState(network, new_state, error_description); | 789 ChangeState(network, new_state, error_description); |
| 1106 evaluating_ = false; | 790 evaluating_ = false; |
| 1107 } | 791 } |
| 1108 | 792 |
| 1109 MobileSetupHandler::PlanActivationState | 793 MobileActivator::PlanActivationState MobileActivator::GetNextReconnectState( |
| 1110 MobileSetupHandler::GetNextReconnectState( | 794 MobileActivator::PlanActivationState state) { |
| 1111 MobileSetupHandler::PlanActivationState state) { | |
| 1112 switch (state) { | 795 switch (state) { |
| 1113 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 796 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| 1114 return PLAN_ACTIVATION_RECONNECTING; | 797 return PLAN_ACTIVATION_RECONNECTING; |
| 1115 case PLAN_ACTIVATION_OTASP: | 798 case PLAN_ACTIVATION_OTASP: |
| 1116 return PLAN_ACTIVATION_RECONNECTING_OTASP; | 799 return PLAN_ACTIVATION_RECONNECTING_OTASP; |
| 1117 case PLAN_ACTIVATION_TRYING_OTASP: | 800 case PLAN_ACTIVATION_TRYING_OTASP: |
| 1118 return PLAN_ACTIVATION_RECONNECTING_OTASP_TRY; | 801 return PLAN_ACTIVATION_RECONNECTING_OTASP_TRY; |
| 1119 default: | 802 default: |
| 1120 return PLAN_ACTIVATION_RECONNECTING; | 803 return PLAN_ACTIVATION_RECONNECTING; |
| 1121 } | 804 } |
| 1122 } | 805 } |
| 1123 | 806 |
| 1124 // Debugging helper function, will take it out at the end. | 807 // Debugging helper function, will take it out at the end. |
| 1125 const char* MobileSetupHandler::GetStateDescription( | 808 const char* MobileActivator::GetStateDescription(PlanActivationState state) { |
| 1126 PlanActivationState state) { | |
| 1127 switch (state) { | 809 switch (state) { |
| 1128 case PLAN_ACTIVATION_PAGE_LOADING: | 810 case PLAN_ACTIVATION_PAGE_LOADING: |
| 1129 return "PAGE_LOADING"; | 811 return "PAGE_LOADING"; |
| 1130 case PLAN_ACTIVATION_START: | 812 case PLAN_ACTIVATION_START: |
| 1131 return "ACTIVATION_START"; | 813 return "ACTIVATION_START"; |
| 1132 case PLAN_ACTIVATION_TRYING_OTASP: | 814 case PLAN_ACTIVATION_TRYING_OTASP: |
| 1133 return "TRYING_OTASP"; | 815 return "TRYING_OTASP"; |
| 1134 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: | 816 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: |
| 1135 return "RECONNECTING_OTASP_TRY"; | 817 return "RECONNECTING_OTASP_TRY"; |
| 1136 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 818 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1153 return "RECONNECTING_OTASP"; | 835 return "RECONNECTING_OTASP"; |
| 1154 case PLAN_ACTIVATION_DONE: | 836 case PLAN_ACTIVATION_DONE: |
| 1155 return "DONE"; | 837 return "DONE"; |
| 1156 case PLAN_ACTIVATION_ERROR: | 838 case PLAN_ACTIVATION_ERROR: |
| 1157 return "ERROR"; | 839 return "ERROR"; |
| 1158 } | 840 } |
| 1159 return "UNKNOWN"; | 841 return "UNKNOWN"; |
| 1160 } | 842 } |
| 1161 | 843 |
| 1162 | 844 |
| 1163 void MobileSetupHandler::CompleteActivation( | 845 void MobileActivator::CompleteActivation( |
| 1164 chromeos::CellularNetwork* network) { | 846 CellularNetwork* network) { |
| 1165 // Remove observers, we are done with this page. | 847 // Remove observers, we are done with this page. |
| 1166 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 848 NetworkLibrary* lib = CrosLibrary::Get()-> |
| 1167 GetNetworkLibrary(); | 849 GetNetworkLibrary(); |
| 1168 lib->RemoveNetworkManagerObserver(this); | 850 lib->RemoveNetworkManagerObserver(this); |
| 1169 lib->RemoveObserverForAllNetworks(this); | 851 lib->RemoveObserverForAllNetworks(this); |
| 1170 if (lib->IsLocked()) | 852 if (lib->IsLocked()) |
| 1171 lib->Unlock(); | 853 lib->Unlock(); |
| 1172 // If we have successfully activated the connection, set autoconnect flag. | 854 // If we have successfully activated the connection, set autoconnect flag. |
| 1173 if (network) | 855 if (network) |
| 1174 network->SetAutoConnect(true); | 856 network->SetAutoConnect(true); |
| 1175 // Reactivate other types of connections if we have | 857 // Reactivate other types of connections if we have |
| 1176 // shut them down previously. | 858 // shut them down previously. |
| 1177 ReEnableOtherConnections(); | 859 ReEnableOtherConnections(); |
| 1178 } | 860 } |
| 1179 | 861 |
| 1180 void MobileSetupHandler::UpdatePage( | 862 bool MobileActivator::RunningActivation() const { |
| 1181 chromeos::CellularNetwork* network, | 863 return !(state_ == PLAN_ACTIVATION_DONE || |
| 1182 const std::string& error_description) { | 864 state_ == PLAN_ACTIVATION_ERROR || |
| 1183 DictionaryValue device_dict; | 865 state_ == PLAN_ACTIVATION_PAGE_LOADING); |
| 1184 if (network) | |
| 1185 GetDeviceInfo(network, &device_dict); | |
| 1186 device_dict.SetInteger("state", state_); | |
| 1187 if (error_description.length()) | |
| 1188 device_dict.SetString("error", error_description); | |
| 1189 web_ui()->CallJavascriptFunction( | |
| 1190 kJsDeviceStatusChangedCallback, device_dict); | |
| 1191 } | 866 } |
| 1192 | 867 |
| 1193 | 868 void MobileActivator::ChangeState(CellularNetwork* network, |
| 1194 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, | 869 PlanActivationState new_state, |
| 1195 PlanActivationState new_state, | 870 const std::string& error_description) { |
| 1196 const std::string& error_description) { | |
| 1197 static bool first_time = true; | 871 static bool first_time = true; |
| 1198 if (state_ == new_state && !first_time) | 872 if (state_ == new_state && !first_time) |
| 1199 return; | 873 return; |
| 1200 LOG(WARNING) << "Activation state flip old = " | 874 LOG(WARNING) << "Activation state flip old = " |
| 1201 << GetStateDescription(state_) | 875 << GetStateDescription(state_) |
| 1202 << ", new = " << GetStateDescription(new_state); | 876 << ", new = " << GetStateDescription(new_state); |
| 1203 first_time = false; | 877 first_time = false; |
| 1204 | 878 |
| 1205 // Pick action that should happen on leaving the old state. | 879 // Pick action that should happen on leaving the old state. |
| 1206 switch (state_) { | 880 switch (state_) { |
| 1207 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: | 881 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: |
| 1208 case PLAN_ACTIVATION_RECONNECTING: | 882 case PLAN_ACTIVATION_RECONNECTING: |
| 1209 case PLAN_ACTIVATION_RECONNECTING_OTASP: | 883 case PLAN_ACTIVATION_RECONNECTING_OTASP: |
| 1210 if (reconnect_timer_.IsRunning()) { | 884 if (reconnect_timer_.IsRunning()) { |
| 1211 reconnect_timer_.Stop(); | 885 reconnect_timer_.Stop(); |
| 1212 } | 886 } |
| 1213 break; | 887 break; |
| 1214 default: | 888 default: |
| 1215 break; | 889 break; |
| 1216 } | 890 } |
| 1217 state_ = new_state; | 891 state_ = new_state; |
| 1218 | 892 |
| 1219 // Signal to JS layer that the state is changing. | 893 // Signal to observers layer that the state is changing. |
| 1220 UpdatePage(network, error_description); | 894 FOR_EACH_OBSERVER(Observer, observers_, |
| 895 OnActivationStateChanged(network, state_, error_description)); |
| 1221 | 896 |
| 1222 // Pick action that should happen on entering the new state. | 897 // Pick action that should happen on entering the new state. |
| 1223 switch (new_state) { | 898 switch (new_state) { |
| 1224 case PLAN_ACTIVATION_START: | 899 case PLAN_ACTIVATION_START: |
| 1225 break; | 900 break; |
| 1226 case PLAN_ACTIVATION_DELAY_OTASP: { | 901 case PLAN_ACTIVATION_DELAY_OTASP: { |
| 1227 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); | 902 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); |
| 1228 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 903 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
| 1229 base::Bind(&MobileSetupHandler::RetryOTASP, AsWeakPtr()), | 904 base::Bind(&MobileActivator::RetryOTASP, AsWeakPtr()), |
| 1230 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay)); | 905 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay)); |
| 1231 break; | 906 break; |
| 1232 } | 907 } |
| 1233 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 908 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| 1234 case PLAN_ACTIVATION_TRYING_OTASP: | 909 case PLAN_ACTIVATION_TRYING_OTASP: |
| 1235 case PLAN_ACTIVATION_OTASP: | 910 case PLAN_ACTIVATION_OTASP: |
| 1236 DCHECK(network); | 911 DCHECK(network); |
| 1237 LOG(WARNING) << "Activating service " << network->service_path().c_str(); | 912 LOG(WARNING) << "Activating service " << network->service_path().c_str(); |
| 1238 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); | 913 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); |
| 1239 if (!network->StartActivation()) { | 914 if (!network->StartActivation()) { |
| 1240 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); | 915 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); |
| 1241 if (new_state == PLAN_ACTIVATION_OTASP) { | 916 if (new_state == PLAN_ACTIVATION_OTASP) { |
| 1242 ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); | 917 ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); |
| 1243 } else { | 918 } else { |
| 1244 ChangeState(network, PLAN_ACTIVATION_ERROR, | 919 ChangeState(network, PLAN_ACTIVATION_ERROR, |
| 1245 GetErrorMessage(kFailedConnectivity)); | 920 GetErrorMessage(kFailedConnectivity)); |
| 1246 } | 921 } |
| 1247 } | 922 } |
| 1248 break; | 923 break; |
| 1249 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: | 924 case PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: |
| 1250 case PLAN_ACTIVATION_RECONNECTING: | 925 case PLAN_ACTIVATION_RECONNECTING: |
| 1251 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: | 926 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: |
| 1252 case PLAN_ACTIVATION_RECONNECTING_OTASP: { | 927 case PLAN_ACTIVATION_RECONNECTING_OTASP: { |
| 1253 // Start reconnect timer. This will ensure that we are not left in | 928 // Start reconnect timer. This will ensure that we are not left in |
| 1254 // limbo by the network library. | 929 // limbo by the network library. |
| 1255 if (!reconnect_timer_.IsRunning()) { | 930 if (!reconnect_timer_.IsRunning()) { |
| 1256 reconnect_timer_.Start( | 931 reconnect_timer_.Start( |
| 1257 FROM_HERE, | 932 FROM_HERE, |
| 1258 base::TimeDelta::FromMilliseconds(kReconnectTimerDelayMS), | 933 base::TimeDelta::FromMilliseconds(kReconnectTimerDelayMS), |
| 1259 this, &MobileSetupHandler::ReconnectTimerFired); | 934 this, &MobileActivator::ReconnectTimerFired); |
| 1260 } | 935 } |
| 1261 // Reset connection metrics and try to connect. | 936 // Reset connection metrics and try to connect. |
| 1262 reconnect_wait_count_ = 0; | 937 reconnect_wait_count_ = 0; |
| 1263 connection_retry_count_ = 0; | 938 connection_retry_count_ = 0; |
| 1264 connection_start_time_ = base::Time::Now(); | 939 connection_start_time_ = base::Time::Now(); |
| 1265 ConnectToNetwork(network, kReconnectDelayMS); | 940 ConnectToNetwork(network, kReconnectDelayMS); |
| 1266 break; | 941 break; |
| 1267 } | 942 } |
| 1268 case PLAN_ACTIVATION_PAGE_LOADING: | 943 case PLAN_ACTIVATION_PAGE_LOADING: |
| 1269 return; | 944 return; |
| 1270 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 945 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
| 1271 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 946 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 1272 // Fix for fix SSL for the walled gardens where cert chain verification | 947 // Fix for fix SSL for the walled gardens where cert chain verification |
| 1273 // might not work. | 948 // might not work. |
| 1274 break; | 949 break; |
| 1275 case PLAN_ACTIVATION_DONE: | 950 case PLAN_ACTIVATION_DONE: |
| 1276 DCHECK(network); | 951 DCHECK(network); |
| 1277 CompleteActivation(network); | 952 CompleteActivation(network); |
| 1278 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupSucceeded", 1); | 953 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupSucceeded", 1); |
| 1279 break; | 954 break; |
| 1280 case PLAN_ACTIVATION_ERROR: | 955 case PLAN_ACTIVATION_ERROR: |
| 1281 CompleteActivation(NULL); | 956 CompleteActivation(NULL); |
| 1282 UMA_HISTOGRAM_COUNTS("Cellular.PlanFailed", 1); | 957 UMA_HISTOGRAM_COUNTS("Cellular.PlanFailed", 1); |
| 1283 break; | 958 break; |
| 1284 default: | 959 default: |
| 1285 break; | 960 break; |
| 1286 } | 961 } |
| 1287 } | 962 } |
| 1288 | 963 |
| 1289 void MobileSetupHandler::ReEnableOtherConnections() { | 964 void MobileActivator::ReEnableOtherConnections() { |
| 1290 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 965 NetworkLibrary* lib = CrosLibrary::Get()->GetNetworkLibrary(); |
| 1291 GetNetworkLibrary(); | |
| 1292 if (reenable_ethernet_) { | 966 if (reenable_ethernet_) { |
| 1293 reenable_ethernet_ = false; | 967 reenable_ethernet_ = false; |
| 1294 lib->EnableEthernetNetworkDevice(true); | 968 lib->EnableEthernetNetworkDevice(true); |
| 1295 } | 969 } |
| 1296 if (reenable_wifi_) { | 970 if (reenable_wifi_) { |
| 1297 reenable_wifi_ = false; | 971 reenable_wifi_ = false; |
| 1298 lib->EnableWifiNetworkDevice(true); | 972 lib->EnableWifiNetworkDevice(true); |
| 1299 } | 973 } |
| 1300 | 974 |
| 1301 PrefService* prefs = g_browser_process->local_state(); | 975 PrefService* prefs = g_browser_process->local_state(); |
| 1302 if (reenable_cert_check_) { | 976 if (reenable_cert_check_) { |
| 1303 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, | 977 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, |
| 1304 true); | 978 true); |
| 1305 reenable_cert_check_ = false; | 979 reenable_cert_check_ = false; |
| 1306 } | 980 } |
| 1307 } | 981 } |
| 1308 | 982 |
| 1309 void MobileSetupHandler::SetupActivationProcess( | 983 void MobileActivator::SetupActivationProcess(CellularNetwork* network) { |
| 1310 chromeos::CellularNetwork* network) { | |
| 1311 if (!network) | 984 if (!network) |
| 1312 return; | 985 return; |
| 1313 | 986 |
| 1314 // Disable SSL cert checks since we will be doing this in | 987 // Disable SSL cert checks since we will be doing this in |
| 1315 // restricted pool. | 988 // restricted pool. |
| 1316 PrefService* prefs = g_browser_process->local_state(); | 989 PrefService* prefs = g_browser_process->local_state(); |
| 1317 if (!reenable_cert_check_ && | 990 if (!reenable_cert_check_ && |
| 1318 prefs->GetBoolean( | 991 prefs->GetBoolean( |
| 1319 prefs::kCertRevocationCheckingEnabled)) { | 992 prefs::kCertRevocationCheckingEnabled)) { |
| 1320 reenable_cert_check_ = true; | 993 reenable_cert_check_ = true; |
| 1321 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); | 994 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); |
| 1322 } | 995 } |
| 1323 | 996 |
| 1324 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 997 NetworkLibrary* lib = CrosLibrary::Get()-> |
| 1325 GetNetworkLibrary(); | 998 GetNetworkLibrary(); |
| 1326 // Disable autoconnect to cellular network. | 999 // Disable autoconnect to cellular network. |
| 1327 network->SetAutoConnect(false); | 1000 network->SetAutoConnect(false); |
| 1328 | 1001 |
| 1329 // Prevent any other network interference. | 1002 // Prevent any other network interference. |
| 1330 DisableOtherNetworks(); | 1003 DisableOtherNetworks(); |
| 1331 lib->Lock(); | 1004 lib->Lock(); |
| 1332 } | 1005 } |
| 1333 | 1006 |
| 1334 void MobileSetupHandler::DisableOtherNetworks() { | 1007 void MobileActivator::DisableOtherNetworks() { |
| 1335 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 1008 NetworkLibrary* lib = CrosLibrary::Get()->GetNetworkLibrary(); |
| 1336 GetNetworkLibrary(); | |
| 1337 // Disable ethernet and wifi. | 1009 // Disable ethernet and wifi. |
| 1338 if (lib->ethernet_enabled()) { | 1010 if (lib->ethernet_enabled()) { |
| 1339 reenable_ethernet_ = true; | 1011 reenable_ethernet_ = true; |
| 1340 lib->EnableEthernetNetworkDevice(false); | 1012 lib->EnableEthernetNetworkDevice(false); |
| 1341 } | 1013 } |
| 1342 if (lib->wifi_enabled()) { | 1014 if (lib->wifi_enabled()) { |
| 1343 reenable_wifi_ = true; | 1015 reenable_wifi_ = true; |
| 1344 lib->EnableWifiNetworkDevice(false); | 1016 lib->EnableWifiNetworkDevice(false); |
| 1345 } | 1017 } |
| 1346 } | 1018 } |
| 1347 | 1019 |
| 1348 bool MobileSetupHandler::GotActivationError( | 1020 bool MobileActivator::GotActivationError( |
| 1349 chromeos::CellularNetwork* network, std::string* error) { | 1021 CellularNetwork* network, std::string* error) { |
| 1350 DCHECK(network); | 1022 DCHECK(network); |
| 1351 bool got_error = false; | 1023 bool got_error = false; |
| 1352 const char* error_code = kErrorDefault; | 1024 const char* error_code = kErrorDefault; |
| 1353 | 1025 |
| 1354 // This is the magic for detection of errors in during activation process. | 1026 // This is the magic for detection of errors in during activation process. |
| 1355 if (network->state() == chromeos::STATE_FAILURE && | 1027 if (network->state() == STATE_FAILURE && |
| 1356 network->error() == chromeos::ERROR_AAA_FAILED) { | 1028 network->error() == ERROR_AAA_FAILED) { |
| 1357 if (network->activation_state() == | 1029 if (network->activation_state() == |
| 1358 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | 1030 ACTIVATION_STATE_PARTIALLY_ACTIVATED) { |
| 1359 error_code = kErrorBadConnectionPartial; | 1031 error_code = kErrorBadConnectionPartial; |
| 1360 } else if (network->activation_state() == | 1032 } else if (network->activation_state() == |
| 1361 chromeos::ACTIVATION_STATE_ACTIVATED) { | 1033 ACTIVATION_STATE_ACTIVATED) { |
| 1362 if (network->roaming_state() == chromeos::ROAMING_STATE_HOME) { | 1034 if (network->roaming_state() == ROAMING_STATE_HOME) { |
| 1363 error_code = kErrorBadConnectionActivated; | 1035 error_code = kErrorBadConnectionActivated; |
| 1364 } else if (network->roaming_state() == chromeos::ROAMING_STATE_ROAMING) { | 1036 } else if (network->roaming_state() == ROAMING_STATE_ROAMING) { |
| 1365 error_code = kErrorRoamingOnConnection; | 1037 error_code = kErrorRoamingOnConnection; |
| 1366 } | 1038 } |
| 1367 } | 1039 } |
| 1368 got_error = true; | 1040 got_error = true; |
| 1369 } else if (network->state() == chromeos::STATE_ACTIVATION_FAILURE) { | 1041 } else if (network->state() == STATE_ACTIVATION_FAILURE) { |
| 1370 if (network->error() == chromeos::ERROR_NEED_EVDO) { | 1042 if (network->error() == ERROR_NEED_EVDO) { |
| 1371 if (network->activation_state() == | 1043 if (network->activation_state() == |
| 1372 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) | 1044 ACTIVATION_STATE_PARTIALLY_ACTIVATED) |
| 1373 error_code = kErrorNoEVDO; | 1045 error_code = kErrorNoEVDO; |
| 1374 } else if (network->error() == chromeos::ERROR_NEED_HOME_NETWORK) { | 1046 } else if (network->error() == ERROR_NEED_HOME_NETWORK) { |
| 1375 if (network->activation_state() == | 1047 if (network->activation_state() == |
| 1376 chromeos::ACTIVATION_STATE_NOT_ACTIVATED) { | 1048 ACTIVATION_STATE_NOT_ACTIVATED) { |
| 1377 error_code = kErrorRoamingActivation; | 1049 error_code = kErrorRoamingActivation; |
| 1378 } else if (network->activation_state() == | 1050 } else if (network->activation_state() == |
| 1379 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | 1051 ACTIVATION_STATE_PARTIALLY_ACTIVATED) { |
| 1380 error_code = kErrorRoamingPartiallyActivated; | 1052 error_code = kErrorRoamingPartiallyActivated; |
| 1381 } | 1053 } |
| 1382 } | 1054 } |
| 1383 got_error = true; | 1055 got_error = true; |
| 1384 } | 1056 } |
| 1385 | 1057 |
| 1386 if (got_error) | 1058 if (got_error) |
| 1387 *error = GetErrorMessage(error_code); | 1059 *error = GetErrorMessage(error_code); |
| 1388 | 1060 |
| 1389 return got_error; | 1061 return got_error; |
| 1390 } | 1062 } |
| 1391 | 1063 |
| 1392 void MobileSetupHandler::GetDeviceInfo(chromeos::CellularNetwork* network, | 1064 void MobileActivator::GetDeviceInfo(CellularNetwork* network, |
| 1393 DictionaryValue* value) { | 1065 DictionaryValue* value) { |
| 1394 DCHECK(network); | 1066 DCHECK(network); |
| 1395 chromeos::NetworkLibrary* cros = | 1067 NetworkLibrary* cros = |
| 1396 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 1068 CrosLibrary::Get()->GetNetworkLibrary(); |
| 1397 if (!cros) | 1069 if (!cros) |
| 1398 return; | 1070 return; |
| 1399 value->SetString("carrier", network->name()); | 1071 value->SetString("carrier", network->name()); |
| 1400 value->SetString("payment_url", network->payment_url()); | 1072 value->SetString("payment_url", network->payment_url()); |
| 1401 if (network->using_post() && network->post_data().length()) | 1073 if (network->using_post() && network->post_data().length()) |
| 1402 value->SetString("post_data", network->post_data()); | 1074 value->SetString("post_data", network->post_data()); |
| 1403 | 1075 |
| 1404 const chromeos::NetworkDevice* device = | 1076 const NetworkDevice* device = |
| 1405 cros->FindNetworkDeviceByPath(network->device_path()); | 1077 cros->FindNetworkDeviceByPath(network->device_path()); |
| 1406 if (device) { | 1078 if (device) { |
| 1407 value->SetString("MEID", device->meid()); | 1079 value->SetString("MEID", device->meid()); |
| 1408 value->SetString("IMEI", device->imei()); | 1080 value->SetString("IMEI", device->imei()); |
| 1409 value->SetString("MDN", device->mdn()); | 1081 value->SetString("MDN", device->mdn()); |
| 1410 } | 1082 } |
| 1411 } | 1083 } |
| 1412 | 1084 |
| 1413 std::string MobileSetupHandler::GetErrorMessage(const std::string& code) { | 1085 std::string MobileActivator::GetErrorMessage(const std::string& code) { |
| 1414 return cellular_config_->GetErrorMessage(code); | 1086 return cellular_config_->GetErrorMessage(code); |
| 1415 } | 1087 } |
| 1416 | 1088 |
| 1417 void MobileSetupHandler::StartActivationOnUIThread() { | 1089 } // namespace chromeos |
| 1418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1419 chromeos::NetworkLibrary* lib = | |
| 1420 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | |
| 1421 | |
| 1422 chromeos::CellularNetwork* network = | |
| 1423 lib->FindCellularNetworkByPath(service_path_); | |
| 1424 | |
| 1425 if (!network || !network->SupportsActivation()) { | |
| 1426 LOG(ERROR) << "Cellular service can't be found: " << service_path_; | |
| 1427 return; | |
| 1428 } | |
| 1429 | |
| 1430 const chromeos::NetworkDevice* device = | |
| 1431 lib->FindNetworkDeviceByPath(network->device_path()); | |
| 1432 if (!device) { | |
| 1433 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); | |
| 1434 return; | |
| 1435 } | |
| 1436 | |
| 1437 meid_ = device->meid(); | |
| 1438 if (!chromeos::CrosLibrary::Get()->GetNetworkLibrary()->IsLocked()) | |
| 1439 SetupActivationProcess(network); | |
| 1440 else | |
| 1441 already_running_ = true; | |
| 1442 | |
| 1443 StartActivation(); | |
| 1444 } | |
| 1445 | |
| 1446 //////////////////////////////////////////////////////////////////////////////// | |
| 1447 // | |
| 1448 // MobileSetupUI | |
| 1449 // | |
| 1450 //////////////////////////////////////////////////////////////////////////////// | |
| 1451 | |
| 1452 MobileSetupUI::MobileSetupUI(content::WebUI* web_ui) | |
| 1453 : WebUIController(web_ui) { | |
| 1454 chromeos::CellularNetwork* network = GetCellularNetwork(); | |
| 1455 std::string service_path = network ? network->service_path() : std::string(); | |
| 1456 web_ui->AddMessageHandler(new MobileSetupHandler(service_path)); | |
| 1457 MobileSetupUIHTMLSource* html_source = | |
| 1458 new MobileSetupUIHTMLSource(service_path); | |
| 1459 | |
| 1460 // Set up the chrome://mobilesetup/ source. | |
| 1461 Profile* profile = Profile::FromWebUI(web_ui); | |
| 1462 ChromeURLDataManager::AddDataSource(profile, html_source); | |
| 1463 } | |
| 1464 | |
| 1465 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) { | |
| 1466 // Destroyed by the corresponding RenderViewHost | |
| 1467 new PortalFrameLoadObserver(AsWeakPtr(), host); | |
| 1468 } | |
| OLD | NEW |