| 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 #ifndef CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 15 #include "chrome/browser/chromeos/cros/network_library.h" | 16 #include "base/timer/timer.h" |
| 17 #include "chromeos/network/network_state_handler_observer.h" |
| 16 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 17 | 19 |
| 20 namespace base { |
| 21 class DictionaryValue; |
| 22 } |
| 23 |
| 18 namespace chromeos { | 24 namespace chromeos { |
| 19 | 25 |
| 26 class NetworkState; |
| 20 class TestMobileActivator; | 27 class TestMobileActivator; |
| 21 | 28 |
| 22 // Cellular plan config document. | 29 // Cellular plan config document. |
| 23 class CellularConfigDocument | 30 class CellularConfigDocument |
| 24 : public base::RefCountedThreadSafe<CellularConfigDocument> { | 31 : public base::RefCountedThreadSafe<CellularConfigDocument> { |
| 25 public: | 32 public: |
| 26 CellularConfigDocument(); | 33 CellularConfigDocument(); |
| 27 | 34 |
| 28 // Return error message for a given code. | 35 // Return error message for a given code. |
| 29 std::string GetErrorMessage(const std::string& code); | 36 std::string GetErrorMessage(const std::string& code); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 | 48 |
| 42 std::string version_; | 49 std::string version_; |
| 43 ErrorMap error_map_; | 50 ErrorMap error_map_; |
| 44 base::Lock config_lock_; | 51 base::Lock config_lock_; |
| 45 | 52 |
| 46 DISALLOW_COPY_AND_ASSIGN(CellularConfigDocument); | 53 DISALLOW_COPY_AND_ASSIGN(CellularConfigDocument); |
| 47 }; | 54 }; |
| 48 | 55 |
| 49 // This class performs mobile plan activation process. | 56 // This class performs mobile plan activation process. |
| 50 class MobileActivator | 57 class MobileActivator |
| 51 : public NetworkLibrary::NetworkManagerObserver, | 58 : public base::SupportsWeakPtr<MobileActivator>, |
| 52 public NetworkLibrary::NetworkObserver, | 59 public NetworkStateHandlerObserver { |
| 53 public base::SupportsWeakPtr<MobileActivator> { | |
| 54 public: | 60 public: |
| 55 // Activation state. | 61 // Activation state. |
| 56 enum PlanActivationState { | 62 enum PlanActivationState { |
| 57 // Activation WebUI page is loading, activation not started. | 63 // Activation WebUI page is loading, activation not started. |
| 58 PLAN_ACTIVATION_PAGE_LOADING = -1, | 64 PLAN_ACTIVATION_PAGE_LOADING = -1, |
| 59 // Activation process started. | 65 // Activation process started. |
| 60 PLAN_ACTIVATION_START = 0, | 66 PLAN_ACTIVATION_START = 0, |
| 61 // Initial over the air activation attempt. | 67 // Initial over the air activation attempt. |
| 62 PLAN_ACTIVATION_TRYING_OTASP = 1, | 68 PLAN_ACTIVATION_TRYING_OTASP = 1, |
| 63 // Performing pre-activation process. | 69 // Performing pre-activation process. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 84 PLAN_ACTIVATION_DONE = 12, | 90 PLAN_ACTIVATION_DONE = 12, |
| 85 // Error occured during activation process. | 91 // Error occured during activation process. |
| 86 PLAN_ACTIVATION_ERROR = 0xFF, | 92 PLAN_ACTIVATION_ERROR = 0xFF, |
| 87 }; | 93 }; |
| 88 | 94 |
| 89 // Activation process observer. | 95 // Activation process observer. |
| 90 class Observer { | 96 class Observer { |
| 91 public: | 97 public: |
| 92 // Signals activation |state| change for given |network|. | 98 // Signals activation |state| change for given |network|. |
| 93 virtual void OnActivationStateChanged( | 99 virtual void OnActivationStateChanged( |
| 94 CellularNetwork* network, | 100 const NetworkState* network, |
| 95 PlanActivationState state, | 101 PlanActivationState state, |
| 96 const std::string& error_description) = 0; | 102 const std::string& error_description) = 0; |
| 97 | 103 |
| 98 protected: | 104 protected: |
| 99 Observer() {} | 105 Observer() {} |
| 100 virtual ~Observer() {} | 106 virtual ~Observer() {} |
| 101 }; | 107 }; |
| 102 | 108 |
| 103 static MobileActivator* GetInstance(); | 109 static MobileActivator* GetInstance(); |
| 104 | 110 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 126 FRIEND_TEST_ALL_PREFIXES(MobileActivatorTest, OTASPScheduling); | 132 FRIEND_TEST_ALL_PREFIXES(MobileActivatorTest, OTASPScheduling); |
| 127 FRIEND_TEST_ALL_PREFIXES(MobileActivatorTest, | 133 FRIEND_TEST_ALL_PREFIXES(MobileActivatorTest, |
| 128 ReconnectOnDisconnectFromPaymentPortal); | 134 ReconnectOnDisconnectFromPaymentPortal); |
| 129 FRIEND_TEST_ALL_PREFIXES(MobileActivatorTest, StartAtStart); | 135 FRIEND_TEST_ALL_PREFIXES(MobileActivatorTest, StartAtStart); |
| 130 // We reach directly into the activator for testing purposes. | 136 // We reach directly into the activator for testing purposes. |
| 131 friend class MobileActivatorTest; | 137 friend class MobileActivatorTest; |
| 132 | 138 |
| 133 MobileActivator(); | 139 MobileActivator(); |
| 134 virtual ~MobileActivator(); | 140 virtual ~MobileActivator(); |
| 135 | 141 |
| 136 // NetworkLibrary::NetworkManagerObserver overrides. | 142 // NetworkStateHandlerObserver overrides. |
| 137 virtual void OnNetworkManagerChanged(NetworkLibrary* obj) OVERRIDE; | 143 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE; |
| 138 // NetworkLibrary::NetworkObserver overrides. | 144 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE; |
| 139 virtual void OnNetworkChanged(NetworkLibrary* obj, | |
| 140 const Network* network) OVERRIDE; | |
| 141 | 145 |
| 142 // Continue activation after inital setup (config load). | 146 // Continue activation after inital setup (config load). |
| 143 void ContinueActivation(); | 147 void ContinueActivation(); |
| 144 // Handles the signal that the payment portal has finished loading. | 148 // Handles the signal that the payment portal has finished loading. |
| 145 void HandlePortalLoaded(bool success); | 149 void HandlePortalLoaded(bool success); |
| 146 // Handles the signal that the user has finished with the portal. | 150 // Handles the signal that the user has finished with the portal. |
| 147 void HandleSetTransactionStatus(bool success); | 151 void HandleSetTransactionStatus(bool success); |
| 148 // Starts activation. | 152 // Starts activation. |
| 149 void StartActivation(); | 153 void StartActivation(); |
| 150 // Called after we delay our OTASP (after payment). | 154 // Called after we delay our OTASP (after payment). |
| 151 void RetryOTASP(); | 155 void RetryOTASP(); |
| 152 // Continues activation process. This method is called after we disconnect | 156 // Continues activation process. This method is called after we disconnect |
| 153 // due to detected connectivity issue to kick off reconnection. | 157 // due to detected connectivity issue to kick off reconnection. |
| 154 void ContinueConnecting(); | 158 void ContinueConnecting(); |
| 155 | 159 |
| 156 // Sends message to host registration page with system/user info data. | 160 // Sends message to host registration page with system/user info data. |
| 157 void SendDeviceInfo(); | 161 void SendDeviceInfo(); |
| 158 | 162 |
| 159 // Starts OTASP process. | 163 // Starts OTASP process. |
| 160 void StartOTASP(); | 164 void StartOTASP(); |
| 161 // Called when an OTASP attempt times out. | 165 // Called when an OTASP attempt times out. |
| 162 void HandleOTASPTimeout(); | 166 void HandleOTASPTimeout(); |
| 163 // Forces disconnect / reconnect when we detect portal connectivity issues. | 167 // Forces disconnect / reconnect when we detect portal connectivity issues. |
| 164 void ForceReconnect(CellularNetwork* network, PlanActivationState next_state); | 168 void ForceReconnect(const NetworkState* network, |
| 169 PlanActivationState next_state); |
| 165 // Called when ForceReconnect takes too long to reconnect. | 170 // Called when ForceReconnect takes too long to reconnect. |
| 166 void ReconnectTimedOut(); | 171 void ReconnectTimedOut(); |
| 172 |
| 173 // Called on default network changes to update cellular network activation |
| 174 // state. |
| 175 void RefreshCellularNetworks(); |
| 167 // Verify the state of cellular network and modify internal state. | 176 // Verify the state of cellular network and modify internal state. |
| 168 virtual void EvaluateCellularNetwork(CellularNetwork* network); | 177 virtual void EvaluateCellularNetwork(const NetworkState* network); |
| 169 // PickNextState selects the desired state based on the current state of the | 178 // PickNextState selects the desired state based on the current state of the |
| 170 // modem and the activator. It does not transition to this state however. | 179 // modem and the activator. It does not transition to this state however. |
| 171 PlanActivationState PickNextState(CellularNetwork* network, | 180 PlanActivationState PickNextState(const NetworkState* network, |
| 172 std::string* error_description) const; | 181 std::string* error_description) const; |
| 173 // One of PickNext*State are called in PickNextState based on whether the | 182 // One of PickNext*State are called in PickNextState based on whether the |
| 174 // modem is online or not. | 183 // modem is online or not. |
| 175 PlanActivationState PickNextOnlineState(CellularNetwork* network) const; | 184 PlanActivationState PickNextOnlineState(const NetworkState* network) const; |
| 176 PlanActivationState PickNextOfflineState(CellularNetwork* network) const; | 185 PlanActivationState PickNextOfflineState(const NetworkState* network) const; |
| 177 // Check the current cellular network for error conditions. | 186 // Check the current cellular network for error conditions. |
| 178 bool GotActivationError(CellularNetwork* network, | 187 bool GotActivationError(const NetworkState* network, |
| 179 std::string* error) const; | 188 std::string* error) const; |
| 180 // Sends status updates to WebUI page. | 189 // Sends status updates to WebUI page. |
| 181 void UpdatePage(CellularNetwork* network, | 190 void UpdatePage(const NetworkState* network, |
| 182 const std::string& error_description); | 191 const std::string& error_description); |
| 192 |
| 193 // Callback used to handle an activation error. |
| 194 void HandleActivationFailure( |
| 195 const std::string& service_path, |
| 196 PlanActivationState new_state, |
| 197 const std::string& error_name, |
| 198 scoped_ptr<base::DictionaryValue> error_data); |
| 199 |
| 183 // Changes internal state. | 200 // Changes internal state. |
| 184 virtual void ChangeState(CellularNetwork* network, | 201 virtual void ChangeState(const NetworkState* network, |
| 185 PlanActivationState new_state, | 202 PlanActivationState new_state, |
| 186 const std::string& error_description); | 203 const std::string& error_description); |
| 187 // Resets network devices after cellular activation process. | 204 // Resets network devices after cellular activation process. |
| 188 // |network| should be NULL if the activation process failed. | 205 // |network| should be NULL if the activation process failed. |
| 189 void CompleteActivation(CellularNetwork* network); | 206 void CompleteActivation(const NetworkState* network); |
| 190 // Disables SSL certificate revocation checking mechanism. In the case | 207 // Disables SSL certificate revocation checking mechanism. In the case |
| 191 // where captive portal connection is the only one present, such revocation | 208 // where captive portal connection is the only one present, such revocation |
| 192 // checks could prevent payment portal page from loading. | 209 // checks could prevent payment portal page from loading. |
| 193 void DisableCertRevocationChecking(); | 210 void DisableCertRevocationChecking(); |
| 194 // Reenables SSL certificate revocation checking mechanism. | 211 // Reenables SSL certificate revocation checking mechanism. |
| 195 void ReEnableCertRevocationChecking(); | 212 void ReEnableCertRevocationChecking(); |
| 196 // Return error message for a given code. | 213 // Return error message for a given code. |
| 197 std::string GetErrorMessage(const std::string& code) const; | 214 std::string GetErrorMessage(const std::string& code) const; |
| 198 | 215 |
| 199 // Converts the currently active CellularNetwork device into a JS object. | 216 // Converts the currently active CellularNetwork device into a JS object. |
| 200 static void GetDeviceInfo(CellularNetwork* network, | 217 static void GetDeviceInfo(const NetworkState* network, |
| 201 DictionaryValue* value); | 218 base::DictionaryValue* value); |
| 202 static bool ShouldReportDeviceState(std::string* state, std::string* error); | 219 static bool ShouldReportDeviceState(std::string* state, std::string* error); |
| 203 | 220 |
| 204 // Performs activation state cellular device evaluation. | 221 // Performs activation state cellular device evaluation. |
| 205 // Returns false if device activation failed. In this case |error| | 222 // Returns false if device activation failed. In this case |error| |
| 206 // will contain error message to be reported to Web UI. | 223 // will contain error message to be reported to Web UI. |
| 207 static bool EvaluateCellularDeviceState(bool* report_status, | 224 static bool EvaluateCellularDeviceState(bool* report_status, |
| 208 std::string* state, | 225 std::string* state, |
| 209 std::string* error); | 226 std::string* error); |
| 210 // Finds cellular network that matches |meid_| or |iccid_|, reattach network | |
| 211 // change observer if |reattach_observer| flag is set. | |
| 212 virtual CellularNetwork* FindMatchingCellularNetwork(bool reattach_observer); | |
| 213 // Starts the OTASP timeout timer. If the timer fires, we'll force a | 227 // Starts the OTASP timeout timer. If the timer fires, we'll force a |
| 214 // disconnect/reconnect cycle on this network. | 228 // disconnect/reconnect cycle on this network. |
| 215 virtual void StartOTASPTimer(); | 229 virtual void StartOTASPTimer(); |
| 216 | 230 |
| 231 // Records information that cellular plan payment has happened. |
| 232 virtual void SignalCellularPlanPayment(); |
| 233 |
| 234 // Returns true if cellular plan payment has been recorded recently. |
| 235 virtual bool HasRecentCellularPlanPayment() const; |
| 236 |
| 217 static const char* GetStateDescription(PlanActivationState state); | 237 static const char* GetStateDescription(PlanActivationState state); |
| 218 | 238 |
| 219 virtual NetworkLibrary* GetNetworkLibrary() const; | |
| 220 | |
| 221 scoped_refptr<CellularConfigDocument> cellular_config_; | 239 scoped_refptr<CellularConfigDocument> cellular_config_; |
| 222 // Internal handler state. | 240 // Internal handler state. |
| 223 PlanActivationState state_; | 241 PlanActivationState state_; |
| 224 // MEID of cellular device to activate. | 242 // MEID of cellular device to activate. |
| 225 std::string meid_; | 243 std::string meid_; |
| 226 // ICCID of the SIM card on cellular device to activate. | 244 // ICCID of the SIM card on cellular device to activate. |
| 227 std::string iccid_; | 245 std::string iccid_; |
| 228 // Service path of network being activated. Note that the path can change | 246 // Service path of network being activated. Note that the path can change |
| 229 // during the activation process while still representing the same service. | 247 // during the activation process while still representing the same service. |
| 230 std::string service_path_; | 248 std::string service_path_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 243 int payment_reconnect_count_; | 261 int payment_reconnect_count_; |
| 244 // Timer that monitors how long we spend in error-prone states. | 262 // Timer that monitors how long we spend in error-prone states. |
| 245 base::RepeatingTimer<MobileActivator> state_duration_timer_; | 263 base::RepeatingTimer<MobileActivator> state_duration_timer_; |
| 246 | 264 |
| 247 // State we will return to if we are disconnected. | 265 // State we will return to if we are disconnected. |
| 248 PlanActivationState post_reconnect_state_; | 266 PlanActivationState post_reconnect_state_; |
| 249 // Called to continue the reconnect attempt. | 267 // Called to continue the reconnect attempt. |
| 250 base::RepeatingTimer<MobileActivator> continue_reconnect_timer_; | 268 base::RepeatingTimer<MobileActivator> continue_reconnect_timer_; |
| 251 // Called when the reconnect attempt times out. | 269 // Called when the reconnect attempt times out. |
| 252 base::OneShotTimer<MobileActivator> reconnect_timeout_timer_; | 270 base::OneShotTimer<MobileActivator> reconnect_timeout_timer_; |
| 253 | 271 // Cellular plan payment time. |
| 272 base::Time cellular_plan_payment_time_; |
| 254 | 273 |
| 255 ObserverList<Observer> observers_; | 274 ObserverList<Observer> observers_; |
| 256 | 275 |
| 257 DISALLOW_COPY_AND_ASSIGN(MobileActivator); | 276 DISALLOW_COPY_AND_ASSIGN(MobileActivator); |
| 258 }; | 277 }; |
| 259 | 278 |
| 260 } // namespace chromeos | 279 } // namespace chromeos |
| 261 | 280 |
| 262 #endif // CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_ | 281 #endif // CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_ |
| OLD | NEW |