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

Side by Side Diff: chrome/browser/chromeos/mobile/mobile_activator.h

Issue 22611005: Switch over MobileActivator to use Network*Handler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add activation handler files Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 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
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
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
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 NetworkManagerChanged() OVERRIDE;
138 // NetworkLibrary::NetworkObserver overrides. 144 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE;
139 virtual void OnNetworkChanged(NetworkLibrary* obj, 145 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE;
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();
167 // Verify the state of cellular network and modify internal state. 173 // Verify the state of cellular network and modify internal state.
168 virtual void EvaluateCellularNetwork(CellularNetwork* network); 174 virtual void EvaluateCellularNetwork(const NetworkState* network);
169 // PickNextState selects the desired state based on the current state of the 175 // 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. 176 // modem and the activator. It does not transition to this state however.
171 PlanActivationState PickNextState(CellularNetwork* network, 177 PlanActivationState PickNextState(const NetworkState* network,
172 std::string* error_description) const; 178 std::string* error_description) const;
173 // One of PickNext*State are called in PickNextState based on whether the 179 // One of PickNext*State are called in PickNextState based on whether the
174 // modem is online or not. 180 // modem is online or not.
175 PlanActivationState PickNextOnlineState(CellularNetwork* network) const; 181 PlanActivationState PickNextOnlineState(const NetworkState* network) const;
176 PlanActivationState PickNextOfflineState(CellularNetwork* network) const; 182 PlanActivationState PickNextOfflineState(const NetworkState* network) const;
177 // Check the current cellular network for error conditions. 183 // Check the current cellular network for error conditions.
178 bool GotActivationError(CellularNetwork* network, 184 bool GotActivationError(const NetworkState* network,
179 std::string* error) const; 185 std::string* error) const;
180 // Sends status updates to WebUI page. 186 // Sends status updates to WebUI page.
181 void UpdatePage(CellularNetwork* network, 187 void UpdatePage(const NetworkState* network,
182 const std::string& error_description); 188 const std::string& error_description);
189
190 // Callback used to handle an activation error.
191 void HandleActivationFailure(
192 const std::string& service_path,
193 PlanActivationState new_state,
194 const std::string& error_name,
195 scoped_ptr<base::DictionaryValue> error_data);
196
183 // Changes internal state. 197 // Changes internal state.
184 virtual void ChangeState(CellularNetwork* network, 198 virtual void ChangeState(const NetworkState* network,
185 PlanActivationState new_state, 199 PlanActivationState new_state,
186 const std::string& error_description); 200 const std::string& error_description);
187 // Resets network devices after cellular activation process. 201 // Resets network devices after cellular activation process.
188 // |network| should be NULL if the activation process failed. 202 // |network| should be NULL if the activation process failed.
189 void CompleteActivation(CellularNetwork* network); 203 void CompleteActivation(const NetworkState* network);
190 // Disables SSL certificate revocation checking mechanism. In the case 204 // Disables SSL certificate revocation checking mechanism. In the case
191 // where captive portal connection is the only one present, such revocation 205 // where captive portal connection is the only one present, such revocation
192 // checks could prevent payment portal page from loading. 206 // checks could prevent payment portal page from loading.
193 void DisableCertRevocationChecking(); 207 void DisableCertRevocationChecking();
194 // Reenables SSL certificate revocation checking mechanism. 208 // Reenables SSL certificate revocation checking mechanism.
195 void ReEnableCertRevocationChecking(); 209 void ReEnableCertRevocationChecking();
196 // Return error message for a given code. 210 // Return error message for a given code.
197 std::string GetErrorMessage(const std::string& code) const; 211 std::string GetErrorMessage(const std::string& code) const;
198 212
199 // Converts the currently active CellularNetwork device into a JS object. 213 // Converts the currently active CellularNetwork device into a JS object.
200 static void GetDeviceInfo(CellularNetwork* network, 214 static void GetDeviceInfo(const NetworkState* network,
201 DictionaryValue* value); 215 base::DictionaryValue* value);
202 static bool ShouldReportDeviceState(std::string* state, std::string* error); 216 static bool ShouldReportDeviceState(std::string* state, std::string* error);
203 217
204 // Performs activation state cellular device evaluation. 218 // Performs activation state cellular device evaluation.
205 // Returns false if device activation failed. In this case |error| 219 // Returns false if device activation failed. In this case |error|
206 // will contain error message to be reported to Web UI. 220 // will contain error message to be reported to Web UI.
207 static bool EvaluateCellularDeviceState(bool* report_status, 221 static bool EvaluateCellularDeviceState(bool* report_status,
208 std::string* state, 222 std::string* state,
209 std::string* error); 223 std::string* error);
210 // Finds cellular network that matches |meid_| or |iccid_|, reattach network 224 // Finds cellular network that matches |meid_| or |iccid_|, reattach network
211 // change observer if |reattach_observer| flag is set. 225 // change observer if |reattach_observer| flag is set.
212 virtual CellularNetwork* FindMatchingCellularNetwork(bool reattach_observer); 226 virtual const NetworkState* FindMatchingCellularNetwork(
227 bool reattach_observer);
213 // Starts the OTASP timeout timer. If the timer fires, we'll force a 228 // Starts the OTASP timeout timer. If the timer fires, we'll force a
214 // disconnect/reconnect cycle on this network. 229 // disconnect/reconnect cycle on this network.
215 virtual void StartOTASPTimer(); 230 virtual void StartOTASPTimer();
216 231
232 // Records information that cellular plan payment has happened.
233 virtual void SignalCellularPlanPayment();
234
235 // Returns true if cellular plan payment has been recorded recently.
236 virtual bool HasRecentCellularPlanPayment() const;
237
217 static const char* GetStateDescription(PlanActivationState state); 238 static const char* GetStateDescription(PlanActivationState state);
218 239
219 virtual NetworkLibrary* GetNetworkLibrary() const;
220
221 scoped_refptr<CellularConfigDocument> cellular_config_; 240 scoped_refptr<CellularConfigDocument> cellular_config_;
222 // Internal handler state. 241 // Internal handler state.
223 PlanActivationState state_; 242 PlanActivationState state_;
224 // MEID of cellular device to activate. 243 // MEID of cellular device to activate.
225 std::string meid_; 244 std::string meid_;
226 // ICCID of the SIM card on cellular device to activate. 245 // ICCID of the SIM card on cellular device to activate.
227 std::string iccid_; 246 std::string iccid_;
228 // Service path of network being activated. Note that the path can change 247 // Service path of network being activated. Note that the path can change
229 // during the activation process while still representing the same service. 248 // during the activation process while still representing the same service.
230 std::string service_path_; 249 std::string service_path_;
(...skipping 12 matching lines...) Expand all
243 int payment_reconnect_count_; 262 int payment_reconnect_count_;
244 // Timer that monitors how long we spend in error-prone states. 263 // Timer that monitors how long we spend in error-prone states.
245 base::RepeatingTimer<MobileActivator> state_duration_timer_; 264 base::RepeatingTimer<MobileActivator> state_duration_timer_;
246 265
247 // State we will return to if we are disconnected. 266 // State we will return to if we are disconnected.
248 PlanActivationState post_reconnect_state_; 267 PlanActivationState post_reconnect_state_;
249 // Called to continue the reconnect attempt. 268 // Called to continue the reconnect attempt.
250 base::RepeatingTimer<MobileActivator> continue_reconnect_timer_; 269 base::RepeatingTimer<MobileActivator> continue_reconnect_timer_;
251 // Called when the reconnect attempt times out. 270 // Called when the reconnect attempt times out.
252 base::OneShotTimer<MobileActivator> reconnect_timeout_timer_; 271 base::OneShotTimer<MobileActivator> reconnect_timeout_timer_;
253 272 // Cellular plan payment time.
273 base::Time cellular_plan_payment_time_;
254 274
255 ObserverList<Observer> observers_; 275 ObserverList<Observer> observers_;
256 276
257 DISALLOW_COPY_AND_ASSIGN(MobileActivator); 277 DISALLOW_COPY_AND_ASSIGN(MobileActivator);
258 }; 278 };
259 279
260 } // namespace chromeos 280 } // namespace chromeos
261 281
262 #endif // CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_ 282 #endif // CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698