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

Side by Side Diff: chrome/browser/google_apis/operation_runner.cc

Issue 16424004: google_apis: Rename base_operations.h/cc to base_requests.h/cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
« no previous file with comments | « chrome/browser/google_apis/operation_runner.h ('k') | chrome/browser/google_apis/test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/google_apis/operation_runner.h" 5 #include "chrome/browser/google_apis/operation_runner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/google_apis/auth_service.h" 8 #include "chrome/browser/google_apis/auth_service.h"
9 #include "chrome/browser/google_apis/base_operations.h" 9 #include "chrome/browser/google_apis/base_requests.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 11
12 using content::BrowserThread; 12 using content::BrowserThread;
13 13
14 namespace google_apis { 14 namespace google_apis {
15 15
16 OperationRunner::OperationRunner( 16 OperationRunner::OperationRunner(
17 Profile* profile, 17 Profile* profile,
18 net::URLRequestContextGetter* url_request_context_getter, 18 net::URLRequestContextGetter* url_request_context_getter,
19 const std::vector<std::string>& scopes, 19 const std::vector<std::string>& scopes,
(...skipping 14 matching lines...) Expand all
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
35 auth_service_->Initialize(profile_); 35 auth_service_->Initialize(profile_);
36 } 36 }
37 37
38 void OperationRunner::CancelAll() { 38 void OperationRunner::CancelAll() {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 operation_registry_->CancelAll(); 40 operation_registry_->CancelAll();
41 } 41 }
42 42
43 void OperationRunner::StartOperationWithRetry( 43 void OperationRunner::StartOperationWithRetry(
44 AuthenticatedOperationInterface* operation) { 44 AuthenticatedRequestInterface* operation) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46 46
47 if (!auth_service_->HasAccessToken()) { 47 if (!auth_service_->HasAccessToken()) {
48 // Fetch OAuth2 access token from the refresh token first. 48 // Fetch OAuth2 access token from the refresh token first.
49 auth_service_->StartAuthentication( 49 auth_service_->StartAuthentication(
50 base::Bind(&OperationRunner::OnAccessTokenFetched, 50 base::Bind(&OperationRunner::OnAccessTokenFetched,
51 weak_ptr_factory_.GetWeakPtr(), 51 weak_ptr_factory_.GetWeakPtr(),
52 operation->GetWeakPtr())); 52 operation->GetWeakPtr()));
53 return; 53 return;
54 } 54 }
55 55
56 operation->Start(auth_service_->access_token(), 56 operation->Start(auth_service_->access_token(),
57 custom_user_agent_, 57 custom_user_agent_,
58 base::Bind(&OperationRunner::RetryOperation, 58 base::Bind(&OperationRunner::RetryOperation,
59 weak_ptr_factory_.GetWeakPtr())); 59 weak_ptr_factory_.GetWeakPtr()));
60 } 60 }
61 61
62 void OperationRunner::OnAccessTokenFetched( 62 void OperationRunner::OnAccessTokenFetched(
63 const base::WeakPtr<AuthenticatedOperationInterface>& operation, 63 const base::WeakPtr<AuthenticatedRequestInterface>& operation,
64 GDataErrorCode code, 64 GDataErrorCode code,
65 const std::string& /* access_token */) { 65 const std::string& /* access_token */) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
67 67
68 // Do nothing if the operation is canceled during authentication. 68 // Do nothing if the operation is canceled during authentication.
69 if (!operation.get()) 69 if (!operation.get())
70 return; 70 return;
71 71
72 if (code == HTTP_SUCCESS) { 72 if (code == HTTP_SUCCESS) {
73 DCHECK(auth_service_->HasAccessToken()); 73 DCHECK(auth_service_->HasAccessToken());
74 StartOperationWithRetry(operation.get()); 74 StartOperationWithRetry(operation.get());
75 } else { 75 } else {
76 operation->OnAuthFailed(code); 76 operation->OnAuthFailed(code);
77 } 77 }
78 } 78 }
79 79
80 void OperationRunner::RetryOperation( 80 void OperationRunner::RetryOperation(
81 AuthenticatedOperationInterface* operation) { 81 AuthenticatedRequestInterface* operation) {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 83
84 auth_service_->ClearAccessToken(); 84 auth_service_->ClearAccessToken();
85 // User authentication might have expired - rerun the request to force 85 // User authentication might have expired - rerun the request to force
86 // auth token refresh. 86 // auth token refresh.
87 StartOperationWithRetry(operation); 87 StartOperationWithRetry(operation);
88 } 88 }
89 89
90 } // namespace google_apis 90 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/operation_runner.h ('k') | chrome/browser/google_apis/test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698