| 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/gdata_operation_runner.h" | 5 #include "chrome/browser/chromeos/gdata/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/gdata_operations.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" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // The re-authenticatation callback will run on UI thread. | 50 // The re-authenticatation callback will run on UI thread. |
| 51 operation->SetReAuthenticateCallback( | 51 operation->SetReAuthenticateCallback( |
| 52 base::Bind(&GDataOperationRunner::RetryOperation, | 52 base::Bind(&GDataOperationRunner::RetryOperation, |
| 53 weak_ptr_bound_to_ui_thread_)); | 53 weak_ptr_bound_to_ui_thread_)); |
| 54 StartOperation(operation); | 54 StartOperation(operation); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void GDataOperationRunner::StartOperation(GDataOperationInterface* operation) { | 57 void GDataOperationRunner::StartOperation(GDataOperationInterface* operation) { |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 59 | 59 |
| 60 if (!auth_service_->IsFullyAuthenticated()) { | 60 if (!auth_service_->HasAccessToken()) { |
| 61 // Fetch OAuth2 authentication token from the refresh token first. | 61 // Fetch OAuth2 authentication token from the refresh token first. |
| 62 auth_service_->StartAuthentication( | 62 auth_service_->StartAuthentication( |
| 63 operation_registry_.get(), | 63 operation_registry_.get(), |
| 64 base::Bind(&GDataOperationRunner::OnOperationAuthRefresh, | 64 base::Bind(&GDataOperationRunner::OnOperationAuthRefresh, |
| 65 weak_ptr_bound_to_ui_thread_, | 65 weak_ptr_bound_to_ui_thread_, |
| 66 operation)); | 66 operation)); |
| 67 return; | 67 return; |
| 68 } | 68 } |
| 69 | 69 |
| 70 operation->Start(auth_service_->oauth2_auth_token()); | 70 operation->Start(auth_service_->access_token()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void GDataOperationRunner::OnOperationAuthRefresh( | 73 void GDataOperationRunner::OnOperationAuthRefresh( |
| 74 GDataOperationInterface* operation, | 74 GDataOperationInterface* operation, |
| 75 GDataErrorCode code, | 75 GDataErrorCode code, |
| 76 const std::string& auth_token) { | 76 const std::string& auth_token) { |
| 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 78 | 78 |
| 79 if (code == HTTP_SUCCESS) { | 79 if (code == HTTP_SUCCESS) { |
| 80 DCHECK(auth_service_->IsPartiallyAuthenticated()); | 80 DCHECK(auth_service_->HasRefreshToken()); |
| 81 StartOperation(operation); | 81 StartOperation(operation); |
| 82 } else { | 82 } else { |
| 83 operation->OnAuthFailed(code); | 83 operation->OnAuthFailed(code); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 void GDataOperationRunner::RetryOperation(GDataOperationInterface* operation) { | 87 void GDataOperationRunner::RetryOperation(GDataOperationInterface* operation) { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 89 | 89 |
| 90 auth_service_->ClearOAuth2Token(); | 90 auth_service_->ClearAccessToken(); |
| 91 // User authentication might have expired - rerun the request to force | 91 // User authentication might have expired - rerun the request to force |
| 92 // auth token refresh. | 92 // auth token refresh. |
| 93 StartOperation(operation); | 93 StartOperation(operation); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void GDataOperationRunner::OnOAuth2RefreshTokenChanged() { | 96 void GDataOperationRunner::OnOAuth2RefreshTokenChanged() { |
| 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace gdata | 100 } // namespace gdata |
| OLD | NEW |