OLD | NEW |
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/chromeos/gdata/operation_runner.h" | 5 #include "chrome/browser/chromeos/gdata/operation_runner.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/chromeos/gdata/gdata_operations.h" | 8 #include "chrome/browser/chromeos/gdata/operations_base.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.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 gdata { | 14 namespace gdata { |
15 | 15 |
16 OperationRunner::OperationRunner(Profile* profile) | 16 OperationRunner::OperationRunner(Profile* profile) |
17 : profile_(profile), | 17 : profile_(profile), |
18 auth_service_(new AuthService()), | 18 auth_service_(new AuthService()), |
(...skipping 17 matching lines...) Expand all Loading... |
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
37 operation_registry_->CancelAll(); | 37 operation_registry_->CancelAll(); |
38 } | 38 } |
39 | 39 |
40 void OperationRunner::Authenticate(const AuthStatusCallback& callback) { | 40 void OperationRunner::Authenticate(const AuthStatusCallback& callback) { |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
42 auth_service_->StartAuthentication(operation_registry_.get(), callback); | 42 auth_service_->StartAuthentication(operation_registry_.get(), callback); |
43 } | 43 } |
44 | 44 |
45 void OperationRunner::StartOperationWithRetry( | 45 void OperationRunner::StartOperationWithRetry( |
46 GDataOperationInterface* operation) { | 46 AuthenticatedOperationInterface* operation) { |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
48 | 48 |
49 // The re-authenticatation callback will run on UI thread. | 49 // The re-authenticatation callback will run on UI thread. |
50 operation->SetReAuthenticateCallback( | 50 operation->SetReAuthenticateCallback( |
51 base::Bind(&OperationRunner::RetryOperation, | 51 base::Bind(&OperationRunner::RetryOperation, |
52 weak_ptr_factory_.GetWeakPtr())); | 52 weak_ptr_factory_.GetWeakPtr())); |
53 StartOperation(operation); | 53 StartOperation(operation); |
54 } | 54 } |
55 | 55 |
56 void OperationRunner::StartOperation(GDataOperationInterface* operation) { | 56 void OperationRunner::StartOperation( |
| 57 AuthenticatedOperationInterface* operation) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
58 | 59 |
59 if (!auth_service_->HasAccessToken()) { | 60 if (!auth_service_->HasAccessToken()) { |
60 // Fetch OAuth2 authentication token from the refresh token first. | 61 // Fetch OAuth2 authentication token from the refresh token first. |
61 auth_service_->StartAuthentication( | 62 auth_service_->StartAuthentication( |
62 operation_registry_.get(), | 63 operation_registry_.get(), |
63 base::Bind(&OperationRunner::OnOperationAuthRefresh, | 64 base::Bind(&OperationRunner::OnOperationAuthRefresh, |
64 weak_ptr_factory_.GetWeakPtr(), | 65 weak_ptr_factory_.GetWeakPtr(), |
65 operation)); | 66 operation)); |
66 return; | 67 return; |
67 } | 68 } |
68 | 69 |
69 operation->Start(auth_service_->access_token()); | 70 operation->Start(auth_service_->access_token()); |
70 } | 71 } |
71 | 72 |
72 void OperationRunner::OnOperationAuthRefresh( | 73 void OperationRunner::OnOperationAuthRefresh( |
73 GDataOperationInterface* operation, | 74 AuthenticatedOperationInterface* operation, |
74 GDataErrorCode code, | 75 GDataErrorCode code, |
75 const std::string& auth_token) { | 76 const std::string& auth_token) { |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
77 | 78 |
78 if (code == HTTP_SUCCESS) { | 79 if (code == HTTP_SUCCESS) { |
79 DCHECK(auth_service_->HasRefreshToken()); | 80 DCHECK(auth_service_->HasRefreshToken()); |
80 StartOperation(operation); | 81 StartOperation(operation); |
81 } else { | 82 } else { |
82 operation->OnAuthFailed(code); | 83 operation->OnAuthFailed(code); |
83 } | 84 } |
84 } | 85 } |
85 | 86 |
86 void OperationRunner::RetryOperation(GDataOperationInterface* operation) { | 87 void OperationRunner::RetryOperation( |
| 88 AuthenticatedOperationInterface* operation) { |
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
88 | 90 |
89 auth_service_->ClearAccessToken(); | 91 auth_service_->ClearAccessToken(); |
90 // User authentication might have expired - rerun the request to force | 92 // User authentication might have expired - rerun the request to force |
91 // auth token refresh. | 93 // auth token refresh. |
92 StartOperation(operation); | 94 StartOperation(operation); |
93 } | 95 } |
94 | 96 |
95 void OperationRunner::OnOAuth2RefreshTokenChanged() { | 97 void OperationRunner::OnOAuth2RefreshTokenChanged() { |
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
97 } | 99 } |
98 | 100 |
99 } // namespace gdata | 101 } // namespace gdata |
OLD | NEW |