Skip to content

Commit

Permalink
Rename InvalidationAuthProvider to IdentityProvider
Browse files Browse the repository at this point in the history
The InvalidationAuthProvider is useful outside the area of invalidation:
It provides an abstract interface for accessing the logged-in GAIA account
and receiving notifications about login/logout events. This CL renames
the InvalidationAuthProvider to IdentityProvider and places it in the
gaia_apis component.

This change is a prerequisite for CL 225403021, which will use the
IdentityProvider in GCM.

BUG=362083
TEST=Updated tests

TBR=atwilson (for chrome/browser/sync/test/integration/sync_test.cc)

Review URL: https://codereview.chromium.org/235273002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265706 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
bartfab@chromium.org committed Apr 23, 2014
1 parent 2442605 commit a263ff5
Show file tree
Hide file tree
Showing 33 changed files with 484 additions and 386 deletions.
33 changes: 33 additions & 0 deletions chrome/browser/chromeos/settings/device_identity_provider.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/settings/device_identity_provider.h"

#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"

namespace chromeos {

DeviceIdentityProvider::DeviceIdentityProvider(
chromeos::DeviceOAuth2TokenService* token_service)
: token_service_(token_service) {}

DeviceIdentityProvider::~DeviceIdentityProvider() {}

std::string DeviceIdentityProvider::GetActiveUsername() {
return token_service_->GetRobotAccountId();
}

std::string DeviceIdentityProvider::GetActiveAccountId() {
return token_service_->GetRobotAccountId();
}

OAuth2TokenService* DeviceIdentityProvider::GetTokenService() {
return token_service_;
}

bool DeviceIdentityProvider::RequestLogin() {
return false;
}

} // namespace chromeos
36 changes: 36 additions & 0 deletions chrome/browser/chromeos/settings/device_identity_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_IDENTITY_PROVIDER_H_
#define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_IDENTITY_PROVIDER_H_

#include "base/macros.h"
#include "google_apis/gaia/identity_provider.h"

namespace chromeos {

class DeviceOAuth2TokenService;

// Identity provider implementation backed by DeviceOAuth2TokenService.
class DeviceIdentityProvider : public IdentityProvider {
public:
explicit DeviceIdentityProvider(
chromeos::DeviceOAuth2TokenService* token_service);
virtual ~DeviceIdentityProvider();

// IdentityProvider:
virtual std::string GetActiveUsername() OVERRIDE;
virtual std::string GetActiveAccountId() OVERRIDE;
virtual OAuth2TokenService* GetTokenService() OVERRIDE;
virtual bool RequestLogin() OVERRIDE;

private:
chromeos::DeviceOAuth2TokenService* token_service_;

DISALLOW_COPY_AND_ASSIGN(DeviceIdentityProvider);
};

} // namespace chromeos

#endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_IDENTITY_PROVIDER_H_
28 changes: 14 additions & 14 deletions chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/token_cache/token_cache_service.h"
#include "chrome/browser/extensions/token_cache/token_cache_service_factory.h"
#include "chrome/browser/invalidation/invalidation_auth_provider.h"
#include "chrome/browser/invalidation/invalidation_service.h"
#include "chrome/browser/invalidation/invalidation_service_factory.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -34,6 +33,7 @@
#include "extensions/common/extension.h"
#include "extensions/common/permissions/api_permission.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/identity_provider.h"

using content::BrowserThread;

Expand Down Expand Up @@ -111,12 +111,12 @@ bool PushMessagingGetChannelIdFunction::RunImpl() {
return false;
}

