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

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

Powered by Google App Engine
This is Rietveld 408576698