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" |
11 | 11 |
12 using content::BrowserThread; | 12 using content::BrowserThread; |
13 | 13 |
14 namespace gdata { | 14 namespace gdata { |
15 | 15 |
16 GDataOperationRunner::GDataOperationRunner(Profile* profile) | 16 GDataOperationRunner::GDataOperationRunner(Profile* profile) |
17 : profile_(profile), | 17 : profile_(profile), |
18 auth_service_(new GDataAuthService()), | 18 auth_service_(new GDataAuthService()), |
19 operation_registry_(new GDataOperationRegistry()), | 19 operation_registry_(new GDataOperationRegistry()), |
20 weak_ptr_factory_(this), | 20 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
21 weak_ptr_bound_to_ui_thread_(weak_ptr_factory_.GetWeakPtr()) { | |
22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
23 auth_service_->AddObserver(this); | 22 auth_service_->AddObserver(this); |
24 } | 23 } |
25 | 24 |
26 GDataOperationRunner::~GDataOperationRunner() { | 25 GDataOperationRunner::~GDataOperationRunner() { |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
28 auth_service_->RemoveObserver(this); | 27 auth_service_->RemoveObserver(this); |
29 } | 28 } |
30 | 29 |
31 void GDataOperationRunner::Initialize() { | 30 void GDataOperationRunner::Initialize() { |
(...skipping 11 matching lines...) Expand all Loading... |
43 auth_service_->StartAuthentication(operation_registry_.get(), callback); | 42 auth_service_->StartAuthentication(operation_registry_.get(), callback); |
44 } | 43 } |
45 | 44 |
46 void GDataOperationRunner::StartOperationWithRetry( | 45 void GDataOperationRunner::StartOperationWithRetry( |
47 GDataOperationInterface* operation) { | 46 GDataOperationInterface* operation) { |
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
49 | 48 |
50 // The re-authenticatation callback will run on UI thread. | 49 // The re-authenticatation callback will run on UI thread. |
51 operation->SetReAuthenticateCallback( | 50 operation->SetReAuthenticateCallback( |
52 base::Bind(&GDataOperationRunner::RetryOperation, | 51 base::Bind(&GDataOperationRunner::RetryOperation, |
53 weak_ptr_bound_to_ui_thread_)); | 52 weak_ptr_factory_.GetWeakPtr())); |
54 StartOperation(operation); | 53 StartOperation(operation); |
55 } | 54 } |
56 | 55 |
57 void GDataOperationRunner::StartOperation(GDataOperationInterface* operation) { | 56 void GDataOperationRunner::StartOperation(GDataOperationInterface* operation) { |
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
59 | 58 |
60 if (!auth_service_->HasAccessToken()) { | 59 if (!auth_service_->HasAccessToken()) { |
61 // Fetch OAuth2 authentication token from the refresh token first. | 60 // Fetch OAuth2 authentication token from the refresh token first. |
62 auth_service_->StartAuthentication( | 61 auth_service_->StartAuthentication( |
63 operation_registry_.get(), | 62 operation_registry_.get(), |
64 base::Bind(&GDataOperationRunner::OnOperationAuthRefresh, | 63 base::Bind(&GDataOperationRunner::OnOperationAuthRefresh, |
65 weak_ptr_bound_to_ui_thread_, | 64 weak_ptr_factory_.GetWeakPtr(), |
66 operation)); | 65 operation)); |
67 return; | 66 return; |
68 } | 67 } |
69 | 68 |
70 operation->Start(auth_service_->access_token()); | 69 operation->Start(auth_service_->access_token()); |
71 } | 70 } |
72 | 71 |
73 void GDataOperationRunner::OnOperationAuthRefresh( | 72 void GDataOperationRunner::OnOperationAuthRefresh( |
74 GDataOperationInterface* operation, | 73 GDataOperationInterface* operation, |
75 GDataErrorCode code, | 74 GDataErrorCode code, |
(...skipping 15 matching lines...) Expand all Loading... |
91 // User authentication might have expired - rerun the request to force | 90 // User authentication might have expired - rerun the request to force |
92 // auth token refresh. | 91 // auth token refresh. |
93 StartOperation(operation); | 92 StartOperation(operation); |
94 } | 93 } |
95 | 94 |
96 void GDataOperationRunner::OnOAuth2RefreshTokenChanged() { | 95 void GDataOperationRunner::OnOAuth2RefreshTokenChanged() { |
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
98 } | 97 } |
99 | 98 |
100 } // namespace gdata | 99 } // namespace gdata |
OLD | NEW |