invalidation::InvalidationAuthProvider* auth_provider =
invalidation_service->GetInvalidationAuthProvider();
if (!auth_provider->GetTokenService()->RefreshTokenIsAvailable(
auth_provider->GetAccountId())) {
if (interactive_ && auth_provider->ShowLoginUI()) {
auth_provider->GetTokenService()->AddObserver(this);
IdentityProvider* identity_provider =
invalidation_service->GetIdentityProvider();
if (!identity_provider->GetTokenService()->RefreshTokenIsAvailable(
identity_provider->GetActiveAccountId())) {
if (interactive_ && identity_provider->RequestLogin()) {
identity_provider->AddActiveAccountRefreshTokenObserver(this);
return true;
} else {
error_ = kUserNotSignedIn;
Expand All @@ -135,24 +135,24 @@ void PushMessagingGetChannelIdFunction::StartAccessTokenFetch() {
invalidation::InvalidationService* invalidation_service =
invalidation::InvalidationServiceFactory::GetForProfile(GetProfile());
CHECK(invalidation_service);
invalidation::InvalidationAuthProvider* auth_provider =
invalidation_service->GetInvalidationAuthProvider();
IdentityProvider* identity_provider =
invalidation_service->GetIdentityProvider();

std::vector<std::string> scope_vector =
extensions::ObfuscatedGaiaIdFetcher::GetScopes();
OAuth2TokenService::ScopeSet scopes(scope_vector.begin(), scope_vector.end());
fetcher_access_token_request_ =
auth_provider->GetTokenService()->StartRequest(
auth_provider->GetAccountId(), scopes, this);
identity_provider->GetTokenService()->StartRequest(
identity_provider->GetActiveAccountId(), scopes, this);
}

void PushMessagingGetChannelIdFunction::OnRefreshTokenAvailable(
const std::string& account_id) {
invalidation::InvalidationService* invalidation_service =
invalidation::InvalidationServiceFactory::GetForProfile(GetProfile());
CHECK(invalidation_service);
invalidation_service->GetInvalidationAuthProvider()->GetTokenService()->
RemoveObserver(this);
invalidation_service->GetIdentityProvider()->
RemoveActiveAccountRefreshTokenObserver(this);
DVLOG(2) << "Newly logged in: " << GetProfile()->GetProfileName();
StartAccessTokenFetch();
}
Expand Down Expand Up @@ -274,7 +274,7 @@ void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure(
invalidation::InvalidationServiceFactory::GetForProfile(GetProfile());
CHECK(invalidation_service);
if (!interactive_ ||
!invalidation_service->GetInvalidationAuthProvider()->ShowLoginUI()) {
!invalidation_service->GetIdentityProvider()->RequestLogin()) {
ReportResult(std::string(), error_text);
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class MockInvalidationService : public invalidation::InvalidationService {
MOCK_METHOD0(GetInvalidationLogger, invalidation::InvalidationLogger*());
MOCK_CONST_METHOD1(RequestDetailedStatus,
void(base::Callback<void(const base::DictionaryValue&)>));
MOCK_METHOD0(GetInvalidationAuthProvider,
invalidation::InvalidationAuthProvider*());
MOCK_METHOD0(GetIdentityProvider, IdentityProvider*());

private:
DISALLOW_COPY_AND_ASSIGN(MockInvalidationService);
Expand Down

This file was deleted.

This file was deleted.

25 changes: 5 additions & 20 deletions chrome/browser/invalidation/fake_invalidation_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,11 @@

namespace invalidation {

FakeInvalidationAuthProvider::FakeInvalidationAuthProvider() {
token_service_.set_auto_post_fetch_response_on_message_loop(true);
}

FakeInvalidationAuthProvider::~FakeInvalidationAuthProvider() {}

OAuth2TokenService* FakeInvalidationAuthProvider::GetTokenService() {
return &token_service_;
}

std::string FakeInvalidationAuthProvider::GetAccountId() {
return "fake@example.com";
}

bool FakeInvalidationAuthProvider::ShowLoginUI() { return false; }

FakeInvalidationService::FakeInvalidationService()
: client_id_(GenerateInvalidatorClientId()) {
: client_id_(GenerateInvalidatorClientId()),
identity_provider_(&token_service_) {
invalidator_registrar_.UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED);
token_service_.set_auto_post_fetch_response_on_message_loop(true);
}

FakeInvalidationService::~FakeInvalidationService() {
Expand Down Expand Up @@ -73,9 +59,8 @@ void FakeInvalidationService::RequestDetailedStatus(
caller.Run(value);
}

InvalidationAuthProvider*
FakeInvalidationService::GetInvalidationAuthProvider() {
return &auth_provider_;
IdentityProvider* FakeInvalidationService::GetIdentityProvider() {
return &identity_provider_;
}

void FakeInvalidationService::SetInvalidatorState(
Expand Down
28 changes: 4 additions & 24 deletions chrome/browser/invalidation/fake_invalidation_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "chrome/browser/invalidation/invalidation_auth_provider.h"
#include "chrome/browser/invalidation/invalidation_service.h"
#include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
#include "google_apis/gaia/fake_identity_provider.h"
#include "sync/notifier/invalidator_registrar.h"
#include "sync/notifier/mock_ack_handler.h"

Expand All @@ -28,27 +28,6 @@ namespace invalidation {

class InvalidationLogger;

// Fake invalidation auth provider implementation.
class FakeInvalidationAuthProvider : public InvalidationAuthProvider {
public:
FakeInvalidationAuthProvider();
virtual ~FakeInvalidationAuthProvider();

// InvalidationAuthProvider:
virtual OAuth2TokenService* GetTokenService() OVERRIDE;
virtual std::string GetAccountId() OVERRIDE;
virtual bool ShowLoginUI() OVERRIDE;

FakeProfileOAuth2TokenService* fake_token_service() {
return &token_service_;
}

private:
FakeProfileOAuth2TokenService token_service_;

DISALLOW_COPY_AND_ASSIGN(FakeInvalidationAuthProvider);
};

// An InvalidationService that emits invalidations only when
// its EmitInvalidationForTest method is called.
class FakeInvalidationService : public InvalidationService {
Expand All @@ -71,7 +50,7 @@ class FakeInvalidationService : public InvalidationService {
virtual InvalidationLogger* GetInvalidationLogger() OVERRIDE;
virtual void RequestDetailedStatus(
base::Callback<void(const base::DictionaryValue&)> caller) const OVERRIDE;
virtual InvalidationAuthProvider* GetInvalidationAuthProvider() OVERRIDE;
virtual IdentityProvider* GetIdentityProvider() OVERRIDE;

void SetInvalidatorState(syncer::InvalidatorState state);

Expand All @@ -89,7 +68,8 @@ class FakeInvalidationService : public InvalidationService {
std::string client_id_;
syncer::InvalidatorRegistrar invalidator_registrar_;
syncer::MockAckHandler mock_ack_handler_;
FakeInvalidationAuthProvider auth_provider_;
FakeProfileOAuth2TokenService token_service_;
FakeIdentityProvider identity_provider_;

DISALLOW_COPY_AND_ASSIGN(FakeInvalidationService);
};
Expand Down
14 changes: 7 additions & 7 deletions chrome/browser/invalidation/gcm_invalidation_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "chrome/browser/invalidation/gcm_invalidation_bridge.h"
#include "chrome/browser/invalidation/invalidation_auth_provider.h"
#include "chrome/browser/services/gcm/gcm_profile_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/identity_provider.h"

namespace invalidation {
namespace {
Expand Down Expand Up @@ -149,10 +149,10 @@ void GCMInvalidationBridge::Core::OnIncomingMessage(

GCMInvalidationBridge::GCMInvalidationBridge(
gcm::GCMProfileService* gcm_profile_service,
InvalidationAuthProvider* auth_provider)
IdentityProvider* identity_provider)
: OAuth2TokenService::Consumer("gcm_network_channel"),
gcm_profile_service_(gcm_profile_service),
auth_provider_(auth_provider),
identity_provider_(identity_provider),
subscribed_for_incoming_messages_(false),
weak_factory_(this) {}

Expand Down Expand Up @@ -195,8 +195,8 @@ void GCMInvalidationBridge::RequestToken(
request_token_callback_ = callback;
OAuth2TokenService::ScopeSet scopes;
scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope);
access_token_request_ = auth_provider_->GetTokenService()->StartRequest(
auth_provider_->GetAccountId(), scopes, this);
access_token_request_ = identity_provider_->GetTokenService()->StartRequest(
identity_provider_->GetActiveAccountId(), scopes, this);
}

void GCMInvalidationBridge::OnGetTokenSuccess(
Expand Down Expand Up @@ -236,8 +236,8 @@ void GCMInvalidationBridge::InvalidateToken(const std::string& token) {
DCHECK(CalledOnValidThread());
OAuth2TokenService::ScopeSet scopes;
scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope);
auth_provider_->GetTokenService()->InvalidateToken(
auth_provider_->GetAccountId(), scopes, token);
identity_provider_->GetTokenService()->InvalidateToken(
identity_provider_->GetActiveAccountId(), scopes, token);
}

void GCMInvalidationBridge::Register(
Expand Down
Loading

0 comments on commit a263ff5

Please sign in to comment.