Chromium Code Reviews| 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/google_apis/gdata_wapi_service.h" | 5 #include "chrome/browser/google_apis/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" |
| 11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 12 #include "chrome/browser/google_apis/auth_service.h" | 12 #include "chrome/browser/google_apis/auth_service.h" |
| 13 #include "chrome/browser/google_apis/gdata_wapi_operations.h" | 13 #include "chrome/browser/google_apis/gdata_wapi_operations.h" |
| 14 #include "chrome/browser/google_apis/gdata_wapi_url_util.h" | |
| 14 #include "chrome/browser/google_apis/operation_runner.h" | 15 #include "chrome/browser/google_apis/operation_runner.h" |
| 15 #include "chrome/browser/google_apis/time_util.h" | 16 #include "chrome/browser/google_apis/time_util.h" |
| 16 #include "chrome/common/net/url_util.h" | 17 #include "chrome/common/net/url_util.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 | 19 |
| 19 using content::BrowserThread; | 20 using content::BrowserThread; |
| 20 | 21 |
| 21 namespace google_apis { | 22 namespace google_apis { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 60 |
| 60 // OAuth2 scopes for the documents API. | 61 // OAuth2 scopes for the documents API. |
| 61 const char kDocsListScope[] = "https://docs.google.com/feeds/"; | 62 const char kDocsListScope[] = "https://docs.google.com/feeds/"; |
| 62 const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/"; | 63 const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/"; |
| 63 const char kUserContentScope[] = "https://docs.googleusercontent.com/"; | 64 const char kUserContentScope[] = "https://docs.googleusercontent.com/"; |
| 64 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps"; | 65 const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps"; |
| 65 | 66 |
| 66 } // namespace | 67 } // namespace |
| 67 | 68 |
| 68 GDataWapiService::GDataWapiService() | 69 GDataWapiService::GDataWapiService() |
| 69 : runner_(NULL) { | 70 : runner_(NULL), |
| 71 url_generator_(gdata_wapi_url_util::kBaseUrlForProduction) { | |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 71 } | 73 } |
| 72 | 74 |
| 73 GDataWapiService::~GDataWapiService() { | 75 GDataWapiService::~GDataWapiService() { |
| 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 75 if (runner_.get()) { | 77 if (runner_.get()) { |
| 76 runner_->operation_registry()->RemoveObserver(this); | 78 runner_->operation_registry()->RemoveObserver(this); |
| 77 runner_->auth_service()->RemoveObserver(this); | 79 runner_->auth_service()->RemoveObserver(this); |
| 78 } | 80 } |
| 79 } | 81 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 bool shared_with_me, | 141 bool shared_with_me, |
| 140 const std::string& directory_resource_id, | 142 const std::string& directory_resource_id, |
| 141 const GetDataCallback& callback) { | 143 const GetDataCallback& callback) { |
| 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 143 | 145 |
| 144 // Drive V2 API defines changestamp in int64, while DocumentsList API uses | 146 // Drive V2 API defines changestamp in int64, while DocumentsList API uses |
| 145 // int32. This narrowing should not cause any trouble. | 147 // int32. This narrowing should not cause any trouble. |
| 146 GetDocumentsOperation* operation = | 148 GetDocumentsOperation* operation = |
| 147 new google_apis::GetDocumentsOperation( | 149 new google_apis::GetDocumentsOperation( |
| 148 operation_registry(), | 150 operation_registry(), |
| 151 url_generator_, | |
| 149 url, | 152 url, |
| 150 static_cast<int>(start_changestamp), | 153 static_cast<int>(start_changestamp), |
| 151 search_query, | 154 search_query, |
| 152 shared_with_me, | 155 shared_with_me, |
| 153 directory_resource_id, | 156 directory_resource_id, |
| 154 callback); | 157 callback); |
| 155 runner_->StartOperationWithRetry(operation); | 158 runner_->StartOperationWithRetry(operation); |
| 156 } | 159 } |
| 157 | 160 |
| 158 void GDataWapiService::GetDocumentEntry( | 161 void GDataWapiService::GetDocumentEntry( |
| 159 const std::string& resource_id, | 162 const std::string& resource_id, |
| 160 const GetDataCallback& callback) { | 163 const GetDataCallback& callback) { |
| 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 162 | 165 |
| 163 GetDocumentEntryOperation* operation = | 166 GetDocumentEntryOperation* operation = |
| 164 new GetDocumentEntryOperation(operation_registry(), | 167 new GetDocumentEntryOperation(operation_registry(), |
| 168 url_generator_, | |
| 165 resource_id, | 169 resource_id, |
| 166 callback); | 170 callback); |
| 167 runner_->StartOperationWithRetry(operation); | 171 runner_->StartOperationWithRetry(operation); |
| 168 } | 172 } |
| 169 | 173 |
| 170 void GDataWapiService::GetAccountMetadata(const GetDataCallback& callback) { | 174 void GDataWapiService::GetAccountMetadata(const GetDataCallback& callback) { |
| 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 172 | 176 |
| 173 GetAccountMetadataOperation* operation = | 177 GetAccountMetadataOperation* operation = |
| 174 new GetAccountMetadataOperation( | 178 new GetAccountMetadataOperation( |
| 175 operation_registry(), callback); | 179 operation_registry(), url_generator_, callback); |
| 176 runner_->StartOperationWithRetry(operation); | 180 runner_->StartOperationWithRetry(operation); |
| 177 } | 181 } |
| 178 | 182 |
| 179 void GDataWapiService::GetApplicationInfo( | 183 void GDataWapiService::GetApplicationInfo( |
| 180 const GetDataCallback& callback) { | 184 const GetDataCallback& callback) { |
| 181 // For WAPI, AccountMetadata includes Drive application information. | 185 // For WAPI, AccountMetadata includes Drive application information. |
| 182 GetAccountMetadata(callback); | 186 GetAccountMetadata(callback); |
| 183 } | 187 } |
| 184 | 188 |
| 185 void GDataWapiService::DownloadDocument( | 189 void GDataWapiService::DownloadDocument( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 document_url)); | 229 document_url)); |
| 226 } | 230 } |
| 227 | 231 |
| 228 void GDataWapiService::AddNewDirectory( | 232 void GDataWapiService::AddNewDirectory( |
| 229 const GURL& parent_content_url, | 233 const GURL& parent_content_url, |
| 230 const FilePath::StringType& directory_name, | 234 const FilePath::StringType& directory_name, |
| 231 const GetDataCallback& callback) { | 235 const GetDataCallback& callback) { |
| 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 233 | 237 |
| 234 runner_->StartOperationWithRetry( | 238 runner_->StartOperationWithRetry( |
| 235 new CreateDirectoryOperation( | 239 new CreateDirectoryOperation( |
|
hashimoto
2012/11/20 09:10:17
nit: Can't we save one newline here?
satorux1
2012/11/21 00:34:18
Done.
| |
| 236 operation_registry(), callback, parent_content_url, directory_name)); | 240 operation_registry(), |
| 241 url_generator_, | |
| 242 callback, | |
| 243 parent_content_url, | |
| 244 directory_name)); | |
| 237 } | 245 } |
| 238 | 246 |
| 239 void GDataWapiService::CopyDocument( | 247 void GDataWapiService::CopyDocument( |
| 240 const std::string& resource_id, | 248 const std::string& resource_id, |
| 241 const FilePath::StringType& new_name, | 249 const FilePath::StringType& new_name, |
| 242 const GetDataCallback& callback) { | 250 const GetDataCallback& callback) { |
| 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 244 | 252 |
| 245 runner_->StartOperationWithRetry( | 253 runner_->StartOperationWithRetry( |
| 246 new CopyDocumentOperation(operation_registry(), callback, | 254 new CopyDocumentOperation(operation_registry(), |
| 247 resource_id, new_name)); | 255 url_generator_, |
| 256 callback, | |
| 257 resource_id, | |
| 258 new_name)); | |
| 248 } | 259 } |
| 249 | 260 |
| 250 void GDataWapiService::RenameResource( | 261 void GDataWapiService::RenameResource( |
| 251 const GURL& resource_url, | 262 const GURL& resource_url, |
| 252 const FilePath::StringType& new_name, | 263 const FilePath::StringType& new_name, |
| 253 const EntryActionCallback& callback) { | 264 const EntryActionCallback& callback) { |
| 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 255 | 266 |
| 256 runner_->StartOperationWithRetry( | 267 runner_->StartOperationWithRetry( |
| 257 new RenameResourceOperation(operation_registry(), callback, | 268 new RenameResourceOperation(operation_registry(), callback, |
| 258 resource_url, new_name)); | 269 resource_url, new_name)); |
| 259 } | 270 } |
| 260 | 271 |
| 261 void GDataWapiService::AddResourceToDirectory( | 272 void GDataWapiService::AddResourceToDirectory( |
| 262 const GURL& parent_content_url, | 273 const GURL& parent_content_url, |
| 263 const GURL& resource_url, | 274 const GURL& resource_url, |
| 264 const EntryActionCallback& callback) { | 275 const EntryActionCallback& callback) { |
| 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 266 | 277 |
| 267 runner_->StartOperationWithRetry( | 278 runner_->StartOperationWithRetry( |
| 268 new AddResourceToDirectoryOperation(operation_registry(), | 279 new AddResourceToDirectoryOperation(operation_registry(), |
| 280 url_generator_, | |
| 269 callback, | 281 callback, |
| 270 parent_content_url, | 282 parent_content_url, |
| 271 resource_url)); | 283 resource_url)); |
| 272 } | 284 } |
| 273 | 285 |
| 274 void GDataWapiService::RemoveResourceFromDirectory( | 286 void GDataWapiService::RemoveResourceFromDirectory( |
| 275 const GURL& parent_content_url, | 287 const GURL& parent_content_url, |
| 276 const GURL& resource_url, | 288 const GURL& resource_url, |
| 277 const std::string& resource_id, | 289 const std::string& resource_id, |
| 278 const EntryActionCallback& callback) { | 290 const EntryActionCallback& callback) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 DriveServiceObserver, observers_, OnProgressUpdate(list)); | 365 DriveServiceObserver, observers_, OnProgressUpdate(list)); |
| 354 } | 366 } |
| 355 | 367 |
| 356 void GDataWapiService::OnAuthenticationFailed(GDataErrorCode error) { | 368 void GDataWapiService::OnAuthenticationFailed(GDataErrorCode error) { |
| 357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 358 FOR_EACH_OBSERVER( | 370 FOR_EACH_OBSERVER( |
| 359 DriveServiceObserver, observers_, OnAuthenticationFailed(error)); | 371 DriveServiceObserver, observers_, OnAuthenticationFailed(error)); |
| 360 } | 372 } |
| 361 | 373 |
| 362 } // namespace google_apis | 374 } // namespace google_apis |
| OLD | NEW |