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

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

Issue 10456045: Refactored mobile activation engine outside of WebUI handler in order to expose its state to other … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 8 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_
6 #define CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_
7 #pragma once
8
9 #include <map>
10 #include <string>
11
12 #include "base/file_path.h"
13 #include "base/memory/singleton.h"
14 #include "base/observer_list.h"
15 #include "chrome/browser/chromeos/cros/network_library.h"
16
17 namespace chromeos {
18
19 // Cellular plan config document.
20 class CellularConfigDocument
21 : public base::RefCountedThreadSafe<CellularConfigDocument> {
22 public:
23 CellularConfigDocument();
24 virtual ~CellularConfigDocument();
25
26 // Return error message for a given code.
27 std::string GetErrorMessage(const std::string& code);
28 void LoadCellularConfigFile();
29 const std::string& version() { return version_; }
30
31 private:
32 typedef std::map<std::string, std::string> ErrorMap;
33
34 void SetErrorMap(const ErrorMap& map);
35 bool LoadFromFile(const FilePath& config_path);
36
37 std::string version_;
38 ErrorMap error_map_;
39 base::Lock config_lock_;
40
41 DISALLOW_COPY_AND_ASSIGN(CellularConfigDocument);
42 };
43
44 // This class performs mobile plan activation process.
45 class MobileActivator
46 : public NetworkLibrary::NetworkManagerObserver,
47 public NetworkLibrary::NetworkObserver {
48 public:
49 // Activation state.
50 enum PlanActivationState {
51 // Activation WebUI page is loading, activation not started.
52 PLAN_ACTIVATION_PAGE_LOADING = -1,
53 // Activation process started.
54 PLAN_ACTIVATION_START = 0,
55 // Initial over the air activation attempt.
56 PLAN_ACTIVATION_TRYING_OTASP = 1,
57 // Reconnection after the initial activation attempt.
58 PLAN_ACTIVATION_RECONNECTING_OTASP_TRY = 2,
59 // Performing pre-activation process.
60 PLAN_ACTIVATION_INITIATING_ACTIVATION = 3,
61 // Reconnecting to network.
62 PLAN_ACTIVATION_RECONNECTING = 4,
63 // Loading payment portal page.
64 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING = 5,
65 // Showing payment portal page.
66 PLAN_ACTIVATION_SHOWING_PAYMENT = 6,
67 // Reconnecting after successful plan payment.
68 PLAN_ACTIVATION_RECONNECTING_PAYMENT = 7,
69 // Delaying activation until payment portal catches up.
70 PLAN_ACTIVATION_DELAY_OTASP = 8,
71 // Starting post-payment activation attempt.
72 PLAN_ACTIVATION_START_OTASP = 9,
73 // Attempting activation.
74 PLAN_ACTIVATION_OTASP = 10,
75 // Reconnecting after activation attempt.
76 PLAN_ACTIVATION_RECONNECTING_OTASP = 11,
77 // Finished activation.
78 PLAN_ACTIVATION_DONE = 12,
79 // Error occured during activation process.
80 PLAN_ACTIVATION_ERROR = 0xFF,
81 };
82
83 // Activation process observer.
84 class Observer {
85 public:
86 // Signals activation |state| change for given |network|.
87 virtual void OnActivationStateChanged(
88 CellularNetwork* network,
89 PlanActivationState state,
90 const std::string& error_description) = 0;
91
92 protected:
93 Observer() {}
94 virtual ~Observer() {}
95 };
96
97 static MobileActivator* GetInstance();
98
99 // Add/remove activation process observer.
100 void AddObserver(Observer* observer);
101 void RemoveObserver(Observer* observer);
102
103 // Activation is in process.
104 bool RunningActivation() const;
105 // Activation state.
106 PlanActivationState state() const { return state_; }
107 // Initiates activation process.
108 void InitiateActivation(const std::string& service_path);
109 // Terminates activation process if already started.
110 void TerminateActivation();
111 // Process portal load attempt status.
112 void OnPortalLoaded(bool success);
113 // Process payment transaction status.
114 void OnSetTransactionStatus(bool success);
115
116 private:
117 friend struct DefaultSingletonTraits<MobileActivator>;
118
119 MobileActivator();
120 virtual ~MobileActivator();
121
122 // NetworkLibrary::NetworkManagerObserver overrides.
123 virtual void OnNetworkManagerChanged(NetworkLibrary* obj) OVERRIDE;
124 // NetworkLibrary::NetworkObserver overrides.
125 virtual void OnNetworkChanged(NetworkLibrary* obj,
126 const Network* network) OVERRIDE;
127
128 // Continue activation after inital setup (config load).
129 void ContinueActivation();
130 // Process payment transaction results.
131 void SetTransactionStatus(bool success);
132 // Starts activation.
133 void StartActivation();
134 // Retried OTASP.
135 void RetryOTASP();
136 // Continues activation process. This method is called after we disconnect
137 // due to detected connectivity issue to kick off reconnection.
138 void ContinueConnecting(int delay);
139
140 // Sends message to host registration page with system/user info data.
141 void SendDeviceInfo();
142
143 // Callback for when |reconnect_timer_| fires.
144 void ReconnectTimerFired();
145 // Starts OTASP process.
146 void StartOTASP();
147 // Checks if we need to reconnect due to failed connection attempt.
148 bool NeedsReconnecting(CellularNetwork* network,
149 PlanActivationState* new_state,
150 std::string* error_description);
151 // Disconnect from network.
152 void DisconnectFromNetwork(CellularNetwork* network);
153 // Connects to cellular network, resets connection timer.
154 bool ConnectToNetwork(CellularNetwork* network, int delay);
155 // Forces disconnect / reconnect when we detect portal connectivity issues.
156 void ForceReconnect(CellularNetwork* network, int delay);
157 // Reports connection timeout.
158 bool ConnectionTimeout();
159 // Verify the state of cellular network and modify internal state.
160 void EvaluateCellularNetwork(CellularNetwork* network);
161 // Check the current cellular network for error conditions.
162 bool GotActivationError(CellularNetwork* network,
163 std::string* error);
164 // Sends status updates to WebUI page.
165 void UpdatePage(CellularNetwork* network,
166 const std::string& error_description);
167 // Changes internal state.
168 void ChangeState(CellularNetwork* network,
169 PlanActivationState new_state,
170 const std::string& error_description);
171 // Prepares network devices for cellular activation process.
172 void SetupActivationProcess(CellularNetwork* network);
173 // Disables ethernet and wifi newtorks since they interefere with
174 // detection of restricted pool on cellular side.
175 void DisableOtherNetworks();
176 // Resets network devices after cellular activation process.
177 // |network| should be NULL if the activation process failed.
178 void CompleteActivation(CellularNetwork* network);
179 // Control routines for handling other types of connections during
180 // cellular activation.
181 void ReEnableOtherConnections();
182 // Return error message for a given code.
183 std::string GetErrorMessage(const std::string& code);
184
185 // Converts the currently active CellularNetwork device into a JS object.
186 static void GetDeviceInfo(CellularNetwork* network,
187 DictionaryValue* value);
188 static bool ShouldReportDeviceState(std::string* state, std::string* error);
189
190 // Performs activation state cellular device evaluation.
191 // Returns false if device activation failed. In this case |error|
192 // will contain error message to be reported to Web UI.
193 static bool EvaluateCellularDeviceState(bool* report_status,
194 std::string* state,
195 std::string* error);
196 // Finds cellular network given device |meid|, reattach network change
197 // observer if |reattach_observer| flag is set.
198 CellularNetwork* FindCellularNetworkByMeid(const std::string& meid,
199 bool reattach_observer);
200
201 // Returns next reconnection state based on the current activation phase.
202 static PlanActivationState GetNextReconnectState(PlanActivationState state);
203 static const char* GetStateDescription(PlanActivationState state);
204
205 scoped_refptr<CellularConfigDocument> cellular_config_;
206 // Internal handler state.
207 PlanActivationState state_;
208 // MEID of cellular device to activate.
209 std::string meid_;
210 // Service path of network begin activated. Please note that the path can
211 // change during the activation process even though it is still representing
212 // the same service.
213 std::string service_path_;
214 // Flags that control if wifi and ethernet connection needs to be restored
215 // after the activation of cellular network.
216 bool reenable_wifi_;
217 bool reenable_ethernet_;
218 bool reenable_cert_check_;
219 bool evaluating_;
220 // True if we think that another tab is already running activation.
221 bool already_running_;
222 // True activation process had been terminated.
223 bool terminated_;
224 // Connection retry counter.
225 int connection_retry_count_;
226 // Post payment reconnect wait counters.
227 int reconnect_wait_count_;
228 // Payment portal reload/reconnect attempt count.
229 int payment_reconnect_count_;
230 // Activation retry attempt count;
231 int activation_attempt_;
232 // Connection start time.
233 base::Time connection_start_time_;
234 // Timer that monitors reconnection timeouts.
235 base::RepeatingTimer<MobileActivator> reconnect_timer_;
236
237 ObserverList<Observer> observers_;
238
239 DISALLOW_COPY_AND_ASSIGN(MobileActivator);
240 };
241
242 } // namespace chromeos
243
244 #endif // CHROME_BROWSER_CHROMEOS_MOBILE_MOBILE_ACTIVATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698