Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_client.cc

Issue 11530004: google_apis: DriveServiceInterface::GetResourceEntry() returns ResourceEntry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/sync_file_system/drive_file_sync_client.h" 5 #include "chrome/browser/sync_file_system/drive_file_sync_client.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 DCHECK_EQ(google_apis::ENTRY_KIND_FOLDER, entry->kind()); 187 DCHECK_EQ(google_apis::ENTRY_KIND_FOLDER, entry->kind());
188 DCHECK_EQ(ASCIIToUTF16(directory_name), entry->title()); 188 DCHECK_EQ(ASCIIToUTF16(directory_name), entry->title());
189 189
190 callback.Run(error, entry->resource_id()); 190 callback.Run(error, entry->resource_id());
191 } 191 }
192 192
193 void DriveFileSyncClient::DidGetParentDirectoryForCreateDirectory( 193 void DriveFileSyncClient::DidGetParentDirectoryForCreateDirectory(
194 const FilePath::StringType& directory_name, 194 const FilePath::StringType& directory_name,
195 const ResourceIdCallback& callback, 195 const ResourceIdCallback& callback,
196 google_apis::GDataErrorCode error, 196 google_apis::GDataErrorCode error,
197 scoped_ptr<base::Value> data) { 197 scoped_ptr<google_apis::ResourceEntry> entry) {
198 DCHECK(CalledOnValidThread()); 198 DCHECK(CalledOnValidThread());
199 199
200 if (error != google_apis::HTTP_SUCCESS) { 200 if (error != google_apis::HTTP_SUCCESS) {
201 callback.Run(error, std::string()); 201 callback.Run(error, std::string());
202 return; 202 return;
203 } 203 }
204 DCHECK(data); 204 DCHECK(entry);
205
206 scoped_ptr<google_apis::ResourceEntry> entry(
207 google_apis::ResourceEntry::ExtractAndParse(*data));
208 if (!entry) {
209 callback.Run(google_apis::GDATA_PARSE_ERROR, std::string());
210 return;
211 }
212 205
213 drive_service_->AddNewDirectory( 206 drive_service_->AddNewDirectory(
214 entry->content_url(), 207 entry->content_url(),
215 directory_name, 208 directory_name,
216 base::Bind(&DriveFileSyncClient::DidCreateDirectory, 209 base::Bind(&DriveFileSyncClient::DidCreateDirectory,
217 AsWeakPtr(), callback)); 210 AsWeakPtr(), callback));
218 } 211 }
219 212
220 void DriveFileSyncClient::DidCreateDirectory( 213 void DriveFileSyncClient::DidCreateDirectory(
221 const ResourceIdCallback& callback, 214 const ResourceIdCallback& callback,
(...skipping 24 matching lines...) Expand all
246 base::Bind(&DriveFileSyncClient::DidGetAccountMetadata, 239 base::Bind(&DriveFileSyncClient::DidGetAccountMetadata,
247 AsWeakPtr(), callback)); 240 AsWeakPtr(), callback));
248 } 241 }
249 242
250 void DriveFileSyncClient::GetResourceEntry( 243 void DriveFileSyncClient::GetResourceEntry(
251 const std::string& resource_id, 244 const std::string& resource_id,
252 const ResourceEntryCallback& callback) { 245 const ResourceEntryCallback& callback) {
253 DCHECK(CalledOnValidThread()); 246 DCHECK(CalledOnValidThread());
254 drive_service_->GetResourceEntry( 247 drive_service_->GetResourceEntry(
255 resource_id, 248 resource_id,
256 base::Bind(&DriveFileSyncClient::DidGetResourceEntryData, 249 base::Bind(&DriveFileSyncClient::DidGetResourceEntry,
257 AsWeakPtr(), callback)); 250 AsWeakPtr(), callback));
258 } 251 }
259 252
260 void DriveFileSyncClient::DidGetAccountMetadata( 253 void DriveFileSyncClient::DidGetAccountMetadata(
261 const ChangeStampCallback& callback, 254 const ChangeStampCallback& callback,
262 google_apis::GDataErrorCode error, 255 google_apis::GDataErrorCode error,
263 scoped_ptr<base::Value> data) { 256 scoped_ptr<base::Value> data) {
264 DCHECK(CalledOnValidThread()); 257 DCHECK(CalledOnValidThread());
265 258
266 int64 largest_changestamp = 0; 259 int64 largest_changestamp = 0;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 317 }
325 318
326 void DriveFileSyncClient::DownloadFile( 319 void DriveFileSyncClient::DownloadFile(
327 const std::string& resource_id, 320 const std::string& resource_id,
328 const std::string& local_file_md5, 321 const std::string& local_file_md5,
329 const FilePath& local_file_path, 322 const FilePath& local_file_path,
330 const DownloadFileCallback& callback) { 323 const DownloadFileCallback& callback) {
331 DCHECK(CalledOnValidThread()); 324 DCHECK(CalledOnValidThread());
332 drive_service_->GetResourceEntry( 325 drive_service_->GetResourceEntry(
333 resource_id, 326 resource_id,
334 base::Bind(&DriveFileSyncClient::DidGetResourceEntryData, 327 base::Bind(&DriveFileSyncClient::DidGetResourceEntry,
335 AsWeakPtr(), 328 AsWeakPtr(),
336 base::Bind(&DriveFileSyncClient::DownloadFileInternal, 329 base::Bind(&DriveFileSyncClient::DownloadFileInternal,
337 AsWeakPtr(), local_file_md5, local_file_path, 330 AsWeakPtr(), local_file_md5, local_file_path,
338 callback))); 331 callback)));
339 } 332 }
340 333
341 void DriveFileSyncClient::UploadNewFile( 334 void DriveFileSyncClient::UploadNewFile(
342 const std::string& directory_resource_id, 335 const std::string& directory_resource_id,
343 const FilePath& local_file_path, 336 const FilePath& local_file_path,
344 const std::string& title, 337 const std::string& title,
345 int64 file_size, 338 int64 file_size,
346 const UploadFileCallback& callback) { 339 const UploadFileCallback& callback) {
347 DCHECK(CalledOnValidThread()); 340 DCHECK(CalledOnValidThread());
348 drive_service_->GetResourceEntry( 341 drive_service_->GetResourceEntry(
349 directory_resource_id, 342 directory_resource_id,
350 base::Bind(&DriveFileSyncClient::DidGetResourceEntryData, 343 base::Bind(&DriveFileSyncClient::DidGetResourceEntry,
351 AsWeakPtr(), 344 AsWeakPtr(),
352 base::Bind(&DriveFileSyncClient::UploadNewFileInternal, 345 base::Bind(&DriveFileSyncClient::UploadNewFileInternal,
353 AsWeakPtr(), local_file_path, title, file_size, 346 AsWeakPtr(), local_file_path, title, file_size,
354 callback))); 347 callback)));
355 } 348 }
356 349
357 void DriveFileSyncClient::UploadExistingFile( 350 void DriveFileSyncClient::UploadExistingFile(
358 const std::string& resource_id, 351 const std::string& resource_id,
359 const std::string& remote_file_md5, 352 const std::string& remote_file_md5,
360 const FilePath& local_file_path, 353 const FilePath& local_file_path,
361 int64 file_size, 354 int64 file_size,
362 const UploadFileCallback& callback) { 355 const UploadFileCallback& callback) {
363 DCHECK(CalledOnValidThread()); 356 DCHECK(CalledOnValidThread());
364 drive_service_->GetResourceEntry( 357 drive_service_->GetResourceEntry(
365 resource_id, 358 resource_id,
366 base::Bind(&DriveFileSyncClient::DidGetResourceEntryData, 359 base::Bind(&DriveFileSyncClient::DidGetResourceEntry,
367 AsWeakPtr(), 360 AsWeakPtr(),
368 base::Bind(&DriveFileSyncClient::UploadExistingFileInternal, 361 base::Bind(&DriveFileSyncClient::UploadExistingFileInternal,
369 AsWeakPtr(), remote_file_md5, local_file_path, 362 AsWeakPtr(), remote_file_md5, local_file_path,
370 file_size, callback))); 363 file_size, callback)));
371 } 364 }
372 365
373 void DriveFileSyncClient::DeleteFile( 366 void DriveFileSyncClient::DeleteFile(
374 const std::string& resource_id, 367 const std::string& resource_id,
375 const std::string& remote_file_md5, 368 const std::string& remote_file_md5,
376 const GDataErrorCallback& callback) { 369 const GDataErrorCallback& callback) {
377 DCHECK(CalledOnValidThread()); 370 DCHECK(CalledOnValidThread());
378 drive_service_->GetResourceEntry( 371 drive_service_->GetResourceEntry(
379 resource_id, 372 resource_id,
380 base::Bind(&DriveFileSyncClient::DidGetResourceEntryData, 373 base::Bind(&DriveFileSyncClient::DidGetResourceEntry,
381 AsWeakPtr(), 374 AsWeakPtr(),
382 base::Bind(&DriveFileSyncClient::DeleteFileInternal, 375 base::Bind(&DriveFileSyncClient::DeleteFileInternal,
383 AsWeakPtr(), remote_file_md5, callback))); 376 AsWeakPtr(), remote_file_md5, callback)));
384 } 377 }
385 378
386 // static 379 // static
387 std::string DriveFileSyncClient::OriginToDirectoryTitle(const GURL& origin) { 380 std::string DriveFileSyncClient::OriginToDirectoryTitle(const GURL& origin) {
388 DCHECK(origin.SchemeIs(extensions::kExtensionScheme)); 381 DCHECK(origin.SchemeIs(extensions::kExtensionScheme));
389 return origin.host(); 382 return origin.host();
390 } 383 }
(...skipping 29 matching lines...) Expand all
420 413
421 if (error != google_apis::HTTP_SUCCESS) { 414 if (error != google_apis::HTTP_SUCCESS) {
422 callback.Run(error, scoped_ptr<google_apis::ResourceList>()); 415 callback.Run(error, scoped_ptr<google_apis::ResourceList>());
423 return; 416 return;
424 } 417 }
425 418
426 DCHECK(resource_list); 419 DCHECK(resource_list);
427 callback.Run(error, resource_list.Pass()); 420 callback.Run(error, resource_list.Pass());
428 } 421 }
429 422
430 void DriveFileSyncClient::DidGetResourceEntryData( 423 void DriveFileSyncClient::DidGetResourceEntry(
431 const ResourceEntryCallback& callback, 424 const ResourceEntryCallback& callback,
432 google_apis::GDataErrorCode error, 425 google_apis::GDataErrorCode error,
433 scoped_ptr<base::Value> data) { 426 scoped_ptr<google_apis::ResourceEntry> entry) {
434 DCHECK(CalledOnValidThread()); 427 DCHECK(CalledOnValidThread());
435 428
436 if (error != google_apis::HTTP_SUCCESS) { 429 if (error != google_apis::HTTP_SUCCESS) {
437 callback.Run(error, scoped_ptr<google_apis::ResourceEntry>()); 430 callback.Run(error, scoped_ptr<google_apis::ResourceEntry>());
438 return; 431 return;
439 } 432 }
440 433
441 DCHECK(data); 434 DCHECK(entry);
442 scoped_ptr<google_apis::ResourceEntry> entry(
443 google_apis::ResourceEntry::ExtractAndParse(*data));
444 if (!entry)
445 error = google_apis::GDATA_PARSE_ERROR;
446 callback.Run(error, entry.Pass()); 435 callback.Run(error, entry.Pass());
447 } 436 }
448 437
449 // static 438 // static
450 std::string DriveFileSyncClient::FormatTitleQuery(const std::string& title) { 439 std::string DriveFileSyncClient::FormatTitleQuery(const std::string& title) {
451 // TODO(tzik): This pattern matches partial and case-insensitive, 440 // TODO(tzik): This pattern matches partial and case-insensitive,
452 // and also matches files in subdirectories. 441 // and also matches files in subdirectories.
453 // Refine the query after we migrate to Drive API. 442 // Refine the query after we migrate to Drive API.
454 std::ostringstream out; 443 std::ostringstream out;
455 out << "title:"; 444 out << "title:";
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 636 }
648 637
649 void DriveFileSyncClient::DidDeleteFile( 638 void DriveFileSyncClient::DidDeleteFile(
650 const GDataErrorCallback& callback, 639 const GDataErrorCallback& callback,
651 google_apis::GDataErrorCode error) { 640 google_apis::GDataErrorCode error) {
652 DCHECK(CalledOnValidThread()); 641 DCHECK(CalledOnValidThread());
653 callback.Run(error); 642 callback.Run(error);
654 } 643 }
655 644
656 } // namespace sync_file_system 645 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698