| 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_wapi_service.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_wapi_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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } // namespace | 67 } // namespace |
| 68 | 68 |
| 69 GDataWapiService::GDataWapiService() | 69 GDataWapiService::GDataWapiService() |
| 70 : profile_(NULL), | 70 : profile_(NULL), |
| 71 runner_(NULL) { | 71 runner_(NULL) { |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 GDataWapiService::~GDataWapiService() { | 75 GDataWapiService::~GDataWapiService() { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 77 if (runner_.get()) | 77 if (runner_.get()) { |
| 78 runner_->operation_registry()->RemoveObserver(this); |
| 78 runner_->auth_service()->RemoveObserver(this); | 79 runner_->auth_service()->RemoveObserver(this); |
| 80 } |
| 79 } | 81 } |
| 80 | 82 |
| 81 AuthService* GDataWapiService::auth_service_for_testing() { | 83 AuthService* GDataWapiService::auth_service_for_testing() { |
| 82 return runner_->auth_service(); | 84 return runner_->auth_service(); |
| 83 } | 85 } |
| 84 | 86 |
| 85 void GDataWapiService::Initialize(Profile* profile) { | 87 void GDataWapiService::Initialize(Profile* profile) { |
| 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 87 profile_ = profile; | 89 profile_ = profile; |
| 88 | 90 |
| 89 std::vector<std::string> scopes; | 91 std::vector<std::string> scopes; |
| 90 scopes.push_back(kDocsListScope); | 92 scopes.push_back(kDocsListScope); |
| 91 scopes.push_back(kSpreadsheetsScope); | 93 scopes.push_back(kSpreadsheetsScope); |
| 92 scopes.push_back(kUserContentScope); | 94 scopes.push_back(kUserContentScope); |
| 93 // Drive App scope is required for even WAPI v3 apps access. | 95 // Drive App scope is required for even WAPI v3 apps access. |
| 94 scopes.push_back(kDriveAppsScope); | 96 scopes.push_back(kDriveAppsScope); |
| 95 runner_.reset(new OperationRunner(profile, scopes)); | 97 runner_.reset(new OperationRunner(profile, scopes)); |
| 96 runner_->Initialize(); | 98 runner_->Initialize(); |
| 97 | 99 |
| 98 runner_->auth_service()->AddObserver(this); | 100 runner_->auth_service()->AddObserver(this); |
| 101 runner_->operation_registry()->AddObserver(this); |
| 99 } | 102 } |
| 100 | 103 |
| 101 void GDataWapiService::AddObserver(DriveServiceObserver* observer) { | 104 void GDataWapiService::AddObserver(DriveServiceObserver* observer) { |
| 102 observers_.AddObserver(observer); | 105 observers_.AddObserver(observer); |
| 103 } | 106 } |
| 104 | 107 |
| 105 void GDataWapiService::RemoveObserver(DriveServiceObserver* observer) { | 108 void GDataWapiService::RemoveObserver(DriveServiceObserver* observer) { |
| 106 observers_.RemoveObserver(observer); | 109 observers_.RemoveObserver(observer); |
| 107 } | 110 } |
| 108 | 111 |
| 109 OperationRegistry* GDataWapiService::operation_registry() const { | |
| 110 return runner_->operation_registry(); | |
| 111 } | |
| 112 | |
| 113 bool GDataWapiService::CanStartOperation() const { | 112 bool GDataWapiService::CanStartOperation() const { |
| 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 115 | 114 |
| 116 return HasRefreshToken(); | 115 return HasRefreshToken(); |
| 117 } | 116 } |
| 118 | 117 |
| 119 void GDataWapiService::CancelAll() { | 118 void GDataWapiService::CancelAll() { |
| 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 121 runner_->CancelAll(); | 120 runner_->CancelAll(); |
| 122 } | 121 } |
| 123 | 122 |
| 123 bool GDataWapiService::CancelForFilePath(const FilePath& file_path) { |
| 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 125 return operation_registry()->CancelForFilePath(file_path); |
| 126 } |
| 127 |
| 128 OperationProgressStatusList GDataWapiService::GetProgressStatusList() const { |
| 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 130 return operation_registry()->GetProgressStatusList(); |
| 131 } |
| 132 |
| 124 void GDataWapiService::Authenticate(const AuthStatusCallback& callback) { | 133 void GDataWapiService::Authenticate(const AuthStatusCallback& callback) { |
| 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 126 runner_->Authenticate(callback); | 135 runner_->Authenticate(callback); |
| 127 } | 136 } |
| 128 | 137 |
| 129 void GDataWapiService::GetDocuments(const GURL& url, | 138 void GDataWapiService::GetDocuments(const GURL& url, |
| 130 int64 start_changestamp, | 139 int64 start_changestamp, |
| 131 const std::string& search_query, | 140 const std::string& search_query, |
| 132 const std::string& directory_resource_id, | 141 const std::string& directory_resource_id, |
| 133 const GetDataCallback& callback) { | 142 const GetDataCallback& callback) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 316 |
| 308 return runner_->auth_service()->HasAccessToken(); | 317 return runner_->auth_service()->HasAccessToken(); |
| 309 } | 318 } |
| 310 | 319 |
| 311 bool GDataWapiService::HasRefreshToken() const { | 320 bool GDataWapiService::HasRefreshToken() const { |
| 312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 313 | 322 |
| 314 return runner_->auth_service()->HasRefreshToken(); | 323 return runner_->auth_service()->HasRefreshToken(); |
| 315 } | 324 } |
| 316 | 325 |
| 326 OperationRegistry* GDataWapiService::operation_registry() const { |
| 327 return runner_->operation_registry(); |
| 328 } |
| 329 |
| 317 void GDataWapiService::OnOAuth2RefreshTokenChanged() { | 330 void GDataWapiService::OnOAuth2RefreshTokenChanged() { |
| 318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 319 if (CanStartOperation()) { | 332 if (CanStartOperation()) { |
| 320 FOR_EACH_OBSERVER( | 333 FOR_EACH_OBSERVER( |
| 321 DriveServiceObserver, observers_, OnReadyToPerformOperations()); | 334 DriveServiceObserver, observers_, OnReadyToPerformOperations()); |
| 322 } | 335 } |
| 323 } | 336 } |
| 324 | 337 |
| 338 void GDataWapiService::OnProgressUpdate( |
| 339 const OperationProgressStatusList& list) { |
| 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 341 FOR_EACH_OBSERVER( |
| 342 DriveServiceObserver, observers_, OnProgressUpdate(list)); |
| 343 } |
| 344 |
| 345 void GDataWapiService::OnAuthenticationFailed() { |
| 346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 347 FOR_EACH_OBSERVER( |
| 348 DriveServiceObserver, observers_, OnAuthenticationFailed()); |
| 349 } |
| 350 |
| 325 } // namespace gdata | 351 } // namespace gdata |
| OLD | NEW |