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

Unified Diff: chrome/browser/invalidation/ticl_invalidation_service.cc

Issue 179843002: Make invalidations work for Chrome OS Kiosk Apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/invalidation/ticl_invalidation_service.cc
diff --git a/chrome/browser/invalidation/ticl_invalidation_service.cc b/chrome/browser/invalidation/ticl_invalidation_service.cc
index 616bdc1c89b33265ea6d22344f9fddefaa6298e5..b89fbbcaec367d3cb412442623731e3c504b6e73 100644
--- a/chrome/browser/invalidation/ticl_invalidation_service.cc
+++ b/chrome/browser/invalidation/ticl_invalidation_service.cc
@@ -6,17 +6,11 @@
#include "base/command_line.h"
#include "base/metrics/histogram.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/invalidation/gcm_network_channel_delegate_impl.h"
+#include "chrome/browser/invalidation/invalidation_auth_provider.h"
#include "chrome/browser/invalidation/invalidation_logger.h"
#include "chrome/browser/invalidation/invalidation_service_util.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/signin/about_signin_internals.h"
-#include "chrome/browser/signin/about_signin_internals_factory.h"
-#include "chrome/browser/signin/profile_oauth2_token_service.h"
-#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
-#include "chrome/browser/signin/signin_manager.h"
-#include "content/public/browser/notification_service.h"
#include "google_apis/gaia/gaia_constants.h"
#include "sync/notifier/gcm_network_channel_delegate.h"
#include "sync/notifier/invalidation_util.h"
@@ -60,16 +54,15 @@ static const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = {
namespace invalidation {
TiclInvalidationService::TiclInvalidationService(
- SigninManagerBase* signin,
- ProfileOAuth2TokenService* oauth2_token_service,
+ scoped_ptr<InvalidationAuthProvider> auth_provider,
Profile* profile)
: OAuth2TokenService::Consumer("ticl_invalidation"),
profile_(profile),
- signin_manager_(signin),
- oauth2_token_service_(oauth2_token_service),
+ auth_provider_(auth_provider.Pass()),
invalidator_registrar_(new syncer::InvalidatorRegistrar()),
request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy),
- logger_() {}
+ logger_() {
+}
TiclInvalidationService::~TiclInvalidationService() {
DCHECK(CalledOnValidThread());
@@ -89,10 +82,8 @@ void TiclInvalidationService::Init() {
StartInvalidator(PUSH_CLIENT_CHANNEL);
}
- notification_registrar_.Add(this,
- chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
- content::Source<Profile>(profile_));
- oauth2_token_service_->AddObserver(this);
+ auth_provider_->AddObserver(this);
+ auth_provider_->GetTokenService()->AddObserver(this);
}
void TiclInvalidationService::InitForTest(syncer::Invalidator* invalidator) {
@@ -163,13 +154,9 @@ InvalidationLogger* TiclInvalidationService::GetInvalidationLogger() {
return &logger_;
}
-void TiclInvalidationService::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK(CalledOnValidThread());
- DCHECK_EQ(type, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT);
- Logout();
+InvalidationAuthProvider*
+TiclInvalidationService::GetInvalidationAuthProvider() {
+ return auth_provider_.get();
}
void TiclInvalidationService::RequestAccessToken() {
@@ -182,14 +169,12 @@ void TiclInvalidationService::RequestAccessToken() {
oauth2_scopes.insert(kOAuth2Scopes[i]);
// Invalidate previous token, otherwise token service will return the same
// token again.
- const std::string& account_id = signin_manager_->GetAuthenticatedAccountId();
- oauth2_token_service_->InvalidateToken(account_id,
- oauth2_scopes,
- access_token_);
+ const std::string& account_id = auth_provider_->GetAccountId();
+ OAuth2TokenService* token_service = auth_provider_->GetTokenService();
+ token_service->InvalidateToken(account_id, oauth2_scopes, access_token_);
access_token_.clear();
- access_token_request_ = oauth2_token_service_->StartRequest(account_id,
- oauth2_scopes,
- this);
+ access_token_request_ =
+ token_service->StartRequest(account_id, oauth2_scopes, this);
}
void TiclInvalidationService::OnGetTokenSuccess(
@@ -240,7 +225,7 @@ void TiclInvalidationService::OnGetTokenFailure(
void TiclInvalidationService::OnRefreshTokenAvailable(
const std::string& account_id) {
- if (signin_manager_->GetAuthenticatedAccountId() == account_id) {
+ if (auth_provider_->GetAccountId() == account_id) {
if (!IsStarted() && IsReadyToStart()) {
StartInvalidator(PUSH_CLIENT_CHANNEL);
}
@@ -249,7 +234,7 @@ void TiclInvalidationService::OnRefreshTokenAvailable(
void TiclInvalidationService::OnRefreshTokenRevoked(
const std::string& account_id) {
- if (signin_manager_->GetAuthenticatedAccountId() == account_id) {
+ if (auth_provider_->GetAccountId() == account_id) {
access_token_.clear();
if (IsStarted()) {
UpdateInvalidatorCredentials();
@@ -257,6 +242,21 @@ void TiclInvalidationService::OnRefreshTokenRevoked(
}
}
+void TiclInvalidationService::OnInvalidationAuthLogout() {
+ access_token_request_.reset();
+ request_access_token_retry_timer_.Stop();
+
+ if (IsStarted()) {
+ StopInvalidator();
+ }
+
+ // This service always expects to have a valid invalidator storage.
+ // So we must not only clear the old one, but also start a new one.
+ invalidator_storage_->Clear();
+ invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs()));
+ invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId());
+}
+
void TiclInvalidationService::OnInvalidatorStateChange(
syncer::InvalidatorState state) {
if (state == syncer::INVALIDATION_CREDENTIALS_REJECTED) {
@@ -290,7 +290,8 @@ std::string TiclInvalidationService::GetOwnerName() const { return "TICL"; }
void TiclInvalidationService::Shutdown() {
DCHECK(CalledOnValidThread());
- oauth2_token_service_->RemoveObserver(this);
+ auth_provider_->GetTokenService()->RemoveObserver(this);
+ auth_provider_->RemoveObserver(this);
if (IsStarted()) {
StopInvalidator();
}
@@ -304,20 +305,20 @@ bool TiclInvalidationService::IsReadyToStart() {
return false;
}
- if (signin_manager_->GetAuthenticatedUsername().empty()) {
+ if (auth_provider_->GetAccountId().empty()) {
DVLOG(2) << "Not starting TiclInvalidationService: User is not signed in.";
return false;
}
- if (!oauth2_token_service_) {
+ OAuth2TokenService* token_service = auth_provider_->GetTokenService();
+ if (!token_service) {
DVLOG(2)
<< "Not starting TiclInvalidationService: "
<< "OAuth2TokenService unavailable.";
return false;
}
- if (!oauth2_token_service_->RefreshTokenIsAvailable(
- signin_manager_->GetAuthenticatedAccountId())) {
+ if (!token_service->RefreshTokenIsAvailable(auth_provider_->GetAccountId())) {
DVLOG(2)
<< "Not starting TiclInvalidationServce: Waiting for refresh token.";
return false;
@@ -391,7 +392,7 @@ void TiclInvalidationService::StartInvalidator(
}
void TiclInvalidationService::UpdateInvalidatorCredentials() {
- std::string email = signin_manager_->GetAuthenticatedUsername();
+ std::string email = auth_provider_->GetAccountId();
DCHECK(!email.empty()) << "Expected user to be signed in.";
@@ -405,19 +406,4 @@ void TiclInvalidationService::StopInvalidator() {
invalidator_.reset();
}
-void TiclInvalidationService::Logout() {
- access_token_request_.reset();
- request_access_token_retry_timer_.Stop();
-
- if (IsStarted()) {
- StopInvalidator();
- }
-
- // This service always expects to have a valid invalidator storage.
- // So we must not only clear the old one, but also start a new one.
- invalidator_storage_->Clear();
- invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs()));
- invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId());
-}
-
} // namespace invalidation

Powered by Google App Engine
This is Rietveld 408576698