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

Unified Diff: chrome/browser/chromeos/gdata/gdata_auth_service.cc

Issue 10837338: Remove "GData" prefix from non-GData specific classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 4 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/chromeos/gdata/gdata_auth_service.cc
diff --git a/chrome/browser/chromeos/gdata/gdata_auth_service.cc b/chrome/browser/chromeos/gdata/gdata_auth_service.cc
deleted file mode 100644
index 0d71bac73e43d2a93e291d5f8125259a5ff37d74..0000000000000000000000000000000000000000
--- a/chrome/browser/chromeos/gdata/gdata_auth_service.cc
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright (c) 2012 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/gdata/gdata_auth_service.h"
-
-#include <string>
-
-#include "base/bind.h"
-#include "base/message_loop_proxy.h"
-#include "chrome/browser/chromeos/gdata/gdata_operations.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/signin/token_service.h"
-#include "chrome/browser/signin/token_service_factory.h"
-#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/net/gaia/gaia_constants.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
-#include "content/public/browser/notification_types.h"
-
-using content::BrowserThread;
-
-namespace gdata {
-
-void GDataAuthService::Initialize(Profile* profile) {
- profile_ = profile;
- // Get OAuth2 refresh token (if we have any) and register for its updates.
- TokenService* service = TokenServiceFactory::GetForProfile(profile_);
- refresh_token_ = service->GetOAuth2LoginRefreshToken();
- registrar_.Add(this,
- chrome::NOTIFICATION_TOKEN_AVAILABLE,
- content::Source<TokenService>(service));
- registrar_.Add(this,
- chrome::NOTIFICATION_TOKEN_REQUEST_FAILED,
- content::Source<TokenService>(service));
-
- if (!refresh_token_.empty())
- FOR_EACH_OBSERVER(Observer, observers_, OnOAuth2RefreshTokenChanged());
-}
-
-GDataAuthService::GDataAuthService()
- : profile_(NULL),
- weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-}
-
-GDataAuthService::~GDataAuthService() {
-}
-
-void GDataAuthService::StartAuthentication(
- GDataOperationRegistry* registry,
- const AuthStatusCallback& callback) {
- scoped_refptr<base::MessageLoopProxy> relay_proxy(
- base::MessageLoopProxy::current());
-
- if (HasAccessToken()) {
- relay_proxy->PostTask(FROM_HERE,
- base::Bind(callback, gdata::HTTP_SUCCESS, access_token_));
- } else if (HasRefreshToken()) {
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- base::Bind(&GDataAuthService::StartAuthenticationOnUIThread,
- weak_ptr_factory_.GetWeakPtr(),
- registry,
- relay_proxy,
- base::Bind(&GDataAuthService::OnAuthCompleted,
- weak_ptr_factory_.GetWeakPtr(),
- relay_proxy,
- callback)));
- } else {
- relay_proxy->PostTask(FROM_HERE,
- base::Bind(callback, gdata::HTTP_UNAUTHORIZED, std::string()));
- }
-}
-
-void GDataAuthService::StartAuthenticationOnUIThread(
- GDataOperationRegistry* registry,
- scoped_refptr<base::MessageLoopProxy> relay_proxy,
- const AuthStatusCallback& callback) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // We have refresh token, let's gets authenticated.
- (new AuthOperation(registry, callback, refresh_token_))->Start();
-}
-
-void GDataAuthService::OnAuthCompleted(
- scoped_refptr<base::MessageLoopProxy> relay_proxy,
- const AuthStatusCallback& callback,
- GDataErrorCode error,
- const std::string& access_token) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- if (error == HTTP_SUCCESS)
- access_token_ = access_token;
-
- // TODO(zelidrag): Add retry, back-off logic when things go wrong here.
- if (!callback.is_null())
- relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error, access_token));
-}
-
-void GDataAuthService::AddObserver(Observer* observer) {
- observers_.AddObserver(observer);
-}
-
-void GDataAuthService::RemoveObserver(Observer* observer) {
- observers_.RemoveObserver(observer);
-}
-
-void GDataAuthService::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE ||
- type == chrome::NOTIFICATION_TOKEN_REQUEST_FAILED);
-
- TokenService::TokenAvailableDetails* token_details =
- content::Details<TokenService::TokenAvailableDetails>(details).ptr();
- if (token_details->service() != GaiaConstants::kGaiaOAuth2LoginRefreshToken)
- return;
-
- access_token_.clear();
- if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) {
- TokenService* service = TokenServiceFactory::GetForProfile(profile_);
- refresh_token_ = service->GetOAuth2LoginRefreshToken();
- } else {
- refresh_token_.clear();
- }
- FOR_EACH_OBSERVER(Observer, observers_, OnOAuth2RefreshTokenChanged());
-}
-
-} // namespace gdata
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_auth_service.h ('k') | chrome/browser/chromeos/gdata/gdata_contacts_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698