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

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

Issue 12729002: Add a unified observer to replace NetworkManagerObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix mobile_activator_unittest Created 7 years, 9 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
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 #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 "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ref_counted_memory.h" 16 #include "base/memory/ref_counted_memory.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/observer_list_threadsafe.h" 19 #include "base/observer_list_threadsafe.h"
20 #include "base/prefs/pref_service.h" 20 #include "base/prefs/pref_service.h"
21 #include "base/string_piece.h" 21 #include "base/string_piece.h"
22 #include "base/string_util.h" 22 #include "base/string_util.h"
23 #include "base/timer.h" 23 #include "base/timer.h"
24 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
25 #include "base/values.h" 25 #include "base/values.h"
26 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/chromeos/cros/cros_library.h" 27 #include "chrome/browser/chromeos/cros/cros_library.h"
28 #include "chrome/browser/chromeos/cros/network_library.h" 28 #include "chrome/browser/chromeos/net/connectivity_state_helper.h"
29 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
30 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
31 31
32 using content::BrowserThread; 32 using content::BrowserThread;
33 33
34 namespace { 34 namespace {
35 35
36 // Cellular configuration file path. 36 // Cellular configuration file path.
37 const char kCellularConfigPath[] = 37 const char kCellularConfigPath[] =
38 "/usr/share/chromeos-assets/mobile/mobile_config.json"; 38 "/usr/share/chromeos-assets/mobile/mobile_config.json";
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 void MobileActivator::TerminateActivation() { 166 void MobileActivator::TerminateActivation() {
167 // We're exiting; don't continue with termination. 167 // We're exiting; don't continue with termination.
168 if (!CrosLibrary::Get()) 168 if (!CrosLibrary::Get())
169 return; 169 return;
170 170
171 state_duration_timer_.Stop(); 171 state_duration_timer_.Stop();
172 continue_reconnect_timer_.Stop(); 172 continue_reconnect_timer_.Stop();
173 reconnect_timeout_timer_.Stop(); 173 reconnect_timeout_timer_.Stop();
174 174
175 ConnectivityStateHelper::Get()->RemoveNetworkManagerObserver(this);
175 NetworkLibrary* lib = GetNetworkLibrary(); 176 NetworkLibrary* lib = GetNetworkLibrary();
stevenjb 2013/03/11 23:11:05 I'd feel more comfortable converting all of this a
gauravsh 2013/03/12 00:30:25 This will still use the NetworkLibrary path in pro
stevenjb 2013/03/12 15:53:34 We will almost certainly want to turn on --enable-
176 lib->RemoveNetworkManagerObserver(this);
177 lib->RemoveObserverForAllNetworks(this); 177 lib->RemoveObserverForAllNetworks(this);
178 if (lib->IsLocked()) 178 if (lib->IsLocked())
179 lib->Unlock(); 179 lib->Unlock();
180 ReEnableCertRevocationChecking(); 180 ReEnableCertRevocationChecking();
181 meid_.clear(); 181 meid_.clear();
182 iccid_.clear(); 182 iccid_.clear();
183 service_path_.clear(); 183 service_path_.clear();
184 state_ = PLAN_ACTIVATION_PAGE_LOADING; 184 state_ = PLAN_ACTIVATION_PAGE_LOADING;
185 reenable_cert_check_ = false; 185 reenable_cert_check_ = false;
186 terminated_ = true; 186 terminated_ = true;
187 // Release the previous cellular config and setup a new empty one. 187 // Release the previous cellular config and setup a new empty one.
188 cellular_config_ = new CellularConfigDocument(); 188 cellular_config_ = new CellularConfigDocument();
189 } 189 }
190 190
191 void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) { 191 void MobileActivator::NetworkManagerChanged() {
192 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) 192 if (state_ == PLAN_ACTIVATION_PAGE_LOADING)
193 return; 193 return;
194 EvaluateCellularNetwork(FindMatchingCellularNetwork(true)); 194 EvaluateCellularNetwork(FindMatchingCellularNetwork(true));
195 } 195 }
196 196
197 void MobileActivator::OnNetworkChanged(NetworkLibrary* cros, 197 void MobileActivator::OnNetworkChanged(NetworkLibrary* cros,
198 const Network* network) { 198 const Network* network) {
199 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) 199 if (state_ == PLAN_ACTIVATION_PAGE_LOADING)
200 return; 200 return;
201 201
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 error = kErrorNoDevice; 366 error = kErrorNoDevice;
367 else if (!lib->cellular_enabled()) 367 else if (!lib->cellular_enabled())
368 error = kErrorDisabled; 368 error = kErrorDisabled;
369 else 369 else
370 error = kErrorNoService; 370 error = kErrorNoService;
371 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); 371 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error));
372 return; 372 return;
373 } 373 }
374 374
375 // Start monitoring network property changes. 375 // Start monitoring network property changes.
376 lib->AddNetworkManagerObserver(this); 376 ConnectivityStateHelper::Get()->AddNetworkManagerObserver(this);
377 if (network->activate_over_non_cellular_network()) { 377 if (network->activate_over_non_cellular_network()) {
378 // Fast forward to payment portal loading if the activation is performed 378 // Fast forward to payment portal loading if the activation is performed
379 // over a non-cellular network. 379 // over a non-cellular network.
380 ChangeState(network, 380 ChangeState(network,
381 (network->activation_state() == ACTIVATION_STATE_ACTIVATED) ? 381 (network->activation_state() == ACTIVATION_STATE_ACTIVATED) ?
382 PLAN_ACTIVATION_DONE : 382 PLAN_ACTIVATION_DONE :
383 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, 383 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING,
384 ""); 384 "");
385 } else if (lib->HasRecentCellularPlanPayment() && 385 } else if (lib->HasRecentCellularPlanPayment() &&
386 network->activation_state() == 386 network->activation_state() ==
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 case PLAN_ACTIVATION_RECONNECTING: 733 case PLAN_ACTIVATION_RECONNECTING:
734 return "RECONNECTING"; 734 return "RECONNECTING";
735 } 735 }
736 return "UNKNOWN"; 736 return "UNKNOWN";
737 } 737 }
738 738
739 739
740 void MobileActivator::CompleteActivation( 740 void MobileActivator::CompleteActivation(
741 CellularNetwork* network) { 741 CellularNetwork* network) {
742 // Remove observers, we are done with this page. 742 // Remove observers, we are done with this page.
743 ConnectivityStateHelper::Get()->RemoveNetworkManagerObserver(this);
743 NetworkLibrary* lib = GetNetworkLibrary(); 744 NetworkLibrary* lib = GetNetworkLibrary();
744 lib->RemoveNetworkManagerObserver(this);
745 lib->RemoveObserverForAllNetworks(this); 745 lib->RemoveObserverForAllNetworks(this);
746 if (lib->IsLocked()) 746 if (lib->IsLocked())
747 lib->Unlock(); 747 lib->Unlock();
748 // Reactivate other types of connections if we have 748 // Reactivate other types of connections if we have
749 // shut them down previously. 749 // shut them down previously.
750 ReEnableCertRevocationChecking(); 750 ReEnableCertRevocationChecking();
751 } 751 }
752 752
753 bool MobileActivator::RunningActivation() const { 753 bool MobileActivator::RunningActivation() const {
754 return !(state_ == PLAN_ACTIVATION_DONE || 754 return !(state_ == PLAN_ACTIVATION_DONE ||
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 951
952 std::string MobileActivator::GetErrorMessage(const std::string& code) const { 952 std::string MobileActivator::GetErrorMessage(const std::string& code) const {
953 return cellular_config_->GetErrorMessage(code); 953 return cellular_config_->GetErrorMessage(code);
954 } 954 }
955 955
956 NetworkLibrary* MobileActivator::GetNetworkLibrary() const { 956 NetworkLibrary* MobileActivator::GetNetworkLibrary() const {
957 return CrosLibrary::Get()->GetNetworkLibrary(); 957 return CrosLibrary::Get()->GetNetworkLibrary();
958 } 958 }
959 959
960 } // namespace chromeos 960 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698