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

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

Issue 10920091: Move Drive API files to google_apis directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reflect comments Created 8 years, 3 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/auth_service.cc
diff --git a/chrome/browser/chromeos/gdata/auth_service.cc b/chrome/browser/chromeos/gdata/auth_service.cc
deleted file mode 100644
index d2d7c0b36d093c326b34e7fecb5e593fa9366f1b..0000000000000000000000000000000000000000
--- a/chrome/browser/chromeos/gdata/auth_service.cc
+++ /dev/null
@@ -1,128 +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/auth_service.h"
-
-#include <string>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/message_loop_proxy.h"
-#include "chrome/browser/google_apis/operations_base.h"
-#include "chrome/browser/google_apis/task_util.h"
-#include "chrome/browser/signin/token_service.h"
-#include "chrome/browser/signin/token_service_factory.h"
-#include "chrome/common/chrome_notification_types.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"
-#include "google_apis/gaia/gaia_constants.h"
-
-using content::BrowserThread;
-
-namespace gdata {
-
-void AuthService::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());
-}
-
-AuthService::AuthService(const std::vector<std::string>& scopes)
- : profile_(NULL),
- scopes_(scopes),
- ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-}
-
-AuthService::~AuthService() {
-}
-
-void AuthService::StartAuthentication(OperationRegistry* 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(&AuthService::StartAuthenticationOnUIThread,
- weak_ptr_factory_.GetWeakPtr(),
- registry,
- CreateRelayCallback(
- base::Bind(&AuthService::OnAuthCompleted,
- weak_ptr_factory_.GetWeakPtr(),
- callback))));
- } else {
- relay_proxy->PostTask(FROM_HERE,
- base::Bind(callback, gdata::GDATA_NOT_READY, std::string()));
- }
-}
-
-void AuthService::StartAuthenticationOnUIThread(
- OperationRegistry* registry,
- const AuthStatusCallback& callback) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // We have refresh token, let's gets authenticated.
- (new AuthOperation(registry, callback, scopes_, refresh_token_))->Start();
-}
-
-void AuthService::OnAuthCompleted(const AuthStatusCallback& callback,
- GDataErrorCode error,
- const std::string& access_token) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(!callback.is_null());
-
- if (error == HTTP_SUCCESS)
- access_token_ = access_token;
-
- // TODO(zelidrag): Add retry, back-off logic when things go wrong here.
- callback.Run(error, access_token);
-}
-
-void AuthService::AddObserver(Observer* observer) {
- observers_.AddObserver(observer);
-}
-
-void AuthService::RemoveObserver(Observer* observer) {
- observers_.RemoveObserver(observer);
-}
-
-void AuthService::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/auth_service.h ('k') | chrome/browser/chromeos/gdata/document_entry_conversion.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698