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 #include "chrome/browser/chromeos/mobile/mobile_activator.h" | 5 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "ash/system/chromeos/network/network_connect.h" | 11 #include "ash/system/chromeos/network/network_connect.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
16 #include "base/location.h" | |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/memory/ref_counted_memory.h" | 18 #include "base/memory/ref_counted_memory.h" |
18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
19 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
20 #include "base/observer_list_threadsafe.h" | 21 #include "base/observer_list_threadsafe.h" |
21 #include "base/prefs/pref_service.h" | 22 #include "base/prefs/pref_service.h" |
22 #include "base/strings/string_piece.h" | 23 #include "base/strings/string_piece.h" |
23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
25 #include "base/timer/timer.h" | 26 #include "base/timer/timer.h" |
26 #include "base/values.h" | 27 #include "base/values.h" |
27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
28 #include "chrome/browser/chromeos/cros/network_library.h" | 29 #include "chrome/browser/chromeos/cros/network_library.h" |
stevenjb
2013/08/14 02:28:31
Remove
gauravsh
2013/08/14 21:42:29
Done.
| |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
31 #include "chromeos/network/cros_network_functions.h" | |
stevenjb
2013/08/14 02:28:31
We shouldn't be using this...?
gauravsh
2013/08/14 21:42:29
Yeah, things got whacky when I rebased removed.
| |
32 #include "chromeos/network/device_state.h" | |
33 #include "chromeos/network/network_activation_handler.h" | |
34 #include "chromeos/network/network_configuration_handler.h" | |
35 #include "chromeos/network/network_connection_handler.h" | |
36 #include "chromeos/network/network_handler_callbacks.h" | |
37 #include "chromeos/network/network_state.h" | |
38 #include "chromeos/network/network_state_handler.h" | |
30 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
40 #include "third_party/cros_system_api/dbus/service_constants.h" | |
31 | 41 |
32 using content::BrowserThread; | 42 using content::BrowserThread; |
33 | 43 |
34 namespace { | 44 namespace { |
35 | 45 |
36 // Cellular configuration file path. | 46 // Cellular configuration file path. |
37 const char kCellularConfigPath[] = | 47 const char kCellularConfigPath[] = |
38 "/usr/share/chromeos-assets/mobile/mobile_config.json"; | 48 "/usr/share/chromeos-assets/mobile/mobile_config.json"; |
39 | 49 |
40 // Cellular config file field names. | 50 // Cellular config file field names. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 TerminateActivation(); | 169 TerminateActivation(); |
160 } | 170 } |
161 | 171 |
162 MobileActivator* MobileActivator::GetInstance() { | 172 MobileActivator* MobileActivator::GetInstance() { |
163 return Singleton<MobileActivator>::get(); | 173 return Singleton<MobileActivator>::get(); |
164 } | 174 } |
165 | 175 |
166 void MobileActivator::TerminateActivation() { | 176 void MobileActivator::TerminateActivation() { |
167 // We're exiting; don't continue with termination. | 177 // We're exiting; don't continue with termination. |
168 if (!NetworkLibrary::Get()) | 178 if (!NetworkLibrary::Get()) |
169 return; | 179 return; |
stevenjb
2013/08/14 02:28:31
Remove
gauravsh
2013/08/14 21:42:29
Done.
| |
170 | 180 |
171 state_duration_timer_.Stop(); | 181 state_duration_timer_.Stop(); |
172 continue_reconnect_timer_.Stop(); | 182 continue_reconnect_timer_.Stop(); |
173 reconnect_timeout_timer_.Stop(); | 183 reconnect_timeout_timer_.Stop(); |
174 | 184 |
175 NetworkLibrary* lib = GetNetworkLibrary(); | 185 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
176 lib->RemoveNetworkManagerObserver(this); | 186 FROM_HERE); |
177 lib->RemoveObserverForAllNetworks(this); | |
178 ReEnableCertRevocationChecking(); | 187 ReEnableCertRevocationChecking(); |
179 meid_.clear(); | 188 meid_.clear(); |
180 iccid_.clear(); | 189 iccid_.clear(); |
181 service_path_.clear(); | 190 service_path_.clear(); |
182 state_ = PLAN_ACTIVATION_PAGE_LOADING; | 191 state_ = PLAN_ACTIVATION_PAGE_LOADING; |
183 reenable_cert_check_ = false; | 192 reenable_cert_check_ = false; |
184 terminated_ = true; | 193 terminated_ = true; |
185 // Release the previous cellular config and setup a new empty one. | 194 // Release the previous cellular config and setup a new empty one. |
186 cellular_config_ = new CellularConfigDocument(); | 195 cellular_config_ = new CellularConfigDocument(); |
187 } | 196 } |
188 | 197 |
189 void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) { | 198 void MobileActivator::NetworkManagerChanged() { |
stevenjb
2013/08/14 02:28:31
We should rename this, something like RefreshCellu
gauravsh
2013/08/14 21:42:29
Not sure I understand. This is an observer overrid
stevenjb
2013/08/14 21:58:35
Oh, right. I don't think we need to observe that h
gauravsh
2013/08/15 01:46:35
Ok, so are you saying we should get rid of the Net
stevenjb
2013/08/15 02:00:10
I certainly wasn't suggesting changing all of them
| |
190 if (state_ == PLAN_ACTIVATION_PAGE_LOADING || | 199 if (state_ == PLAN_ACTIVATION_PAGE_LOADING || |
191 state_ == PLAN_ACTIVATION_DONE || | 200 state_ == PLAN_ACTIVATION_DONE || |
192 state_ == PLAN_ACTIVATION_ERROR) { | 201 state_ == PLAN_ACTIVATION_ERROR) { |
193 return; | 202 return; |
194 } | 203 } |
195 | 204 |
196 CellularNetwork* network = FindMatchingCellularNetwork(true); | 205 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); |
197 if (network && network->activate_over_non_cellular_network()) { | 206 const NetworkState* network = FindMatchingCellularNetwork(true); |
207 if (network && network->activate_over_non_cellular_networks()) { | |
198 bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION); | 208 bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION); |
199 bool is_online = | 209 bool is_online = nsh->DefaultNetwork() && |
200 cros->connected_network() && cros->connected_network()->online(); | 210 nsh->DefaultNetwork()->connection_state() == flimflam::kStateOnline; |
201 if (waiting && is_online) { | 211 if (waiting && is_online) { |
202 ChangeState(network, post_reconnect_state_, ""); | 212 ChangeState(network, post_reconnect_state_, ""); |
203 } else if (!waiting && !is_online) { | 213 } else if (!waiting && !is_online) { |
204 ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, ""); | 214 ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, ""); |
205 } | 215 } |
206 } | 216 } |
207 | 217 |
208 EvaluateCellularNetwork(network); | 218 EvaluateCellularNetwork(network); |
209 } | 219 } |
210 | 220 |
211 void MobileActivator::OnNetworkChanged(NetworkLibrary* cros, | 221 void MobileActivator::DefaultNetworkChanged(const NetworkState* network) { |
212 const Network* network) { | 222 NetworkManagerChanged(); |
223 } | |
224 | |
225 void MobileActivator::NetworkPropertiesUpdated(const NetworkState* network) { | |
213 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 226 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
214 return; | 227 return; |
215 | 228 |
216 if (!network || network->type() != TYPE_CELLULAR) { | 229 if (!network || |
217 NOTREACHED(); | 230 network->type() != flimflam::kTypeCellular || |
231 network->path() != service_path_) { | |
armansito
2013/08/14 00:49:51
I guess the original code expected this to never h
gauravsh
2013/08/14 21:42:29
Done.
| |
218 return; | 232 return; |
219 } | 233 } |
220 | 234 |
221 EvaluateCellularNetwork( | 235 EvaluateCellularNetwork(network); |
222 static_cast<CellularNetwork*>(const_cast<Network*>(network))); | |
223 } | 236 } |
224 | 237 |
225 void MobileActivator::AddObserver(MobileActivator::Observer* observer) { | 238 void MobileActivator::AddObserver(MobileActivator::Observer* observer) { |
226 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); | 239 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); |
227 observers_.AddObserver(observer); | 240 observers_.AddObserver(observer); |
228 } | 241 } |
229 | 242 |
230 void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) { | 243 void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) { |
231 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); | 244 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); |
232 observers_.RemoveObserver(observer); | 245 observers_.RemoveObserver(observer); |
233 } | 246 } |
234 | 247 |
235 void MobileActivator::InitiateActivation(const std::string& service_path) { | 248 void MobileActivator::InitiateActivation(const std::string& service_path) { |
236 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); | 249 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); |
237 NetworkLibrary* lib = GetNetworkLibrary(); | 250 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
238 CellularNetwork* network = lib->FindCellularNetworkByPath(service_path); | 251 GetNetworkState(service_path); |
239 if (!network) { | 252 if (!network) { |
240 LOG(ERROR) << "Cellular service can't be found: " << service_path; | 253 LOG(ERROR) << "Cellular service can't be found: " << service_path; |
241 return; | 254 return; |
242 } | 255 } |
243 | 256 |
244 const chromeos::NetworkDevice* device = | 257 const DeviceState* device = NetworkHandler::Get()->network_state_handler()-> |
245 lib->FindNetworkDeviceByPath(network->device_path()); | 258 GetDeviceState(network->device_path()); |
246 if (!device) { | 259 if (!device) { |
247 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); | 260 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); |
248 return; | 261 return; |
249 } | 262 } |
250 | 263 |
251 terminated_ = false; | 264 terminated_ = false; |
252 meid_ = device->meid(); | 265 meid_ = device->meid(); |
253 iccid_ = device->iccid(); | 266 iccid_ = device->iccid(); |
254 service_path_ = service_path; | 267 service_path_ = service_path; |
255 | 268 |
256 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, ""); | 269 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, ""); |
257 | 270 |
258 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 271 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
259 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, | 272 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, |
260 cellular_config_.get()), | 273 cellular_config_.get()), |
261 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); | 274 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); |
262 } | 275 } |
263 | 276 |
264 void MobileActivator::ContinueActivation() { | 277 void MobileActivator::ContinueActivation() { |
265 CellularNetwork* network = FindMatchingCellularNetwork(false); | 278 const NetworkState* network = FindMatchingCellularNetwork(false); |
stevenjb
2013/08/14 02:28:31
We should really just use service_path_ here I thi
gauravsh
2013/08/14 21:42:29
Yeah, I don't think we need FindMatchingCellularNe
| |
266 if (!network || !network->SupportsActivation()) | 279 if (!network || |
280 (network->payment_url().empty() && network->usage_url().empty())) | |
267 return; | 281 return; |
268 | 282 |
269 DisableCertRevocationChecking(); | 283 DisableCertRevocationChecking(); |
270 // We want shill to connect us after activations. | |
271 network->SetAutoConnect(true); | |
272 | 284 |
285 // We want shill to connect us after activations, so enable autoconnect. | |
286 DictionaryValue auto_connect_property; | |
287 auto_connect_property.SetBoolean(flimflam::kAutoConnectProperty, true); | |
288 NetworkHandler::Get()->network_configuration_handler()->SetProperties( | |
289 network->path(), | |
290 auto_connect_property, | |
291 base::Bind(&base::DoNothing), | |
292 network_handler::ErrorCallback()); | |
273 StartActivation(); | 293 StartActivation(); |
274 } | 294 } |
275 | 295 |
276 void MobileActivator::OnSetTransactionStatus(bool success) { | 296 void MobileActivator::OnSetTransactionStatus(bool success) { |
277 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 297 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
278 base::Bind(&MobileActivator::HandleSetTransactionStatus, | 298 base::Bind(&MobileActivator::HandleSetTransactionStatus, |
279 AsWeakPtr(), success)); | 299 AsWeakPtr(), success)); |
280 } | 300 } |
281 | 301 |
282 void MobileActivator::HandleSetTransactionStatus(bool success) { | 302 void MobileActivator::HandleSetTransactionStatus(bool success) { |
283 // The payment is received, try to reconnect and check the status all over | 303 // The payment is received, try to reconnect and check the status all over |
284 // again. | 304 // again. |
285 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 305 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
286 NetworkLibrary* lib = GetNetworkLibrary(); | 306 SignalCellularPlanPayment(); |
287 lib->SignalCellularPlanPayment(); | |
288 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); | 307 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); |
289 CellularNetwork* network = FindMatchingCellularNetwork(true); | 308 const NetworkState* network = FindMatchingCellularNetwork(true); |
stevenjb
2013/08/14 02:28:31
Seems like we should also use service_path_ here.
gauravsh
2013/08/14 21:42:29
Done.
| |
290 if (network && network->activate_over_non_cellular_network()) { | 309 if (network && network->activate_over_non_cellular_networks()) { |
291 state_ = PLAN_ACTIVATION_DONE; | 310 state_ = PLAN_ACTIVATION_DONE; |
292 network->CompleteActivation(); | 311 NetworkHandler::Get()->network_activation_handler()-> |
312 CompleteActivation(network->path(), | |
313 base::Bind(&base::DoNothing), | |
314 network_handler::ErrorCallback()); | |
293 } else { | 315 } else { |
294 StartOTASP(); | 316 StartOTASP(); |
295 } | 317 } |
296 } else { | 318 } else { |
297 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); | 319 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); |
298 } | 320 } |
299 } | 321 } |
300 | 322 |
301 void MobileActivator::OnPortalLoaded(bool success) { | 323 void MobileActivator::OnPortalLoaded(bool success) { |
302 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 324 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
303 base::Bind(&MobileActivator::HandlePortalLoaded, | 325 base::Bind(&MobileActivator::HandlePortalLoaded, |
304 AsWeakPtr(), success)); | 326 AsWeakPtr(), success)); |
305 } | 327 } |
306 | 328 |
307 void MobileActivator::HandlePortalLoaded(bool success) { | 329 void MobileActivator::HandlePortalLoaded(bool success) { |
308 CellularNetwork* network = FindMatchingCellularNetwork(true); | 330 const NetworkState* network = FindMatchingCellularNetwork(true); |
stevenjb
2013/08/14 02:28:31
Use service_path_?
gauravsh
2013/08/14 21:42:29
Done.
| |
309 if (!network) { | 331 if (!network) { |
310 ChangeState(NULL, PLAN_ACTIVATION_ERROR, | 332 ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
311 GetErrorMessage(kErrorNoService)); | 333 GetErrorMessage(kErrorNoService)); |
312 return; | 334 return; |
313 } | 335 } |
314 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || | 336 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || |
315 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 337 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
316 if (success) { | 338 if (success) { |
317 payment_reconnect_count_ = 0; | 339 payment_reconnect_count_ = 0; |
318 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); | 340 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); |
319 } else { | 341 } else { |
320 // There is no point in forcing reconnecting the cellular network if the | 342 // There is no point in forcing reconnecting the cellular network if the |
321 // activation should not be done over it. | 343 // activation should not be done over it. |
322 if (network->activate_over_non_cellular_network()) | 344 if (network->activate_over_non_cellular_networks()) |
323 return; | 345 return; |
324 | 346 |
325 payment_reconnect_count_++; | 347 payment_reconnect_count_++; |
326 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { | 348 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { |
327 ChangeState(NULL, PLAN_ACTIVATION_ERROR, | 349 ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
328 GetErrorMessage(kErrorNoService)); | 350 GetErrorMessage(kErrorNoService)); |
329 return; | 351 return; |
330 } | 352 } |
331 | 353 |
332 // Reconnect and try and load the frame again. | 354 // Reconnect and try and load the frame again. |
333 ChangeState(network, | 355 ChangeState(network, |
334 PLAN_ACTIVATION_RECONNECTING, | 356 PLAN_ACTIVATION_RECONNECTING, |
335 GetErrorMessage(kFailedPaymentError)); | 357 GetErrorMessage(kFailedPaymentError)); |
336 } | 358 } |
337 } else { | 359 } else { |
338 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: " | 360 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: " |
339 << GetStateDescription(state_); | 361 << GetStateDescription(state_); |
340 } | 362 } |
341 } | 363 } |
342 | 364 |
343 CellularNetwork* MobileActivator::FindMatchingCellularNetwork( | 365 const NetworkState* MobileActivator::FindMatchingCellularNetwork( |
344 bool reattach_observer) { | 366 bool reattach_observer) { |
stevenjb
2013/08/14 02:28:31
I don't think we need this argument.
gauravsh
2013/08/14 21:42:29
Done.
| |
345 NetworkLibrary* lib = GetNetworkLibrary(); | 367 NetworkStateHandler::NetworkStateList list; |
346 for (CellularNetworkVector::const_iterator it = | 368 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); |
347 lib->cellular_networks().begin(); | 369 nsh->GetNetworkListByType(flimflam::kTypeCellular, &list); |
348 it != lib->cellular_networks().end(); ++it) { | 370 for (NetworkStateHandler::NetworkStateList::const_iterator it = list.begin(); |
349 const chromeos::NetworkDevice* device = | 371 it != list.end(); ++it) { |
350 lib->FindNetworkDeviceByPath((*it)->device_path()); | 372 const DeviceState* device = nsh->GetDeviceState((*it)->device_path()); |
351 if (device && ((!meid_.empty() && meid_ == device->meid()) || | 373 if (device && ((!meid_.empty() && meid_ == device->meid()) || |
352 (!iccid_.empty() && iccid_ == device->iccid()))) { | 374 (!iccid_.empty() && iccid_ == device->iccid()))) { |
353 CellularNetwork* network = *it; | 375 const NetworkState* network = *it; |
354 // If service path has changed, reattach the event observer for this | 376 // If service path has changed, update it, so we correctly process |
355 // network service. | 377 // property updates for the network. |
356 if (reattach_observer && service_path_ != network->service_path()) { | 378 if (reattach_observer && service_path_ != network->path()) |
357 lib->RemoveObserverForAllNetworks(this); | 379 service_path_ = network->path(); |
358 lib->AddNetworkObserver(network->service_path(), this); | |
359 service_path_ = network->service_path(); | |
360 } | |
361 return network; | 380 return network; |
362 } | 381 } |
363 } | 382 } |
364 return NULL; | 383 return NULL; |
365 } | 384 } |
366 | 385 |
367 void MobileActivator::StartOTASPTimer() { | 386 void MobileActivator::StartOTASPTimer() { |
368 state_duration_timer_.Start( | 387 state_duration_timer_.Start( |
369 FROM_HERE, | 388 FROM_HERE, |
370 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay), | 389 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay), |
371 this, &MobileActivator::HandleOTASPTimeout); | 390 this, &MobileActivator::HandleOTASPTimeout); |
372 } | 391 } |
373 | 392 |
374 void MobileActivator::StartActivation() { | 393 void MobileActivator::StartActivation() { |
375 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); | 394 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); |
376 NetworkLibrary* lib = GetNetworkLibrary(); | 395 const NetworkState* network = FindMatchingCellularNetwork(true); |
377 CellularNetwork* network = FindMatchingCellularNetwork(true); | |
378 // Check if we can start activation process. | 396 // Check if we can start activation process. |
379 if (!network) { | 397 if (!network) { |
398 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); | |
380 std::string error; | 399 std::string error; |
381 if (!lib->cellular_available()) | 400 if (nsh->GetTechnologyState(flimflam::kTypeCellular) == |
stevenjb
2013/08/14 02:28:31
nit: local for technology_state
gauravsh
2013/08/14 21:42:29
Done.
| |
401 NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) { | |
382 error = kErrorNoDevice; | 402 error = kErrorNoDevice; |
383 else if (!lib->cellular_enabled()) | 403 } else if (nsh->GetTechnologyState(flimflam::kTypeCellular) != |
404 NetworkStateHandler::TECHNOLOGY_ENABLED) { | |
384 error = kErrorDisabled; | 405 error = kErrorDisabled; |
385 else | 406 } else { |
386 error = kErrorNoService; | 407 error = kErrorNoService; |
408 } | |
387 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); | 409 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); |
388 return; | 410 return; |
389 } | 411 } |
390 | 412 |
391 // Start monitoring network property changes. | 413 // Start monitoring network property changes. |
392 lib->AddNetworkManagerObserver(this); | 414 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); |
393 if (network->activate_over_non_cellular_network()) { | 415 if (network->activate_over_non_cellular_networks()) { |
394 // Fast forward to payment portal loading if the activation is performed | 416 // Fast forward to payment portal loading if the activation is performed |
395 // over a non-cellular network. | 417 // over a non-cellular network. |
396 ChangeState(network, | 418 ChangeState( |
397 (network->activation_state() == ACTIVATION_STATE_ACTIVATED) ? | 419 network, |
398 PLAN_ACTIVATION_DONE : | 420 (network->activation_state() == flimflam::kActivationStateActivated) ? |
399 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, | 421 PLAN_ACTIVATION_DONE : |
400 ""); | 422 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, |
423 ""); | |
401 // Verify that there is no need to wait for the connection. This will also | 424 // Verify that there is no need to wait for the connection. This will also |
402 // evaluate the network. | 425 // evaluate the network. |
403 OnNetworkManagerChanged(lib); | 426 NetworkManagerChanged(); |
404 return; | 427 return; |
405 } | 428 } |
406 | 429 |
407 if (lib->HasRecentCellularPlanPayment() && | 430 if (HasRecentCellularPlanPayment() && |
408 network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | 431 (network->activation_state() == |
432 flimflam::kActivationStatePartiallyActivated)) { | |
409 // Try to start with OTASP immediately if we have received payment recently. | 433 // Try to start with OTASP immediately if we have received payment recently. |
410 state_ = PLAN_ACTIVATION_START_OTASP; | 434 state_ = PLAN_ACTIVATION_START_OTASP; |
411 } else { | 435 } else { |
412 state_ = PLAN_ACTIVATION_START; | 436 state_ = PLAN_ACTIVATION_START; |
413 } | 437 } |
414 | 438 |
415 EvaluateCellularNetwork(network); | 439 EvaluateCellularNetwork(network); |
416 } | 440 } |
417 | 441 |
418 void MobileActivator::RetryOTASP() { | 442 void MobileActivator::RetryOTASP() { |
419 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP); | 443 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP); |
420 StartOTASP(); | 444 StartOTASP(); |
421 } | 445 } |
422 | 446 |
423 void MobileActivator::StartOTASP() { | 447 void MobileActivator::StartOTASP() { |
424 CellularNetwork* network = FindMatchingCellularNetwork(true); | 448 const NetworkState* network = FindMatchingCellularNetwork(true); |
stevenjb
2013/08/14 02:28:31
Use service_path_?
gauravsh
2013/08/14 21:42:29
Done.
| |
425 ChangeState(network, PLAN_ACTIVATION_START_OTASP, std::string()); | 449 ChangeState(network, PLAN_ACTIVATION_START_OTASP, std::string()); |
426 EvaluateCellularNetwork(network); | 450 EvaluateCellularNetwork(network); |
427 } | 451 } |
428 | 452 |
429 void MobileActivator::HandleOTASPTimeout() { | 453 void MobileActivator::HandleOTASPTimeout() { |
430 LOG(WARNING) << "OTASP seems to be taking too long."; | 454 LOG(WARNING) << "OTASP seems to be taking too long."; |
431 CellularNetwork* network = FindMatchingCellularNetwork(true); | 455 const NetworkState* network = FindMatchingCellularNetwork(true); |
stevenjb
2013/08/14 02:28:31
Use service_path_?
gauravsh
2013/08/14 21:42:29
Done.
| |
432 // We're here because one of OTASP steps is taking too long to complete. | 456 // We're here because one of OTASP steps is taking too long to complete. |
433 // Usually, this means something bad has happened below us. | 457 // Usually, this means something bad has happened below us. |
434 if (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION) { | 458 if (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION) { |
435 ++initial_OTASP_attempts_; | 459 ++initial_OTASP_attempts_; |
436 if (initial_OTASP_attempts_ <= kMaxOTASPTries) { | 460 if (initial_OTASP_attempts_ <= kMaxOTASPTries) { |
437 ChangeState(network, | 461 ChangeState(network, |
438 PLAN_ACTIVATION_RECONNECTING, | 462 PLAN_ACTIVATION_RECONNECTING, |
439 GetErrorMessage(kErrorDefault)); | 463 GetErrorMessage(kErrorDefault)); |
440 return; | 464 return; |
441 } | 465 } |
(...skipping 16 matching lines...) Expand all Loading... | |
458 } | 482 } |
459 } else { | 483 } else { |
460 LOG(ERROR) << "OTASP timed out from a non-OTASP wait state?"; | 484 LOG(ERROR) << "OTASP timed out from a non-OTASP wait state?"; |
461 } | 485 } |
462 LOG(ERROR) << "OTASP failed too many times; aborting."; | 486 LOG(ERROR) << "OTASP failed too many times; aborting."; |
463 ChangeState(network, | 487 ChangeState(network, |
464 PLAN_ACTIVATION_ERROR, | 488 PLAN_ACTIVATION_ERROR, |
465 GetErrorMessage(kErrorDefault)); | 489 GetErrorMessage(kErrorDefault)); |
466 } | 490 } |
467 | 491 |
468 void MobileActivator::ForceReconnect(CellularNetwork* network, | 492 void MobileActivator::ForceReconnect(const NetworkState* network, |
469 PlanActivationState next_state) { | 493 PlanActivationState next_state) { |
470 DCHECK(network); | 494 DCHECK(network); |
471 // Store away our next destination for when we complete. | 495 // Store away our next destination for when we complete. |
472 post_reconnect_state_ = next_state; | 496 post_reconnect_state_ = next_state; |
473 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); | 497 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); |
474 // First, disconnect... | 498 // First, disconnect... |
475 LOG(INFO) << "Disconnecting from " << network->service_path(); | 499 LOG(INFO) << "Disconnecting from " << network->path(); |
476 // Explicit service Disconnect()s disable autoconnect on the service until | 500 // Explicit service Disconnect()s disable autoconnect on the service until |
477 // Connect() is called on the service again. Hence this dance to explicitly | 501 // Connect() is called on the service again. Hence this dance to explicitly |
478 // call Connect(). | 502 // call Connect(). |
479 GetNetworkLibrary()->DisconnectFromNetwork(network); | 503 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( |
504 network->path(), | |
505 base::Bind(&base::DoNothing), | |
506 network_handler::ErrorCallback()); | |
480 // Keep trying to connect until told otherwise. | 507 // Keep trying to connect until told otherwise. |
481 continue_reconnect_timer_.Stop(); | 508 continue_reconnect_timer_.Stop(); |
482 continue_reconnect_timer_.Start( | 509 continue_reconnect_timer_.Start( |
483 FROM_HERE, | 510 FROM_HERE, |
484 base::TimeDelta::FromMilliseconds(kReconnectDelayMS), | 511 base::TimeDelta::FromMilliseconds(kReconnectDelayMS), |
485 this, &MobileActivator::ContinueConnecting); | 512 this, &MobileActivator::ContinueConnecting); |
486 // If we don't ever connect again, we're going to call this a failure. | 513 // If we don't ever connect again, we're going to call this a failure. |
487 reconnect_timeout_timer_.Stop(); | 514 reconnect_timeout_timer_.Stop(); |
488 reconnect_timeout_timer_.Start( | 515 reconnect_timeout_timer_.Start( |
489 FROM_HERE, | 516 FROM_HERE, |
490 base::TimeDelta::FromMilliseconds(kMaxReconnectTime), | 517 base::TimeDelta::FromMilliseconds(kMaxReconnectTime), |
491 this, &MobileActivator::ReconnectTimedOut); | 518 this, &MobileActivator::ReconnectTimedOut); |
492 } | 519 } |
493 | 520 |
494 void MobileActivator::ReconnectTimedOut() { | 521 void MobileActivator::ReconnectTimedOut() { |
495 LOG(ERROR) << "Ending activation attempt after failing to reconnect."; | 522 LOG(ERROR) << "Ending activation attempt after failing to reconnect."; |
496 ChangeState(FindMatchingCellularNetwork(true), | 523 ChangeState(FindMatchingCellularNetwork(true), |
stevenjb
2013/08/14 02:28:31
Use service_path_?
gauravsh
2013/08/14 21:42:29
Done.
| |
497 PLAN_ACTIVATION_ERROR, | 524 PLAN_ACTIVATION_ERROR, |
498 GetErrorMessage(kFailedConnectivity)); | 525 GetErrorMessage(kFailedConnectivity)); |
499 } | 526 } |
500 | 527 |
501 void MobileActivator::ContinueConnecting() { | 528 void MobileActivator::ContinueConnecting() { |
502 CellularNetwork* network = FindMatchingCellularNetwork(true); | 529 const NetworkState* network = FindMatchingCellularNetwork(true); |
stevenjb
2013/08/14 02:28:31
Use service_path_?
gauravsh
2013/08/14 21:42:29
Done.
| |
503 if (network && network->connected()) { | 530 if (network && network->IsConnectedState()) { |
504 if (network->restricted_pool() && | 531 if (network->connection_state() == flimflam::kStatePortal && |
505 network->error() == ERROR_DNS_LOOKUP_FAILED) { | 532 network->error() == flimflam::kErrorDNSLookupFailed) { |
506 // It isn't an error to be in a restricted pool, but if DNS doesn't work, | 533 // It isn't an error to be in a restricted pool, but if DNS doesn't work, |
507 // then we're not getting traffic through at all. Just disconnect and | 534 // then we're not getting traffic through at all. Just disconnect and |
508 // try again. | 535 // try again. |
509 GetNetworkLibrary()->DisconnectFromNetwork(network); | 536 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( |
537 network->path(), | |
538 base::Bind(&base::DoNothing), | |
539 network_handler::ErrorCallback()); | |
510 return; | 540 return; |
511 } | 541 } |
512 // Stop this callback | 542 // Stop this callback |
513 continue_reconnect_timer_.Stop(); | 543 continue_reconnect_timer_.Stop(); |
514 EvaluateCellularNetwork(network); | 544 EvaluateCellularNetwork(network); |
515 } else { | 545 } else { |
516 LOG(WARNING) << "Connect failed, will try again in a little bit."; | 546 LOG(WARNING) << "Connect failed, will try again in a little bit."; |
517 if (network) { | 547 if (network) { |
518 LOG(INFO) << "Connecting to: " << network->service_path(); | 548 LOG(INFO) << "Connecting to: " << network->path(); |
519 ash::network_connect::ConnectToNetwork( | 549 ash::network_connect::ConnectToNetwork( |
520 network->service_path(), NULL /* no parent window */); | 550 network->path(), NULL /* no parent window */); |
521 } | 551 } |
522 } | 552 } |
523 } | 553 } |
524 | 554 |
525 void MobileActivator::EvaluateCellularNetwork(CellularNetwork* network) { | 555 void MobileActivator::EvaluateCellularNetwork(const NetworkState* network) { |
526 if (terminated_) { | 556 if (terminated_) { |
527 LOG(ERROR) << "Tried to run MobileActivator state machine while " | 557 LOG(ERROR) << "Tried to run MobileActivator state machine while " |
528 << "terminated."; | 558 << "terminated."; |
529 return; | 559 return; |
530 } | 560 } |
531 | 561 |
532 if (!network) { | 562 if (!network) { |
533 LOG(WARNING) << "Cellular service lost"; | 563 LOG(WARNING) << "Cellular service lost"; |
534 return; | 564 return; |
535 } | 565 } |
536 | 566 |
537 LOG(WARNING) << "Cellular:\n service=" << network->GetStateString() | 567 LOG(WARNING) << "Cellular:\n service state=" << network->connection_state() |
538 << "\n ui=" << GetStateDescription(state_) | 568 << "\n ui=" << GetStateDescription(state_) |
539 << "\n activation=" << network->GetActivationStateString() | 569 << "\n activation=" << network->activation_state() |
540 << "\n error=" << network->GetErrorString() | 570 << "\n error=" << network->error() |
541 << "\n setvice_path=" << network->service_path() | 571 << "\n setvice_path=" << network->path() |
542 << "\n connected=" << network->connected(); | 572 << "\n connected=" << network->IsConnectedState(); |
543 | 573 |
544 // If the network is activated over non cellular network, the activator state | 574 // If the network is activated over non cellular network, the activator state |
545 // does not depend on the network's own state. | 575 // does not depend on the network's own state. |
546 if (network->activate_over_non_cellular_network()) | 576 if (network->activate_over_non_cellular_networks()) |
547 return; | 577 return; |
548 | 578 |
549 std::string error_description; | 579 std::string error_description; |
550 PlanActivationState new_state = PickNextState(network, &error_description); | 580 PlanActivationState new_state = PickNextState(network, &error_description); |
551 | 581 |
552 ChangeState(network, new_state, error_description); | 582 ChangeState(network, new_state, error_description); |
553 } | 583 } |
554 | 584 |
555 MobileActivator::PlanActivationState MobileActivator::PickNextState( | 585 MobileActivator::PlanActivationState MobileActivator::PickNextState( |
556 CellularNetwork* network, std::string* error_description) const { | 586 const NetworkState* network, std::string* error_description) const { |
557 PlanActivationState new_state = state_; | 587 PlanActivationState new_state = state_; |
558 if (!network->connected()) | 588 if (!network->IsConnectedState()) |
559 new_state = PickNextOfflineState(network); | 589 new_state = PickNextOfflineState(network); |
560 else | 590 else |
561 new_state = PickNextOnlineState(network); | 591 new_state = PickNextOnlineState(network); |
562 if (new_state != PLAN_ACTIVATION_ERROR && | 592 if (new_state != PLAN_ACTIVATION_ERROR && |
563 GotActivationError(network, error_description)) { | 593 GotActivationError(network, error_description)) { |
564 // Check for this special case when we try to do activate partially | 594 // Check for this special case when we try to do activate partially |
565 // activated device. If that attempt failed, try to disconnect to clear the | 595 // activated device. If that attempt failed, try to disconnect to clear the |
566 // state and reconnect again. | 596 // state and reconnect again. |
567 if ((network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED || | 597 const std::string& activation = network->activation_state(); |
568 network->activation_state() == ACTIVATION_STATE_ACTIVATING) && | 598 bool is_partially_activated = |
569 (network->error() == ERROR_NO_ERROR || | 599 activation == flimflam::kActivationStatePartiallyActivated || |
570 network->error() == ERROR_OTASP_FAILED) && | 600 activation == flimflam::kActivationStateActivating; |
571 network->state() == STATE_ACTIVATION_FAILURE) { | 601 if (is_partially_activated && |
572 LOG(WARNING) << "Activation failure detected " | 602 (network->error().empty() || |
573 << network->service_path(); | 603 network->error() == flimflam::kErrorOtaspFailed) && |
604 network->connection_state() == flimflam::kStateActivationFailure) { | |
605 LOG(WARNING) << "Activation failure detected " << network->path(); | |
574 switch (state_) { | 606 switch (state_) { |
575 case PLAN_ACTIVATION_OTASP: | 607 case PLAN_ACTIVATION_OTASP: |
576 new_state = PLAN_ACTIVATION_DELAY_OTASP; | 608 new_state = PLAN_ACTIVATION_DELAY_OTASP; |
577 break; | 609 break; |
578 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 610 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
579 case PLAN_ACTIVATION_TRYING_OTASP: | 611 case PLAN_ACTIVATION_TRYING_OTASP: |
580 new_state = PLAN_ACTIVATION_START; | 612 new_state = PLAN_ACTIVATION_START; |
581 break; | 613 break; |
582 case PLAN_ACTIVATION_START: | 614 case PLAN_ACTIVATION_START: |
583 // We are just starting, so this must be previous activation attempt | 615 // We are just starting, so this must be previous activation attempt |
584 // failure. | 616 // failure. |
585 new_state = PLAN_ACTIVATION_TRYING_OTASP; | 617 new_state = PLAN_ACTIVATION_TRYING_OTASP; |
586 break; | 618 break; |
587 case PLAN_ACTIVATION_DELAY_OTASP: | 619 case PLAN_ACTIVATION_DELAY_OTASP: |
588 new_state = state_; | 620 new_state = state_; |
589 break; | 621 break; |
590 default: | 622 default: |
591 new_state = PLAN_ACTIVATION_ERROR; | 623 new_state = PLAN_ACTIVATION_ERROR; |
592 break; | 624 break; |
593 } | 625 } |
594 } else { | 626 } else { |
595 LOG(WARNING) << "Unexpected activation failure for " | 627 LOG(WARNING) << "Unexpected activation failure for " << network->path(); |
596 << network->service_path(); | |
597 new_state = PLAN_ACTIVATION_ERROR; | 628 new_state = PLAN_ACTIVATION_ERROR; |
598 } | 629 } |
599 } | 630 } |
600 | 631 |
601 if (new_state == PLAN_ACTIVATION_ERROR && !error_description->length()) | 632 if (new_state == PLAN_ACTIVATION_ERROR && !error_description->length()) |
602 *error_description = GetErrorMessage(kErrorDefault); | 633 *error_description = GetErrorMessage(kErrorDefault); |
603 return new_state; | 634 return new_state; |
604 } | 635 } |
605 | 636 |
606 MobileActivator::PlanActivationState MobileActivator::PickNextOfflineState( | 637 MobileActivator::PlanActivationState MobileActivator::PickNextOfflineState( |
607 CellularNetwork* network) const { | 638 const NetworkState* network) const { |
608 PlanActivationState new_state = state_; | 639 PlanActivationState new_state = state_; |
640 const std::string& activation = network->activation_state(); | |
609 switch (state_) { | 641 switch (state_) { |
610 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 642 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
611 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 643 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
612 if (!network->activate_over_non_cellular_network()) | 644 if (!network->activate_over_non_cellular_networks()) |
613 new_state = PLAN_ACTIVATION_RECONNECTING; | 645 new_state = PLAN_ACTIVATION_RECONNECTING; |
614 break; | 646 break; |
615 case PLAN_ACTIVATION_START: | 647 case PLAN_ACTIVATION_START: |
616 switch (network->activation_state()) { | 648 if (activation == flimflam::kActivationStateActivated) { |
617 case ACTIVATION_STATE_ACTIVATED: | 649 if (network->connection_state() == flimflam::kStatePortal) |
618 if (network->restricted_pool()) | 650 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
619 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 651 else |
620 else | 652 new_state = PLAN_ACTIVATION_DONE; |
621 new_state = PLAN_ACTIVATION_DONE; | 653 } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
622 break; | 654 new_state = PLAN_ACTIVATION_TRYING_OTASP; |
623 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 655 } else { |
624 new_state = PLAN_ACTIVATION_TRYING_OTASP; | 656 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
625 break; | |
626 default: | |
627 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; | |
628 break; | |
629 } | 657 } |
630 break; | 658 break; |
631 default: { | 659 default: |
632 LOG(INFO) << "Waiting for cellular service to connect."; | 660 LOG(INFO) << "Waiting for cellular service to connect."; |
633 } break; | 661 break; |
634 } | 662 } |
635 return new_state; | 663 return new_state; |
636 } | 664 } |
637 | 665 |
638 MobileActivator::PlanActivationState MobileActivator::PickNextOnlineState( | 666 MobileActivator::PlanActivationState MobileActivator::PickNextOnlineState( |
639 CellularNetwork* network) const { | 667 const NetworkState* network) const { |
640 PlanActivationState new_state = state_; | 668 PlanActivationState new_state = state_; |
669 const std::string& activation = network->activation_state(); | |
641 switch (state_) { | 670 switch (state_) { |
642 case PLAN_ACTIVATION_START: | 671 case PLAN_ACTIVATION_START: |
643 switch (network->activation_state()) { | 672 if (activation == flimflam::kActivationStateActivated) { |
644 case ACTIVATION_STATE_ACTIVATED: | 673 if (network->connection_state() == flimflam::kStatePortal) |
645 if (network->restricted_pool()) | 674 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
646 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 675 else |
647 else | 676 new_state = PLAN_ACTIVATION_DONE; |
648 new_state = PLAN_ACTIVATION_DONE; | 677 } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
649 break; | 678 new_state = PLAN_ACTIVATION_TRYING_OTASP; |
650 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 679 } else { |
651 new_state = PLAN_ACTIVATION_TRYING_OTASP; | 680 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
652 break; | |
653 default: | |
654 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; | |
655 break; | |
656 } | 681 } |
657 break; | 682 break; |
658 case PLAN_ACTIVATION_START_OTASP: { | 683 case PLAN_ACTIVATION_START_OTASP: { |
659 switch (network->activation_state()) { | 684 if (activation == flimflam::kActivationStatePartiallyActivated) { |
660 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | |
661 new_state = PLAN_ACTIVATION_OTASP; | 685 new_state = PLAN_ACTIVATION_OTASP; |
662 break; | 686 } else if (activation == flimflam::kActivationStateActivated) { |
663 case ACTIVATION_STATE_ACTIVATED: | 687 new_state = PLAN_ACTIVATION_RECONNECTING; |
664 new_state = PLAN_ACTIVATION_RECONNECTING; | 688 } else { |
665 break; | 689 LOG(WARNING) << "Unexpected activation state for device " |
666 default: { | 690 << network->path(); |
667 LOG(WARNING) << "Unexpected activation state for device " | |
668 << network->service_path(); | |
669 break; | |
670 } | |
671 } | 691 } |
672 break; | 692 break; |
673 } | 693 } |
674 case PLAN_ACTIVATION_DELAY_OTASP: | 694 case PLAN_ACTIVATION_DELAY_OTASP: |
675 // Just ignore any changes until the OTASP retry timer kicks in. | 695 // Just ignore any changes until the OTASP retry timer kicks in. |
676 break; | 696 break; |
677 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { | 697 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { |
678 switch (network->activation_state()) { | 698 if (activation == flimflam::kActivationStateActivated || |
679 case ACTIVATION_STATE_ACTIVATED: | 699 activation == flimflam::kActivationStatePartiallyActivated) { |
680 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 700 new_state = PLAN_ACTIVATION_START; |
681 new_state = PLAN_ACTIVATION_START; | 701 } else if (activation == flimflam::kActivationStateNotActivated || |
682 break; | 702 activation == flimflam::kActivationStateActivating) { |
683 case ACTIVATION_STATE_NOT_ACTIVATED: | 703 // Wait in this state until activation state changes. |
684 case ACTIVATION_STATE_ACTIVATING: | 704 } else { |
685 // Wait in this state until activation state changes. | 705 LOG(WARNING) << "Unknown transition"; |
686 break; | |
687 default: | |
688 LOG(WARNING) << "Unknown transition"; | |
689 break; | |
690 } | 706 } |
691 break; | 707 break; |
692 } | 708 } |
693 case PLAN_ACTIVATION_OTASP: | 709 case PLAN_ACTIVATION_OTASP: |
694 case PLAN_ACTIVATION_TRYING_OTASP: | 710 case PLAN_ACTIVATION_TRYING_OTASP: |
695 if (network->activation_state() == ACTIVATION_STATE_NOT_ACTIVATED || | 711 if (activation == flimflam::kActivationStateNotActivated || |
696 network->activation_state() == ACTIVATION_STATE_ACTIVATING) { | 712 activation == flimflam::kActivationStateActivating) { |
697 LOG(INFO) << "Waiting for the OTASP to finish and the service to " | 713 LOG(INFO) << "Waiting for the OTASP to finish and the service to " |
698 << "come back online"; | 714 << "come back online"; |
699 } else if (network->activation_state() == ACTIVATION_STATE_ACTIVATED) { | 715 } else if (activation == flimflam::kActivationStateActivated) { |
700 new_state = PLAN_ACTIVATION_DONE; | 716 new_state = PLAN_ACTIVATION_DONE; |
701 } else { | 717 } else { |
702 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 718 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
703 } | 719 } |
704 break; | 720 break; |
705 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: | 721 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: |
706 if (!network->restricted_pool() && | 722 if (network->connection_state() != flimflam::kStatePortal && |
707 network->activation_state() == ACTIVATION_STATE_ACTIVATED) | 723 activation == flimflam::kActivationStateActivated) |
708 // We're not portalled, and we're already activated, so we're online! | 724 // We're not portalled, and we're already activated, so we're online! |
709 new_state = PLAN_ACTIVATION_DONE; | 725 new_state = PLAN_ACTIVATION_DONE; |
710 else | 726 else |
711 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 727 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
712 break; | 728 break; |
713 // Initial state | 729 // Initial state |
714 case PLAN_ACTIVATION_PAGE_LOADING: | 730 case PLAN_ACTIVATION_PAGE_LOADING: |
715 break; | 731 break; |
716 // Just ignore all signals until the site confirms payment. | 732 // Just ignore all signals until the site confirms payment. |
717 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 733 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 return "ERROR"; | 776 return "ERROR"; |
761 case PLAN_ACTIVATION_RECONNECTING: | 777 case PLAN_ACTIVATION_RECONNECTING: |
762 return "RECONNECTING"; | 778 return "RECONNECTING"; |
763 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: | 779 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: |
764 return "WAITING FOR CONNECTION"; | 780 return "WAITING FOR CONNECTION"; |
765 } | 781 } |
766 return "UNKNOWN"; | 782 return "UNKNOWN"; |
767 } | 783 } |
768 | 784 |
769 | 785 |
770 void MobileActivator::CompleteActivation( | 786 void MobileActivator::CompleteActivation(const NetworkState* network) { |
771 CellularNetwork* network) { | |
772 // Remove observers, we are done with this page. | 787 // Remove observers, we are done with this page. |
773 NetworkLibrary* lib = GetNetworkLibrary(); | 788 NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
774 lib->RemoveNetworkManagerObserver(this); | 789 this, FROM_HERE); |
775 lib->RemoveObserverForAllNetworks(this); | 790 |
776 // Reactivate other types of connections if we have | 791 // Reactivate other types of connections if we have |
777 // shut them down previously. | 792 // shut them down previously. |
778 ReEnableCertRevocationChecking(); | 793 ReEnableCertRevocationChecking(); |
779 } | 794 } |
780 | 795 |
781 bool MobileActivator::RunningActivation() const { | 796 bool MobileActivator::RunningActivation() const { |
782 return !(state_ == PLAN_ACTIVATION_DONE || | 797 return !(state_ == PLAN_ACTIVATION_DONE || |
783 state_ == PLAN_ACTIVATION_ERROR || | 798 state_ == PLAN_ACTIVATION_ERROR || |
784 state_ == PLAN_ACTIVATION_PAGE_LOADING); | 799 state_ == PLAN_ACTIVATION_PAGE_LOADING); |
785 } | 800 } |
786 | 801 |
787 void MobileActivator::ChangeState(CellularNetwork* network, | 802 void MobileActivator::HandleActivationFailure( |
803 const std::string& service_path, | |
804 PlanActivationState new_state, | |
805 const std::string& error_name, | |
806 scoped_ptr<base::DictionaryValue> error_data) { | |
807 const NetworkState* network = | |
808 NetworkHandler::Get()->network_state_handler()->GetNetworkState( | |
809 service_path); | |
stevenjb
2013/08/14 02:28:31
Need to confirm network != NULL here or in ChangeS
gauravsh
2013/08/14 21:42:29
Done.
| |
810 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); | |
811 LOG(ERROR) << "Failed to call Activate() on service in shill."; | |
stevenjb
2013/08/14 02:28:31
NET_LOG_ERROR
gauravsh
2013/08/14 21:42:29
Done.
| |
812 if (new_state == PLAN_ACTIVATION_OTASP) { | |
813 ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); | |
814 } else { | |
815 ChangeState(network, | |
816 PLAN_ACTIVATION_ERROR, | |
817 GetErrorMessage(kFailedConnectivity)); | |
818 } | |
819 } | |
820 | |
821 void MobileActivator::ChangeState(const NetworkState* network, | |
788 PlanActivationState new_state, | 822 PlanActivationState new_state, |
789 const std::string& error_description) { | 823 const std::string& error_description) { |
790 static bool first_time = true; | 824 static bool first_time = true; |
791 LOG(INFO) << "Activation state flip old = " | 825 LOG(INFO) << "Activation state flip old = " |
792 << GetStateDescription(state_) | 826 << GetStateDescription(state_) |
793 << ", new = " << GetStateDescription(new_state); | 827 << ", new = " << GetStateDescription(new_state); |
794 if (state_ == new_state && !first_time) | 828 if (state_ == new_state && !first_time) |
795 return; | 829 return; |
796 first_time = false; | 830 first_time = false; |
797 LOG(INFO) << "Transitioning..."; | 831 LOG(INFO) << "Transitioning..."; |
798 | 832 |
799 // Kill all the possible timers and callbacks we might have outstanding. | 833 // Kill all the possible timers and callbacks we might have outstanding. |
800 state_duration_timer_.Stop(); | 834 state_duration_timer_.Stop(); |
801 continue_reconnect_timer_.Stop(); | 835 continue_reconnect_timer_.Stop(); |
802 reconnect_timeout_timer_.Stop(); | 836 reconnect_timeout_timer_.Stop(); |
803 const PlanActivationState old_state = state_; | 837 const PlanActivationState old_state = state_; |
804 state_ = new_state; | 838 state_ = new_state; |
805 | 839 |
806 // Signal to observers layer that the state is changing. | 840 // Signal to observers layer that the state is changing. |
807 FOR_EACH_OBSERVER(Observer, observers_, | 841 FOR_EACH_OBSERVER(Observer, observers_, |
808 OnActivationStateChanged(network, state_, error_description)); | 842 OnActivationStateChanged(network, state_, error_description)); |
809 | 843 |
844 network_handler::ErrorCallback on_activation_error = | |
845 base::Bind(&MobileActivator::HandleActivationFailure, AsWeakPtr(), | |
846 network->path(), | |
847 new_state); | |
810 // Pick action that should happen on entering the new state. | 848 // Pick action that should happen on entering the new state. |
811 switch (new_state) { | 849 switch (new_state) { |
812 case PLAN_ACTIVATION_START: | 850 case PLAN_ACTIVATION_START: |
813 break; | 851 break; |
814 case PLAN_ACTIVATION_DELAY_OTASP: { | 852 case PLAN_ACTIVATION_DELAY_OTASP: { |
815 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); | 853 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); |
816 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 854 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
817 base::Bind(&MobileActivator::RetryOTASP, AsWeakPtr()), | 855 base::Bind(&MobileActivator::RetryOTASP, AsWeakPtr()), |
818 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay)); | 856 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay)); |
819 break; | 857 break; |
820 } | 858 } |
821 case PLAN_ACTIVATION_START_OTASP: | 859 case PLAN_ACTIVATION_START_OTASP: |
822 break; | 860 break; |
823 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 861 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
824 case PLAN_ACTIVATION_TRYING_OTASP: | 862 case PLAN_ACTIVATION_TRYING_OTASP: |
825 case PLAN_ACTIVATION_OTASP: | 863 case PLAN_ACTIVATION_OTASP: |
826 DCHECK(network); | 864 DCHECK(network); |
827 LOG(WARNING) << "Activating service " << network->service_path(); | 865 LOG(WARNING) << "Activating service " << network->path(); |
stevenjb
2013/08/14 02:28:31
NET_LOG_EVENT
gauravsh
2013/08/14 21:42:29
Done.
| |
828 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); | 866 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); |
829 if (!network->StartActivation()) { | 867 NetworkHandler::Get()->network_activation_handler()-> |
830 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); | 868 Activate(network->path(), |
831 LOG(ERROR) << "Failed to call Activate() on service in shill."; | 869 "", // carrier. |
stevenjb
2013/08/14 02:28:31
nit: no '.'
gauravsh
2013/08/14 21:42:29
Done.
| |
832 if (new_state == PLAN_ACTIVATION_OTASP) { | 870 base::Bind(&MobileActivator::StartOTASPTimer, AsWeakPtr()), |
833 ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); | 871 on_activation_error); |
834 } else { | |
835 ChangeState(network, | |
836 PLAN_ACTIVATION_ERROR, | |
837 GetErrorMessage(kFailedConnectivity)); | |
838 } | |
839 } else { | |
840 StartOTASPTimer(); | |
841 } | |
842 break; | 872 break; |
843 case PLAN_ACTIVATION_PAGE_LOADING: | 873 case PLAN_ACTIVATION_PAGE_LOADING: |
844 return; | 874 return; |
845 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 875 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
846 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 876 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
847 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: | 877 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: |
848 // Fix for fix SSL for the walled gardens where cert chain verification | 878 // Fix for fix SSL for the walled gardens where cert chain verification |
849 // might not work. | 879 // might not work. |
850 break; | 880 break; |
851 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: | 881 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: |
852 post_reconnect_state_ = old_state; | 882 post_reconnect_state_ = old_state; |
853 break; | 883 break; |
854 case PLAN_ACTIVATION_RECONNECTING: { | 884 case PLAN_ACTIVATION_RECONNECTING: { |
855 PlanActivationState next_state = old_state; | 885 PlanActivationState next_state = old_state; |
856 // Pick where we want to return to after we reconnect. | 886 // Pick where we want to return to after we reconnect. |
857 switch (old_state) { | 887 switch (old_state) { |
858 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 888 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
859 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 889 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
860 // We decide here what to do next based on the state of the modem. | 890 // We decide here what to do next based on the state of the modem. |
861 next_state = PLAN_ACTIVATION_RECONNECTING_PAYMENT; | 891 next_state = PLAN_ACTIVATION_RECONNECTING_PAYMENT; |
862 break; | 892 break; |
863 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 893 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
864 case PLAN_ACTIVATION_TRYING_OTASP: | 894 case PLAN_ACTIVATION_TRYING_OTASP: |
865 next_state = PLAN_ACTIVATION_START; | 895 next_state = PLAN_ACTIVATION_START; |
866 break; | 896 break; |
867 case PLAN_ACTIVATION_START_OTASP: | 897 case PLAN_ACTIVATION_START_OTASP: |
868 case PLAN_ACTIVATION_OTASP: | 898 case PLAN_ACTIVATION_OTASP: |
869 if (!network || !network->connected()) { | 899 if (!network || !network->IsConnectedState()) { |
870 next_state = PLAN_ACTIVATION_START_OTASP; | 900 next_state = PLAN_ACTIVATION_START_OTASP; |
871 } else { | 901 } else { |
872 // We're online, which means we've conspired with | 902 // We're online, which means we've conspired with |
873 // PickNextOnlineState to reconnect after activation (that's the | 903 // PickNextOnlineState to reconnect after activation (that's the |
874 // only way we see this transition). Thus, after we reconnect, we | 904 // only way we see this transition). Thus, after we reconnect, we |
875 // should be done. | 905 // should be done. |
876 next_state = PLAN_ACTIVATION_DONE; | 906 next_state = PLAN_ACTIVATION_DONE; |
877 } | 907 } |
878 break; | 908 break; |
879 default: | 909 default: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 PrefService* prefs = g_browser_process->local_state(); | 944 PrefService* prefs = g_browser_process->local_state(); |
915 if (!reenable_cert_check_ && | 945 if (!reenable_cert_check_ && |
916 prefs->GetBoolean( | 946 prefs->GetBoolean( |
917 prefs::kCertRevocationCheckingEnabled)) { | 947 prefs::kCertRevocationCheckingEnabled)) { |
918 reenable_cert_check_ = true; | 948 reenable_cert_check_ = true; |
919 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); | 949 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); |
920 } | 950 } |
921 } | 951 } |
922 | 952 |
923 bool MobileActivator::GotActivationError( | 953 bool MobileActivator::GotActivationError( |
924 CellularNetwork* network, std::string* error) const { | 954 const NetworkState* network, std::string* error) const { |
925 DCHECK(network); | 955 DCHECK(network); |
926 bool got_error = false; | 956 bool got_error = false; |
927 const char* error_code = kErrorDefault; | 957 const char* error_code = kErrorDefault; |
958 const std::string& activation = network->activation_state(); | |
928 | 959 |
929 // This is the magic for detection of errors in during activation process. | 960 // This is the magic for detection of errors in during activation process. |
930 if (network->state() == STATE_FAILURE && | 961 if (network->connection_state() == flimflam::kStateFailure && |
931 network->error() == ERROR_AAA_FAILED) { | 962 network->error() == flimflam::kErrorAaaFailed) { |
932 if (network->activation_state() == | 963 if (activation == flimflam::kActivationStatePartiallyActivated) { |
933 ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | |
934 error_code = kErrorBadConnectionPartial; | 964 error_code = kErrorBadConnectionPartial; |
935 } else if (network->activation_state() == ACTIVATION_STATE_ACTIVATED) { | 965 } else if (activation == flimflam::kActivationStateActivated) { |
936 if (network->roaming_state() == ROAMING_STATE_HOME) | 966 if (network->roaming() == flimflam::kRoamingStateHome) |
937 error_code = kErrorBadConnectionActivated; | 967 error_code = kErrorBadConnectionActivated; |
938 else if (network->roaming_state() == ROAMING_STATE_ROAMING) | 968 else if (network->roaming() == flimflam::kRoamingStateRoaming) |
939 error_code = kErrorRoamingOnConnection; | 969 error_code = kErrorRoamingOnConnection; |
940 } | 970 } |
941 got_error = true; | 971 got_error = true; |
942 } else if (network->state() == STATE_ACTIVATION_FAILURE) { | 972 } else if (network->connection_state() == flimflam::kStateActivationFailure) { |
943 if (network->error() == ERROR_NEED_EVDO) { | 973 if (network->error() == flimflam::kErrorNeedEvdo) { |
944 if (network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) | 974 if (activation == flimflam::kActivationStatePartiallyActivated) |
945 error_code = kErrorNoEVDO; | 975 error_code = kErrorNoEVDO; |
946 } else if (network->error() == ERROR_NEED_HOME_NETWORK) { | 976 } else if (network->error() == flimflam::kErrorNeedHomeNetwork) { |
947 if (network->activation_state() == ACTIVATION_STATE_NOT_ACTIVATED) { | 977 if (activation == flimflam::kActivationStateNotActivated) { |
948 error_code = kErrorRoamingActivation; | 978 error_code = kErrorRoamingActivation; |
949 } else if (network->activation_state() == | 979 } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
950 ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | |
951 error_code = kErrorRoamingPartiallyActivated; | 980 error_code = kErrorRoamingPartiallyActivated; |
952 } | 981 } |
953 } | 982 } |
954 got_error = true; | 983 got_error = true; |
955 } | 984 } |
956 | 985 |
957 if (got_error) | 986 if (got_error) |
958 *error = GetErrorMessage(error_code); | 987 *error = GetErrorMessage(error_code); |
959 | 988 |
960 return got_error; | 989 return got_error; |
961 } | 990 } |
962 | 991 |
963 void MobileActivator::GetDeviceInfo(CellularNetwork* network, | 992 void MobileActivator::GetDeviceInfo(const NetworkState* network, |
964 DictionaryValue* value) { | 993 DictionaryValue* value) { |
965 DCHECK(network); | 994 DCHECK(network); |
966 NetworkLibrary* cros = NetworkLibrary::Get(); | |
967 if (!cros) | |
968 return; | |
969 value->SetString("carrier", network->name()); | 995 value->SetString("carrier", network->name()); |
970 value->SetString("payment_url", network->payment_url()); | 996 value->SetString("payment_url", network->payment_url()); |
971 if (network->using_post() && network->post_data().length()) | 997 if (network->post_method() == "post" && !network->post_data().empty()) |
972 value->SetString("post_data", network->post_data()); | 998 value->SetString("post_data", network->post_data()); |
973 | 999 |
974 const NetworkDevice* device = | 1000 const DeviceState* device = |
975 cros->FindNetworkDeviceByPath(network->device_path()); | 1001 NetworkHandler::Get()->network_state_handler()->GetDeviceState( |
1002 network->device_path()); | |
976 if (device) { | 1003 if (device) { |
977 value->SetString("MEID", device->meid()); | 1004 value->SetString("MEID", device->meid()); |
978 value->SetString("IMEI", device->imei()); | 1005 value->SetString("IMEI", device->imei()); |
979 value->SetString("MDN", device->mdn()); | 1006 value->SetString("MDN", device->mdn()); |
980 } | 1007 } |
981 } | 1008 } |
982 | 1009 |
983 std::string MobileActivator::GetErrorMessage(const std::string& code) const { | 1010 std::string MobileActivator::GetErrorMessage(const std::string& code) const { |
984 return cellular_config_->GetErrorMessage(code); | 1011 return cellular_config_->GetErrorMessage(code); |
985 } | 1012 } |
986 | 1013 |
987 NetworkLibrary* MobileActivator::GetNetworkLibrary() const { | 1014 void MobileActivator::SignalCellularPlanPayment() { |
988 return NetworkLibrary::Get(); | 1015 DCHECK(!HasRecentCellularPlanPayment()); |
1016 cellular_plan_payment_time_ = base::Time::Now(); | |
1017 } | |
1018 | |
1019 bool MobileActivator::HasRecentCellularPlanPayment() const { | |
1020 const int kRecentPlanPaymentHours = 6; | |
1021 return (base::Time::Now() - | |
1022 cellular_plan_payment_time_).InHours() < kRecentPlanPaymentHours; | |
989 } | 1023 } |
990 | 1024 |
991 } // namespace chromeos | 1025 } // namespace chromeos |
OLD | NEW |