| 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_documents_service.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_wapi_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "chrome/browser/chromeos/gdata/drive_api_operations.h" | 11 #include "chrome/browser/chromeos/gdata/drive_api_operations.h" |
| 12 #include "chrome/browser/chromeos/gdata/gdata_operation_runner.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_operation_runner.h" |
| 13 #include "chrome/browser/chromeos/gdata/gdata_operations.h" | 13 #include "chrome/browser/chromeos/gdata/gdata_operations.h" |
| 14 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 14 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 return "ods"; | 52 return "ods"; |
| 53 case TSV: | 53 case TSV: |
| 54 return "tsv"; | 54 return "tsv"; |
| 55 default: | 55 default: |
| 56 return "pdf"; | 56 return "pdf"; |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 DocumentsService::DocumentsService() | 62 GDataWapiService::GDataWapiService() |
| 63 : profile_(NULL), | 63 : profile_(NULL), |
| 64 runner_(NULL) { | 64 runner_(NULL) { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 DocumentsService::~DocumentsService() { | 68 GDataWapiService::~GDataWapiService() { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 GDataAuthService* DocumentsService::auth_service_for_testing() { | 72 GDataAuthService* GDataWapiService::auth_service_for_testing() { |
| 73 return runner_->auth_service(); | 73 return runner_->auth_service(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void DocumentsService::Initialize(Profile* profile) { | 76 void GDataWapiService::Initialize(Profile* profile) { |
| 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 78 profile_ = profile; | 78 profile_ = profile; |
| 79 runner_.reset(new GDataOperationRunner(profile)); | 79 runner_.reset(new GDataOperationRunner(profile)); |
| 80 runner_->Initialize(); | 80 runner_->Initialize(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 GDataOperationRegistry* DocumentsService::operation_registry() const { | 83 GDataOperationRegistry* GDataWapiService::operation_registry() const { |
| 84 return runner_->operation_registry(); | 84 return runner_->operation_registry(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void DocumentsService::CancelAll() { | 87 void GDataWapiService::CancelAll() { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 89 runner_->CancelAll(); | 89 runner_->CancelAll(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void DocumentsService::Authenticate(const AuthStatusCallback& callback) { | 92 void GDataWapiService::Authenticate(const AuthStatusCallback& callback) { |
| 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 94 runner_->Authenticate(callback); | 94 runner_->Authenticate(callback); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void DocumentsService::GetDocuments(const GURL& url, | 97 void GDataWapiService::GetDocuments(const GURL& url, |
| 98 int start_changestamp, | 98 int64 start_changestamp, |
| 99 const std::string& search_query, | 99 const std::string& search_query, |
| 100 const std::string& directory_resource_id, | 100 const std::string& directory_resource_id, |
| 101 const GetDataCallback& callback) { | 101 const GetDataCallback& callback) { |
| 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 103 | 103 |
| 104 // Drive V2 API defines changestamp in int64, while DocumentsList API uses |
| 105 // int32. This narrowing should not cause any trouble. |
| 104 GetDocumentsOperation* operation = | 106 GetDocumentsOperation* operation = |
| 105 new GetDocumentsOperation(operation_registry(), | 107 new GetDocumentsOperation(operation_registry(), |
| 106 url, | 108 url, |
| 107 start_changestamp, | 109 static_cast<int>(start_changestamp), |
| 108 search_query, | 110 search_query, |
| 109 directory_resource_id, | 111 directory_resource_id, |
| 110 callback); | 112 callback); |
| 111 runner_->StartOperationWithRetry(operation); | 113 runner_->StartOperationWithRetry(operation); |
| 112 } | 114 } |
| 113 | 115 |
| 114 void DocumentsService::GetFilelist(const GURL& url, | 116 void GDataWapiService::GetDocumentEntry(const std::string& resource_id, |
| 115 const std::string& search_query, | |
| 116 const GetDataCallback& callback) { | |
| 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 118 | |
| 119 GetFilelistOperation* operation = | |
| 120 new GetFilelistOperation(operation_registry(), | |
| 121 url, | |
| 122 search_query, | |
| 123 callback); | |
| 124 runner_->StartOperationWithRetry(operation); | |
| 125 } | |
| 126 | |
| 127 void DocumentsService::GetChangelist(const GURL& url, | |
| 128 int64 start_changestamp, | |
| 129 const GetDataCallback& callback) { | |
| 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 131 | |
| 132 GetChangelistOperation* operation = | |
| 133 new GetChangelistOperation(operation_registry(), | |
| 134 url, | |
| 135 start_changestamp, | |
| 136 callback); | |
| 137 runner_->StartOperationWithRetry(operation); | |
| 138 } | |
| 139 | |
| 140 void DocumentsService::GetDocumentEntry(const std::string& resource_id, | |
| 141 const GetDataCallback& callback) { | 117 const GetDataCallback& callback) { |
| 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 143 | 119 |
| 144 GetDocumentEntryOperation* operation = | 120 GetDocumentEntryOperation* operation = |
| 145 new GetDocumentEntryOperation(operation_registry(), | 121 new GetDocumentEntryOperation(operation_registry(), |
| 146 resource_id, | 122 resource_id, |
| 147 callback); | 123 callback); |
| 148 runner_->StartOperationWithRetry(operation); | 124 runner_->StartOperationWithRetry(operation); |
| 149 } | 125 } |
| 150 | 126 |
| 151 void DocumentsService::GetFile(const std::string& file_id, | 127 void GDataWapiService::GetAccountMetadata(const GetDataCallback& callback) { |
| 152 const GetDataCallback& callback) { | |
| 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 154 | |
| 155 GetFileOperation* operation = | |
| 156 new GetFileOperation(operation_registry(), | |
| 157 file_id, | |
| 158 callback); | |
| 159 runner_->StartOperationWithRetry(operation); | |
| 160 } | |
| 161 | |
| 162 void DocumentsService::GetAccountMetadata(const GetDataCallback& callback) { | |
| 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 164 | 129 |
| 165 GetAccountMetadataOperation* operation = | 130 GetAccountMetadataOperation* operation = |
| 166 new GetAccountMetadataOperation(operation_registry(), callback); | 131 new GetAccountMetadataOperation(operation_registry(), callback); |
| 167 runner_->StartOperationWithRetry(operation); | 132 runner_->StartOperationWithRetry(operation); |
| 168 } | 133 } |
| 169 | 134 |
| 170 void DocumentsService::GetAboutResource(const GetDataCallback& callback) { | 135 void GDataWapiService::GetApplicationInfo(const GetDataCallback& callback) { |
| 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 136 // For WAPI, AccountMetadata includes Drive application information. |
| 172 | 137 GetAccountMetadata(callback); |
| 173 GetAboutOperation* operation = | |
| 174 new GetAboutOperation(operation_registry(), callback); | |
| 175 runner_->StartOperationWithRetry(operation); | |
| 176 } | 138 } |
| 177 | 139 |
| 178 void DocumentsService::GetApplicationList(const GetDataCallback& callback) { | 140 void GDataWapiService::DownloadDocument( |
| 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 180 | |
| 181 GetApplistOperation* operation = | |
| 182 new GetApplistOperation(operation_registry(), callback); | |
| 183 runner_->StartOperationWithRetry(operation); | |
| 184 } | |
| 185 | |
| 186 void DocumentsService::DownloadDocument( | |
| 187 const FilePath& virtual_path, | 141 const FilePath& virtual_path, |
| 188 const FilePath& local_cache_path, | 142 const FilePath& local_cache_path, |
| 189 const GURL& document_url, | 143 const GURL& document_url, |
| 190 DocumentExportFormat format, | 144 DocumentExportFormat format, |
| 191 const DownloadActionCallback& callback) { | 145 const DownloadActionCallback& callback) { |
| 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 193 | 147 |
| 194 DownloadFile( | 148 DownloadFile( |
| 195 virtual_path, | 149 virtual_path, |
| 196 local_cache_path, | 150 local_cache_path, |
| 197 chrome_common_net::AppendQueryParameter(document_url, | 151 chrome_common_net::AppendQueryParameter(document_url, |
| 198 "exportFormat", | 152 "exportFormat", |
| 199 GetExportFormatParam(format)), | 153 GetExportFormatParam(format)), |
| 200 callback, | 154 callback, |
| 201 GetContentCallback()); | 155 GetContentCallback()); |
| 202 } | 156 } |
| 203 | 157 |
| 204 void DocumentsService::DownloadFile( | 158 void GDataWapiService::DownloadFile( |
| 205 const FilePath& virtual_path, | 159 const FilePath& virtual_path, |
| 206 const FilePath& local_cache_path, | 160 const FilePath& local_cache_path, |
| 207 const GURL& document_url, | 161 const GURL& document_url, |
| 208 const DownloadActionCallback& download_action_callback, | 162 const DownloadActionCallback& download_action_callback, |
| 209 const GetContentCallback& get_content_callback) { | 163 const GetContentCallback& get_content_callback) { |
| 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 211 | 165 |
| 212 runner_->StartOperationWithRetry( | 166 runner_->StartOperationWithRetry( |
| 213 new DownloadFileOperation(operation_registry(), | 167 new DownloadFileOperation(operation_registry(), |
| 214 download_action_callback, | 168 download_action_callback, |
| 215 get_content_callback, document_url, | 169 get_content_callback, document_url, |
| 216 virtual_path, local_cache_path)); | 170 virtual_path, local_cache_path)); |
| 217 } | 171 } |
| 218 | 172 |
| 219 void DocumentsService::DeleteDocument(const GURL& document_url, | 173 void GDataWapiService::DeleteDocument(const GURL& document_url, |
| 220 const EntryActionCallback& callback) { | 174 const EntryActionCallback& callback) { |
| 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 222 | 176 |
| 223 runner_->StartOperationWithRetry( | 177 runner_->StartOperationWithRetry( |
| 224 new DeleteDocumentOperation(operation_registry(), callback, | 178 new DeleteDocumentOperation(operation_registry(), callback, |
| 225 document_url)); | 179 document_url)); |
| 226 } | 180 } |
| 227 | 181 |
| 228 void DocumentsService::CreateDirectory( | 182 void GDataWapiService::CreateDirectory( |
| 229 const GURL& parent_content_url, | 183 const GURL& parent_content_url, |
| 230 const FilePath::StringType& directory_name, | 184 const FilePath::StringType& directory_name, |
| 231 const GetDataCallback& callback) { | 185 const GetDataCallback& callback) { |
| 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 233 | 187 |
| 234 runner_->StartOperationWithRetry( | 188 runner_->StartOperationWithRetry( |
| 235 new CreateDirectoryOperation(operation_registry(), callback, | 189 new CreateDirectoryOperation(operation_registry(), callback, |
| 236 parent_content_url, directory_name)); | 190 parent_content_url, directory_name)); |
| 237 } | 191 } |
| 238 | 192 |
| 239 void DocumentsService::CopyDocument(const std::string& resource_id, | 193 void GDataWapiService::CopyDocument(const std::string& resource_id, |
| 240 const FilePath::StringType& new_name, | 194 const FilePath::StringType& new_name, |
| 241 const GetDataCallback& callback) { | 195 const GetDataCallback& callback) { |
| 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 243 | 197 |
| 244 runner_->StartOperationWithRetry( | 198 runner_->StartOperationWithRetry( |
| 245 new CopyDocumentOperation(operation_registry(), callback, | 199 new CopyDocumentOperation(operation_registry(), callback, |
| 246 resource_id, new_name)); | 200 resource_id, new_name)); |
| 247 } | 201 } |
| 248 | 202 |
| 249 void DocumentsService::RenameResource(const GURL& resource_url, | 203 void GDataWapiService::RenameResource(const GURL& resource_url, |
| 250 const FilePath::StringType& new_name, | 204 const FilePath::StringType& new_name, |
| 251 const EntryActionCallback& callback) { | 205 const EntryActionCallback& callback) { |
| 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 253 | 207 |
| 254 runner_->StartOperationWithRetry( | 208 runner_->StartOperationWithRetry( |
| 255 new RenameResourceOperation(operation_registry(), callback, | 209 new RenameResourceOperation(operation_registry(), callback, |
| 256 resource_url, new_name)); | 210 resource_url, new_name)); |
| 257 } | 211 } |
| 258 | 212 |
| 259 void DocumentsService::AddResourceToDirectory( | 213 void GDataWapiService::AddResourceToDirectory( |
| 260 const GURL& parent_content_url, | 214 const GURL& parent_content_url, |
| 261 const GURL& resource_url, | 215 const GURL& resource_url, |
| 262 const EntryActionCallback& callback) { | 216 const EntryActionCallback& callback) { |
| 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 264 | 218 |
| 265 runner_->StartOperationWithRetry( | 219 runner_->StartOperationWithRetry( |
| 266 new AddResourceToDirectoryOperation(operation_registry(), | 220 new AddResourceToDirectoryOperation(operation_registry(), |
| 267 callback, | 221 callback, |
| 268 parent_content_url, | 222 parent_content_url, |
| 269 resource_url)); | 223 resource_url)); |
| 270 } | 224 } |
| 271 | 225 |
| 272 void DocumentsService::RemoveResourceFromDirectory( | 226 void GDataWapiService::RemoveResourceFromDirectory( |
| 273 const GURL& parent_content_url, | 227 const GURL& parent_content_url, |
| 274 const GURL& resource_url, | 228 const GURL& resource_url, |
| 275 const std::string& resource_id, | 229 const std::string& resource_id, |
| 276 const EntryActionCallback& callback) { | 230 const EntryActionCallback& callback) { |
| 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 278 | 232 |
| 279 runner_->StartOperationWithRetry( | 233 runner_->StartOperationWithRetry( |
| 280 new RemoveResourceFromDirectoryOperation(operation_registry(), | 234 new RemoveResourceFromDirectoryOperation(operation_registry(), |
| 281 callback, | 235 callback, |
| 282 parent_content_url, | 236 parent_content_url, |
| 283 resource_url, | 237 resource_url, |
| 284 resource_id)); | 238 resource_id)); |
| 285 } | 239 } |
| 286 | 240 |
| 287 void DocumentsService::InitiateUpload(const InitiateUploadParams& params, | 241 void GDataWapiService::InitiateUpload(const InitiateUploadParams& params, |
| 288 const InitiateUploadCallback& callback) { | 242 const InitiateUploadCallback& callback) { |
| 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 290 | 244 |
| 291 if (params.upload_location.is_empty()) { | 245 if (params.upload_location.is_empty()) { |
| 292 if (!callback.is_null()) | 246 if (!callback.is_null()) |
| 293 callback.Run(HTTP_BAD_REQUEST, GURL()); | 247 callback.Run(HTTP_BAD_REQUEST, GURL()); |
| 294 return; | 248 return; |
| 295 } | 249 } |
| 296 | 250 |
| 297 runner_->StartOperationWithRetry( | 251 runner_->StartOperationWithRetry( |
| 298 new InitiateUploadOperation(operation_registry(), callback, params)); | 252 new InitiateUploadOperation(operation_registry(), callback, params)); |
| 299 } | 253 } |
| 300 | 254 |
| 301 void DocumentsService::ResumeUpload(const ResumeUploadParams& params, | 255 void GDataWapiService::ResumeUpload(const ResumeUploadParams& params, |
| 302 const ResumeUploadCallback& callback) { | 256 const ResumeUploadCallback& callback) { |
| 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 304 | 258 |
| 305 runner_->StartOperationWithRetry( | 259 runner_->StartOperationWithRetry( |
| 306 new ResumeUploadOperation(operation_registry(), callback, params)); | 260 new ResumeUploadOperation(operation_registry(), callback, params)); |
| 307 } | 261 } |
| 308 | 262 |
| 309 | 263 |
| 310 void DocumentsService::AuthorizeApp(const GURL& resource_url, | 264 void GDataWapiService::AuthorizeApp(const GURL& resource_url, |
| 311 const std::string& app_ids, | 265 const std::string& app_ids, |
| 312 const GetDataCallback& callback) { | 266 const GetDataCallback& callback) { |
| 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 314 | 268 |
| 315 runner_->StartOperationWithRetry( | 269 runner_->StartOperationWithRetry( |
| 316 new AuthorizeAppsOperation(operation_registry(), callback, | 270 new AuthorizeAppsOperation(operation_registry(), callback, |
| 317 resource_url, app_ids)); | 271 resource_url, app_ids)); |
| 318 } | 272 } |
| 319 | 273 |
| 320 bool DocumentsService::HasAccessToken() const { | 274 bool GDataWapiService::HasAccessToken() const { |
| 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 322 | 276 |
| 323 return runner_->auth_service()->HasAccessToken(); | 277 return runner_->auth_service()->HasAccessToken(); |
| 324 } | 278 } |
| 325 | 279 |
| 326 bool DocumentsService::HasRefreshToken() const { | 280 bool GDataWapiService::HasRefreshToken() const { |
| 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 328 | 282 |
| 329 return runner_->auth_service()->HasRefreshToken(); | 283 return runner_->auth_service()->HasRefreshToken(); |
| 330 } | 284 } |
| 331 | 285 |
| 332 } // namespace gdata | 286 } // namespace gdata |
| OLD | NEW |