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

Side by Side Diff: chrome/browser/chromeos/gdata/operation_runner.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/gdata/operation_runner.h"
6
7 #include "base/bind.h"
8 #include "chrome/browser/chromeos/gdata/auth_service.h"
9 #include "chrome/browser/google_apis/operations_base.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_thread.h"
12
13 using content::BrowserThread;
14
15 namespace gdata {
16
17 OperationRunner::OperationRunner(Profile* profile,
18 const std::vector<std::string>& scopes)
19 : profile_(profile),
20 auth_service_(new AuthService(scopes)),
21 operation_registry_(new OperationRegistry()),
22 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
24 }
25
26 OperationRunner::~OperationRunner() {
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
28 }
29
30 void OperationRunner::Initialize() {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
32 auth_service_->Initialize(profile_);
33 }
34
35 void OperationRunner::CancelAll() {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 operation_registry_->CancelAll();
38 }
39
40 void OperationRunner::Authenticate(const AuthStatusCallback& callback) {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
42 auth_service_->StartAuthentication(operation_registry_.get(), callback);
43 }
44
45 void OperationRunner::StartOperationWithRetry(
46 AuthenticatedOperationInterface* operation) {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48
49 // The re-authentication callback will run on UI thread.
50 operation->SetReAuthenticateCallback(
51 base::Bind(&OperationRunner::RetryOperation,
52 weak_ptr_factory_.GetWeakPtr()));
53 StartOperation(operation);
54 }
55
56 void OperationRunner::StartOperation(
57 AuthenticatedOperationInterface* operation) {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59
60 if (!auth_service_->HasAccessToken()) {
61 // Fetch OAuth2 authentication token from the refresh token first.
62 auth_service_->StartAuthentication(
63 operation_registry_.get(),
64 base::Bind(&OperationRunner::OnOperationAuthRefresh,
65 weak_ptr_factory_.GetWeakPtr(),
66 operation));
67 return;
68 }
69
70 operation->Start(auth_service_->access_token());
71 }
72
73 void OperationRunner::OnOperationAuthRefresh(
74 AuthenticatedOperationInterface* operation,
75 GDataErrorCode code,
76 const std::string& auth_token) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
78
79 if (code == HTTP_SUCCESS) {
80 DCHECK(auth_service_->HasRefreshToken());
81 StartOperation(operation);
82 } else {
83 operation->OnAuthFailed(code);
84 }
85 }
86
87 void OperationRunner::RetryOperation(
88 AuthenticatedOperationInterface* operation) {
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
90
91 auth_service_->ClearAccessToken();
92 // User authentication might have expired - rerun the request to force
93 // auth token refresh.
94 StartOperation(operation);
95 }
96
97 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/operation_runner.h ('k') | chrome/browser/chromeos/gdata/stale_cache_files_remover_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698