Skip to content

Commit 79da5a0

Browse files
Kyle HorimotoKyle Horimoto
authored andcommitted
[CrOS Tether] Eliminate token fetch from Initializer.
This code was unnecessary, since the CryptAuth component is the one that needs to listen for these tokens. Additionally, the listener in this class was set up improperly, which made it possible to get "stuck" without a token. TBR=khorimoto@google.com (cherry picked from commit a88ec4a) Bug: 763506, 672263 Change-Id: I3e02f10aa201b129591028a8606b6fb4eefbaf11 Reviewed-on: https://chromium-review.googlesource.com/663978 Commit-Queue: Kyle Horimoto <khorimoto@chromium.org> Reviewed-by: Ryan Hansberry <hansberry@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#501486} Reviewed-on: https://chromium-review.googlesource.com/663982 Reviewed-by: Kyle Horimoto <khorimoto@chromium.org> Cr-Commit-Position: refs/branch-heads/3202@{crosswalk-project#193} Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
1 parent 7b954f1 commit 79da5a0

File tree

5 files changed

+6
-55
lines changed

5 files changed

+6
-55
lines changed

chrome/browser/chromeos/tether/tether_service.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "chrome/browser/chromeos/tether/tether_service_factory.h"
1515
#include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h"
1616
#include "chrome/browser/profiles/profile.h"
17-
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
1817
#include "chrome/common/chrome_features.h"
1918
#include "chrome/common/pref_names.h"
2019
#include "chromeos/chromeos_switches.h"
@@ -159,7 +158,6 @@ void TetherService::StartTetherIfPossible() {
159158
PA_LOG(INFO) << "Starting up Tether component.";
160159
initializer_ = chromeos::tether::InitializerImpl::Factory::NewInstance(
161160
cryptauth_service_, notification_presenter_.get(), profile_->GetPrefs(),
162-
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
163161
network_state_handler_,
164162
chromeos::NetworkHandler::Get()->managed_network_configuration_handler(),
165163
chromeos::NetworkConnect::Get(),

chrome/browser/chromeos/tether/tether_service_unittest.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ class TestInitializerFactory
157157
cryptauth::CryptAuthService* cryptauth_service,
158158
chromeos::tether::NotificationPresenter* notification_presenter,
159159
PrefService* pref_service,
160-
ProfileOAuth2TokenService* token_service,
161160
chromeos::NetworkStateHandler* network_state_handler,
162161
chromeos::ManagedNetworkConfigurationHandler*
163162
managed_network_configuration_handler,

chromeos/components/tether/initializer_impl.cc

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ std::unique_ptr<Initializer> InitializerImpl::Factory::NewInstance(
6464
cryptauth::CryptAuthService* cryptauth_service,
6565
NotificationPresenter* notification_presenter,
6666
PrefService* pref_service,
67-
ProfileOAuth2TokenService* token_service,
6867
NetworkStateHandler* network_state_handler,
6968
ManagedNetworkConfigurationHandler* managed_network_configuration_handler,
7069
NetworkConnect* network_connect,
@@ -74,7 +73,7 @@ std::unique_ptr<Initializer> InitializerImpl::Factory::NewInstance(
7473
factory_instance_ = new Factory();
7574
}
7675
return factory_instance_->BuildInstance(
77-
cryptauth_service, notification_presenter, pref_service, token_service,
76+
cryptauth_service, notification_presenter, pref_service,
7877
network_state_handler, managed_network_configuration_handler,
7978
network_connect, network_connection_handler, adapter);
8079
}
@@ -96,14 +95,13 @@ std::unique_ptr<Initializer> InitializerImpl::Factory::BuildInstance(
9695
cryptauth::CryptAuthService* cryptauth_service,
9796
NotificationPresenter* notification_presenter,
9897
PrefService* pref_service,
99-
ProfileOAuth2TokenService* token_service,
10098
NetworkStateHandler* network_state_handler,
10199
ManagedNetworkConfigurationHandler* managed_network_configuration_handler,
102100
NetworkConnect* network_connect,
103101
NetworkConnectionHandler* network_connection_handler,
104102
scoped_refptr<device::BluetoothAdapter> adapter) {
105103
return base::WrapUnique(new InitializerImpl(
106-
cryptauth_service, notification_presenter, pref_service, token_service,
104+
cryptauth_service, notification_presenter, pref_service,
107105
network_state_handler, managed_network_configuration_handler,
108106
network_connect, network_connection_handler, adapter));
109107
}
@@ -112,7 +110,6 @@ InitializerImpl::InitializerImpl(
112110
cryptauth::CryptAuthService* cryptauth_service,
113111
NotificationPresenter* notification_presenter,
114112
PrefService* pref_service,
115-
ProfileOAuth2TokenService* token_service,
116113
NetworkStateHandler* network_state_handler,
117114
ManagedNetworkConfigurationHandler* managed_network_configuration_handler,
118115
NetworkConnect* network_connect,
@@ -121,28 +118,17 @@ InitializerImpl::InitializerImpl(
121118
: cryptauth_service_(cryptauth_service),
122119
notification_presenter_(notification_presenter),
123120
pref_service_(pref_service),
124-
token_service_(token_service),
125121
network_state_handler_(network_state_handler),
126122
managed_network_configuration_handler_(
127123
managed_network_configuration_handler),
128124
network_connect_(network_connect),
129125
network_connection_handler_(network_connection_handler),
130126
adapter_(adapter),
131127
weak_ptr_factory_(this) {
132-
if (!token_service_->RefreshTokenIsAvailable(
133-
cryptauth_service_->GetAccountId())) {
134-
PA_LOG(INFO) << "Refresh token not yet available; "
135-
<< "waiting for valid token to initializing tether feature.";
136-
token_service_->AddObserver(this);
137-
return;
138-
}
139-
140-
PA_LOG(INFO) << "Refresh token is available; initializing tether feature.";
141128
CreateComponent();
142129
}
143130

144131
InitializerImpl::~InitializerImpl() {
145-
token_service_->RemoveObserver(this);
146132
network_state_handler_->set_tether_sort_delegate(nullptr);
147133

148134
if (disconnect_tethering_request_sender_)
@@ -187,20 +173,6 @@ void InitializerImpl::RequestShutdown() {
187173
StartAsynchronousShutdown();
188174
}
189175

190-
void InitializerImpl::OnRefreshTokensLoaded() {
191-
if (!token_service_->RefreshTokenIsAvailable(
192-
cryptauth_service_->GetAccountId())) {
193-
// If a token for the active account is still not available, continue
194-
// waiting for a new token.
195-
return;
196-
}
197-
198-
PA_LOG(INFO) << "Refresh token has loaded; initializing tether feature.";
199-
200-
token_service_->RemoveObserver(this);
201-
CreateComponent();
202-
}
203-
204176
void InitializerImpl::OnPendingDisconnectRequestsComplete() {
205177
DCHECK(status() == Initializer::Status::SHUTTING_DOWN);
206178
disconnect_tethering_request_sender_->RemoveObserver(this);
@@ -217,9 +189,6 @@ void InitializerImpl::OnPendingDisconnectRequestsComplete() {
217189
}
218190

219191
void InitializerImpl::CreateComponent() {
220-
PA_LOG(INFO) << "Successfully set Bluetooth advertisement interval. "
221-
<< "Initializing tether feature.";
222-
223192
network_list_sorter_ = base::MakeUnique<NetworkListSorter>();
224193
network_state_handler_->set_tether_sort_delegate(network_list_sorter_.get());
225194
tether_host_fetcher_ =

chromeos/components/tether/initializer_impl.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "chromeos/components/tether/disconnect_tethering_request_sender.h"
1616
#include "chromeos/components/tether/initializer.h"
1717
#include "components/prefs/pref_registry_simple.h"
18-
#include "components/signin/core/browser/profile_oauth2_token_service.h"
1918
#include "device/bluetooth/bluetooth_adapter.h"
2019
#include "device/bluetooth/bluetooth_advertisement.h"
2120

@@ -64,7 +63,6 @@ class WifiHotspotDisconnector;
6463

6564
// Initializes the Tether Chrome OS component.
6665
class InitializerImpl : public Initializer,
67-
public OAuth2TokenService::Observer,
6866
public DisconnectTetheringRequestSender::Observer {
6967
public:
7068
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
@@ -75,7 +73,6 @@ class InitializerImpl : public Initializer,
7573
cryptauth::CryptAuthService* cryptauth_service,
7674
NotificationPresenter* notification_presenter,
7775
PrefService* pref_service,
78-
ProfileOAuth2TokenService* token_service,
7976
NetworkStateHandler* network_state_handler,
8077
ManagedNetworkConfigurationHandler*
8178
managed_network_configuration_handler,
@@ -90,7 +87,6 @@ class InitializerImpl : public Initializer,
9087
cryptauth::CryptAuthService* cryptauth_service,
9188
NotificationPresenter* notification_presenter,
9289
PrefService* pref_service,
93-
ProfileOAuth2TokenService* token_service,
9490
NetworkStateHandler* network_state_handler,
9591
ManagedNetworkConfigurationHandler*
9692
managed_network_configuration_handler,
@@ -106,7 +102,6 @@ class InitializerImpl : public Initializer,
106102
cryptauth::CryptAuthService* cryptauth_service,
107103
NotificationPresenter* notification_presenter,
108104
PrefService* pref_service,
109-
ProfileOAuth2TokenService* token_service,
110105
NetworkStateHandler* network_state_handler,
111106
ManagedNetworkConfigurationHandler* managed_network_configuration_handler,
112107
NetworkConnect* network_connect,
@@ -118,9 +113,6 @@ class InitializerImpl : public Initializer,
118113
// Initializer:
119114
void RequestShutdown() override;
120115

121-
// OAuth2TokenService::Observer:
122-
void OnRefreshTokensLoaded() override;
123-
124116
// DisconnectTetheringRequestSender::Observer:
125117
void OnPendingDisconnectRequestsComplete() override;
126118

@@ -134,7 +126,6 @@ class InitializerImpl : public Initializer,
134126
cryptauth::CryptAuthService* cryptauth_service_;
135127
NotificationPresenter* notification_presenter_;
136128
PrefService* pref_service_;
137-
ProfileOAuth2TokenService* token_service_;
138129
NetworkStateHandler* network_state_handler_;
139130
ManagedNetworkConfigurationHandler* managed_network_configuration_handler_;
140131
NetworkConnect* network_connect_;

chromeos/components/tether/initializer_impl_unittest.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "components/cryptauth/proto/cryptauth_api.pb.h"
2828
#include "components/cryptauth/secure_message_delegate.h"
2929
#include "components/prefs/testing_pref_service.h"
30-
#include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
3130
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
3231
#include "testing/gmock/include/gmock/gmock.h"
3332
#include "testing/gtest/include/gtest/gtest.h"
@@ -142,14 +141,13 @@ class InitializerTest : public NetworkStateTest {
142141
cryptauth::CryptAuthService* cryptauth_service,
143142
NotificationPresenter* notification_presenter,
144143
PrefService* pref_service,
145-
ProfileOAuth2TokenService* token_service,
146144
NetworkStateHandler* network_state_handler,
147145
ManagedNetworkConfigurationHandler* managed_network_configuration_handler,
148146
NetworkConnect* network_connect,
149147
NetworkConnectionHandler* network_connection_handler,
150148
scoped_refptr<device::BluetoothAdapter> adapter) {
151149
Initializer* initializer = new InitializerImpl(
152-
cryptauth_service, notification_presenter, pref_service, token_service,
150+
cryptauth_service, notification_presenter, pref_service,
153151
network_state_handler, managed_network_configuration_handler,
154152
network_connect, network_connection_handler, adapter);
155153
delete initializer;
@@ -193,9 +191,6 @@ TEST_F(InitializerTest, TestCreateAndDestroy) {
193191
std::unique_ptr<TestingPrefServiceSimple> test_pref_service =
194192
base::MakeUnique<TestingPrefServiceSimple>();
195193

196-
std::unique_ptr<FakeProfileOAuth2TokenService> fake_token_service =
197-
base::MakeUnique<FakeProfileOAuth2TokenService>();
198-
199194
std::unique_ptr<ManagedNetworkConfigurationHandler>
200195
managed_network_configuration_handler = base::WrapUnique(
201196
new NiceMock<MockManagedNetworkConfigurationHandler>);
@@ -214,10 +209,9 @@ TEST_F(InitializerTest, TestCreateAndDestroy) {
214209
// InitializerTest only applies to the class itself, not these test functions.
215210
InitializeAndDestroy(
216211
fake_cryptauth_service.get(), fake_notification_presenter.get(),
217-
test_pref_service_.get(), fake_token_service.get(),
218-
network_state_handler(), managed_network_configuration_handler.get(),
219-
mock_network_connect.get(), network_connection_handler_.get(),
220-
mock_adapter);
212+
test_pref_service_.get(), network_state_handler(),
213+
managed_network_configuration_handler.get(), mock_network_connect.get(),
214+
network_connection_handler_.get(), mock_adapter);
221215
}
222216

223217
} // namespace tether

0 commit comments

Comments
 (0)