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/drive_api_service.h" | 5 #include "chrome/browser/chromeos/gdata/drive_api_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 DriveAPIService::DriveAPIService() | 33 DriveAPIService::DriveAPIService() |
34 : profile_(NULL), | 34 : profile_(NULL), |
35 runner_(NULL) { | 35 runner_(NULL) { |
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
37 } | 37 } |
38 | 38 |
39 DriveAPIService::~DriveAPIService() { | 39 DriveAPIService::~DriveAPIService() { |
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
41 if (runner_.get()) | 41 if (runner_.get()) { |
| 42 runner_->operation_registry()->RemoveObserver(this); |
42 runner_->auth_service()->RemoveObserver(this); | 43 runner_->auth_service()->RemoveObserver(this); |
| 44 } |
43 } | 45 } |
44 | 46 |
45 void DriveAPIService::Initialize(Profile* profile) { | 47 void DriveAPIService::Initialize(Profile* profile) { |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
47 profile_ = profile; | 49 profile_ = profile; |
48 | 50 |
49 std::vector<std::string> scopes; | 51 std::vector<std::string> scopes; |
50 scopes.push_back(kDriveScope); | 52 scopes.push_back(kDriveScope); |
51 scopes.push_back(kDriveAppsReadonlyScope); | 53 scopes.push_back(kDriveAppsReadonlyScope); |
52 runner_.reset(new OperationRunner(profile, scopes)); | 54 runner_.reset(new OperationRunner(profile, scopes)); |
53 runner_->Initialize(); | 55 runner_->Initialize(); |
54 | 56 |
55 runner_->auth_service()->AddObserver(this); | 57 runner_->auth_service()->AddObserver(this); |
| 58 runner_->operation_registry()->AddObserver(this); |
56 } | 59 } |
57 | 60 |
58 void DriveAPIService::AddObserver(DriveServiceObserver* observer) { | 61 void DriveAPIService::AddObserver(DriveServiceObserver* observer) { |
59 observers_.AddObserver(observer); | 62 observers_.AddObserver(observer); |
60 } | 63 } |
61 | 64 |
62 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) { | 65 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) { |
63 observers_.RemoveObserver(observer); | 66 observers_.RemoveObserver(observer); |
64 } | 67 } |
65 | 68 |
66 OperationRegistry* DriveAPIService::operation_registry() const { | |
67 return runner_->operation_registry(); | |
68 } | |
69 | |
70 bool DriveAPIService::CanStartOperation() const { | 69 bool DriveAPIService::CanStartOperation() const { |
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
72 | 71 |
73 return HasRefreshToken(); | 72 return HasRefreshToken(); |
74 } | 73 } |
75 | 74 |
76 void DriveAPIService::CancelAll() { | 75 void DriveAPIService::CancelAll() { |
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
78 runner_->CancelAll(); | 77 runner_->CancelAll(); |
79 } | 78 } |
80 | 79 |
| 80 bool DriveAPIService::CancelForFilePath(const FilePath& file_path) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 82 return operation_registry()->CancelForFilePath(file_path); |
| 83 } |
| 84 |
| 85 OperationProgressStatusList DriveAPIService::GetProgressStatusList() const { |
| 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 87 return operation_registry()->GetProgressStatusList(); |
| 88 } |
| 89 |
81 void DriveAPIService::Authenticate(const AuthStatusCallback& callback) { | 90 void DriveAPIService::Authenticate(const AuthStatusCallback& callback) { |
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
83 runner_->Authenticate(callback); | 92 runner_->Authenticate(callback); |
84 } | 93 } |
85 | 94 |
86 void DriveAPIService::GetDocuments(const GURL& url, | 95 void DriveAPIService::GetDocuments(const GURL& url, |
87 int64 start_changestamp, | 96 int64 start_changestamp, |
88 const std::string& search_query, | 97 const std::string& search_query, |
89 const std::string& directory_resource_id, | 98 const std::string& directory_resource_id, |
90 const GetDataCallback& callback) { | 99 const GetDataCallback& callback) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 267 |
259 return runner_->auth_service()->HasAccessToken(); | 268 return runner_->auth_service()->HasAccessToken(); |
260 } | 269 } |
261 | 270 |
262 bool DriveAPIService::HasRefreshToken() const { | 271 bool DriveAPIService::HasRefreshToken() const { |
263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
264 | 273 |
265 return runner_->auth_service()->HasRefreshToken(); | 274 return runner_->auth_service()->HasRefreshToken(); |
266 } | 275 } |
267 | 276 |
| 277 OperationRegistry* DriveAPIService::operation_registry() const { |
| 278 return runner_->operation_registry(); |
| 279 } |
| 280 |
268 void DriveAPIService::OnOAuth2RefreshTokenChanged() { | 281 void DriveAPIService::OnOAuth2RefreshTokenChanged() { |
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
270 if (CanStartOperation()) { | 283 if (CanStartOperation()) { |
271 FOR_EACH_OBSERVER( | 284 FOR_EACH_OBSERVER( |
272 DriveServiceObserver, observers_, OnReadyToPerformOperations()); | 285 DriveServiceObserver, observers_, OnReadyToPerformOperations()); |
273 } | 286 } |
274 } | 287 } |
275 | 288 |
| 289 void DriveAPIService::OnProgressUpdate( |
| 290 const OperationProgressStatusList& list) { |
| 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 292 FOR_EACH_OBSERVER( |
| 293 DriveServiceObserver, observers_, OnProgressUpdate(list)); |
| 294 } |
| 295 |
| 296 void DriveAPIService::OnAuthenticationFailed() { |
| 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 298 FOR_EACH_OBSERVER( |
| 299 DriveServiceObserver, observers_, OnAuthenticationFailed()); |
| 300 } |
| 301 |
276 } // namespace gdata | 302 } // namespace gdata |
OLD | NEW |