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