| 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/fake_drive_service.h" | 5 #include "chrome/browser/google_apis/fake_drive_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 332 } |
| 333 | 333 |
| 334 void FakeDriveService::GetResourceEntry( | 334 void FakeDriveService::GetResourceEntry( |
| 335 const std::string& resource_id, | 335 const std::string& resource_id, |
| 336 const GetResourceEntryCallback& callback) { | 336 const GetResourceEntryCallback& callback) { |
| 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 338 DCHECK(!callback.is_null()); | 338 DCHECK(!callback.is_null()); |
| 339 | 339 |
| 340 if (offline_) { | 340 if (offline_) { |
| 341 scoped_ptr<ResourceEntry> null; | 341 scoped_ptr<ResourceEntry> null; |
| 342 MessageLoop::current()->PostTask( | 342 base::MessageLoop::current()->PostTask( |
| 343 FROM_HERE, | 343 FROM_HERE, |
| 344 base::Bind(callback, | 344 base::Bind(callback, GDATA_NO_CONNECTION, base::Passed(&null))); |
| 345 GDATA_NO_CONNECTION, | |
| 346 base::Passed(&null))); | |
| 347 return; | 345 return; |
| 348 } | 346 } |
| 349 | 347 |
| 350 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); | 348 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); |
| 351 if (entry) { | 349 if (entry) { |
| 352 scoped_ptr<ResourceEntry> resource_entry = | 350 scoped_ptr<ResourceEntry> resource_entry = |
| 353 ResourceEntry::CreateFrom(*entry); | 351 ResourceEntry::CreateFrom(*entry); |
| 354 MessageLoop::current()->PostTask( | 352 base::MessageLoop::current()->PostTask( |
| 355 FROM_HERE, | 353 FROM_HERE, |
| 356 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_entry))); | 354 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_entry))); |
| 357 return; | 355 return; |
| 358 } | 356 } |
| 359 | 357 |
| 360 scoped_ptr<ResourceEntry> null; | 358 scoped_ptr<ResourceEntry> null; |
| 361 MessageLoop::current()->PostTask( | 359 base::MessageLoop::current()->PostTask( |
| 362 FROM_HERE, | 360 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
| 363 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); | |
| 364 } | 361 } |
| 365 | 362 |
| 366 void FakeDriveService::GetAccountMetadata( | 363 void FakeDriveService::GetAccountMetadata( |
| 367 const GetAccountMetadataCallback& callback) { | 364 const GetAccountMetadataCallback& callback) { |
| 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 369 DCHECK(!callback.is_null()); | 366 DCHECK(!callback.is_null()); |
| 370 | 367 |
| 371 if (offline_) { | 368 if (offline_) { |
| 372 scoped_ptr<AccountMetadata> null; | 369 scoped_ptr<AccountMetadata> null; |
| 373 MessageLoop::current()->PostTask( | 370 base::MessageLoop::current()->PostTask( |
| 374 FROM_HERE, | 371 FROM_HERE, |
| 375 base::Bind(callback, | 372 base::Bind(callback, GDATA_NO_CONNECTION, base::Passed(&null))); |
| 376 GDATA_NO_CONNECTION, | |
| 377 base::Passed(&null))); | |
| 378 return; | 373 return; |
| 379 } | 374 } |
| 380 | 375 |
| 381 ++account_metadata_load_count_; | 376 ++account_metadata_load_count_; |
| 382 scoped_ptr<AccountMetadata> account_metadata = | 377 scoped_ptr<AccountMetadata> account_metadata = |
| 383 AccountMetadata::CreateFrom(*account_metadata_value_); | 378 AccountMetadata::CreateFrom(*account_metadata_value_); |
| 384 // Overwrite the change stamp. | 379 // Overwrite the change stamp. |
| 385 account_metadata->set_largest_changestamp(largest_changestamp_); | 380 account_metadata->set_largest_changestamp(largest_changestamp_); |
| 386 MessageLoop::current()->PostTask( | 381 base::MessageLoop::current()->PostTask( |
| 387 FROM_HERE, | 382 FROM_HERE, |
| 388 base::Bind(callback, | 383 base::Bind(callback, HTTP_SUCCESS, base::Passed(&account_metadata))); |
| 389 HTTP_SUCCESS, | |
| 390 base::Passed(&account_metadata))); | |
| 391 } | 384 } |
| 392 | 385 |
| 393 void FakeDriveService::GetAboutResource( | 386 void FakeDriveService::GetAboutResource( |
| 394 const GetAboutResourceCallback& callback) { | 387 const GetAboutResourceCallback& callback) { |
| 395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 396 DCHECK(!callback.is_null()); | 389 DCHECK(!callback.is_null()); |
| 397 | 390 |
| 398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 399 DCHECK(!callback.is_null()); | 392 DCHECK(!callback.is_null()); |
| 400 | 393 |
| 401 if (offline_) { | 394 if (offline_) { |
| 402 scoped_ptr<AboutResource> null; | 395 scoped_ptr<AboutResource> null; |
| 403 MessageLoop::current()->PostTask( | 396 base::MessageLoop::current()->PostTask( |
| 404 FROM_HERE, | 397 FROM_HERE, |
| 405 base::Bind(callback, | 398 base::Bind(callback, GDATA_NO_CONNECTION, base::Passed(&null))); |
| 406 GDATA_NO_CONNECTION, base::Passed(&null))); | |
| 407 return; | 399 return; |
| 408 } | 400 } |
| 409 | 401 |
| 410 ++about_resource_load_count_; | 402 ++about_resource_load_count_; |
| 411 scoped_ptr<AboutResource> about_resource( | 403 scoped_ptr<AboutResource> about_resource( |
| 412 AboutResource::CreateFromAccountMetadata( | 404 AboutResource::CreateFromAccountMetadata( |
| 413 *AccountMetadata::CreateFrom(*account_metadata_value_), | 405 *AccountMetadata::CreateFrom(*account_metadata_value_), |
| 414 GetRootResourceId())); | 406 GetRootResourceId())); |
| 415 // Overwrite the change id. | 407 // Overwrite the change id. |
| 416 about_resource->set_largest_change_id(largest_changestamp_); | 408 about_resource->set_largest_change_id(largest_changestamp_); |
| 417 MessageLoop::current()->PostTask( | 409 base::MessageLoop::current()->PostTask( |
| 418 FROM_HERE, | 410 FROM_HERE, |
| 419 base::Bind(callback, | 411 base::Bind(callback, HTTP_SUCCESS, base::Passed(&about_resource))); |
| 420 HTTP_SUCCESS, base::Passed(&about_resource))); | |
| 421 } | 412 } |
| 422 | 413 |
| 423 void FakeDriveService::GetAppList(const GetAppListCallback& callback) { | 414 void FakeDriveService::GetAppList(const GetAppListCallback& callback) { |
| 424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 425 DCHECK(!callback.is_null()); | 416 DCHECK(!callback.is_null()); |
| 426 | 417 |
| 427 if (offline_) { | 418 if (offline_) { |
| 428 scoped_ptr<AppList> null; | 419 scoped_ptr<AppList> null; |
| 429 MessageLoop::current()->PostTask( | 420 base::MessageLoop::current()->PostTask( |
| 430 FROM_HERE, | 421 FROM_HERE, |
| 431 base::Bind(callback, | 422 base::Bind(callback, GDATA_NO_CONNECTION, base::Passed(&null))); |
| 432 GDATA_NO_CONNECTION, | |
| 433 base::Passed(&null))); | |
| 434 return; | 423 return; |
| 435 } | 424 } |
| 436 | 425 |
| 437 scoped_ptr<AppList> app_list(AppList::CreateFrom(*app_info_value_)); | 426 scoped_ptr<AppList> app_list(AppList::CreateFrom(*app_info_value_)); |
| 438 MessageLoop::current()->PostTask( | 427 base::MessageLoop::current()->PostTask( |
| 439 FROM_HERE, | 428 FROM_HERE, base::Bind(callback, HTTP_SUCCESS, base::Passed(&app_list))); |
| 440 base::Bind(callback, HTTP_SUCCESS, base::Passed(&app_list))); | |
| 441 } | 429 } |
| 442 | 430 |
| 443 void FakeDriveService::DeleteResource( | 431 void FakeDriveService::DeleteResource( |
| 444 const std::string& resource_id, | 432 const std::string& resource_id, |
| 445 const std::string& etag, | 433 const std::string& etag, |
| 446 const EntryActionCallback& callback) { | 434 const EntryActionCallback& callback) { |
| 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 448 DCHECK(!callback.is_null()); | 436 DCHECK(!callback.is_null()); |
| 449 | 437 |
| 450 if (offline_) { | 438 if (offline_) { |
| 451 MessageLoop::current()->PostTask( | 439 base::MessageLoop::current()->PostTask( |
| 452 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); | 440 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); |
| 453 return; | 441 return; |
| 454 } | 442 } |
| 455 | 443 |
| 456 base::DictionaryValue* resource_list_dict = NULL; | 444 base::DictionaryValue* resource_list_dict = NULL; |
| 457 base::ListValue* entries = NULL; | 445 base::ListValue* entries = NULL; |
| 458 // Go through entries and remove the one that matches |resource_id|. | 446 // Go through entries and remove the one that matches |resource_id|. |
| 459 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && | 447 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| 460 resource_list_dict->GetList("entry", &entries)) { | 448 resource_list_dict->GetList("entry", &entries)) { |
| 461 for (size_t i = 0; i < entries->GetSize(); ++i) { | 449 for (size_t i = 0; i < entries->GetSize(); ++i) { |
| 462 base::DictionaryValue* entry = NULL; | 450 base::DictionaryValue* entry = NULL; |
| 463 std::string current_resource_id; | 451 std::string current_resource_id; |
| 464 if (entries->GetDictionary(i, &entry) && | 452 if (entries->GetDictionary(i, &entry) && |
| 465 entry->GetString("gd$resourceId.$t", ¤t_resource_id) && | 453 entry->GetString("gd$resourceId.$t", ¤t_resource_id) && |
| 466 resource_id == current_resource_id) { | 454 resource_id == current_resource_id) { |
| 467 entries->Remove(i, NULL); | 455 entries->Remove(i, NULL); |
| 468 MessageLoop::current()->PostTask( | 456 base::MessageLoop::current()->PostTask( |
| 469 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); | 457 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); |
| 470 return; | 458 return; |
| 471 } | 459 } |
| 472 } | 460 } |
| 473 } | 461 } |
| 474 | 462 |
| 475 // TODO(satorux): Add support for returning "deleted" entries in | 463 // TODO(satorux): Add support for returning "deleted" entries in |
| 476 // changelists from GetResourceList(). | 464 // changelists from GetResourceList(). |
| 477 MessageLoop::current()->PostTask( | 465 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 478 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); | 466 base::Bind(callback, HTTP_NOT_FOUND)); |
| 479 } | 467 } |
| 480 | 468 |
| 481 void FakeDriveService::DownloadFile( | 469 void FakeDriveService::DownloadFile( |
| 482 const base::FilePath& virtual_path, | 470 const base::FilePath& virtual_path, |
| 483 const base::FilePath& local_cache_path, | 471 const base::FilePath& local_cache_path, |
| 484 const GURL& download_url, | 472 const GURL& download_url, |
| 485 const DownloadActionCallback& download_action_callback, | 473 const DownloadActionCallback& download_action_callback, |
| 486 const GetContentCallback& get_content_callback, | 474 const GetContentCallback& get_content_callback, |
| 487 const ProgressCallback& progress_callback) { | 475 const ProgressCallback& progress_callback) { |
| 488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 489 DCHECK(!download_action_callback.is_null()); | 477 DCHECK(!download_action_callback.is_null()); |
| 490 | 478 |
| 491 if (offline_) { | 479 if (offline_) { |
| 492 MessageLoop::current()->PostTask( | 480 base::MessageLoop::current()->PostTask( |
| 493 FROM_HERE, | 481 FROM_HERE, |
| 494 base::Bind(download_action_callback, | 482 base::Bind( |
| 495 GDATA_NO_CONNECTION, | 483 download_action_callback, GDATA_NO_CONNECTION, base::FilePath())); |
| 496 base::FilePath())); | |
| 497 return; | 484 return; |
| 498 } | 485 } |
| 499 | 486 |
| 500 // The field content.src is the URL to download the file. | 487 // The field content.src is the URL to download the file. |
| 501 base::DictionaryValue* entry = FindEntryByContentUrl(download_url); | 488 base::DictionaryValue* entry = FindEntryByContentUrl(download_url); |
| 502 if (!entry) { | 489 if (!entry) { |
| 503 base::MessageLoopProxy::current()->PostTask( | 490 base::MessageLoopProxy::current()->PostTask( |
| 504 FROM_HERE, | 491 FROM_HERE, |
| 505 base::Bind(download_action_callback, HTTP_NOT_FOUND, base::FilePath())); | 492 base::Bind(download_action_callback, HTTP_NOT_FOUND, base::FilePath())); |
| 506 return; | 493 return; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 | 547 |
| 561 void FakeDriveService::CopyHostedDocument( | 548 void FakeDriveService::CopyHostedDocument( |
| 562 const std::string& resource_id, | 549 const std::string& resource_id, |
| 563 const std::string& new_name, | 550 const std::string& new_name, |
| 564 const GetResourceEntryCallback& callback) { | 551 const GetResourceEntryCallback& callback) { |
| 565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 566 DCHECK(!callback.is_null()); | 553 DCHECK(!callback.is_null()); |
| 567 | 554 |
| 568 if (offline_) { | 555 if (offline_) { |
| 569 scoped_ptr<ResourceEntry> null; | 556 scoped_ptr<ResourceEntry> null; |
| 570 MessageLoop::current()->PostTask( | 557 base::MessageLoop::current()->PostTask( |
| 571 FROM_HERE, | 558 FROM_HERE, |
| 572 base::Bind(callback, | 559 base::Bind(callback, GDATA_NO_CONNECTION, base::Passed(&null))); |
| 573 GDATA_NO_CONNECTION, | |
| 574 base::Passed(&null))); | |
| 575 return; | 560 return; |
| 576 } | 561 } |
| 577 | 562 |
| 578 base::DictionaryValue* resource_list_dict = NULL; | 563 base::DictionaryValue* resource_list_dict = NULL; |
| 579 base::ListValue* entries = NULL; | 564 base::ListValue* entries = NULL; |
| 580 // Go through entries and copy the one that matches |resource_id|. | 565 // Go through entries and copy the one that matches |resource_id|. |
| 581 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && | 566 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| 582 resource_list_dict->GetList("entry", &entries)) { | 567 resource_list_dict->GetList("entry", &entries)) { |
| 583 for (size_t i = 0; i < entries->GetSize(); ++i) { | 568 for (size_t i = 0; i < entries->GetSize(); ++i) { |
| 584 base::DictionaryValue* entry = NULL; | 569 base::DictionaryValue* entry = NULL; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 606 copied_entry->SetString("title.$t", new_name); | 591 copied_entry->SetString("title.$t", new_name); |
| 607 | 592 |
| 608 AddNewChangestamp(copied_entry.get()); | 593 AddNewChangestamp(copied_entry.get()); |
| 609 | 594 |
| 610 // Parse the new entry. | 595 // Parse the new entry. |
| 611 scoped_ptr<ResourceEntry> resource_entry = | 596 scoped_ptr<ResourceEntry> resource_entry = |
| 612 ResourceEntry::CreateFrom(*copied_entry); | 597 ResourceEntry::CreateFrom(*copied_entry); |
| 613 // Add it to the resource list. | 598 // Add it to the resource list. |
| 614 entries->Append(copied_entry.release()); | 599 entries->Append(copied_entry.release()); |
| 615 | 600 |
| 616 MessageLoop::current()->PostTask( | 601 base::MessageLoop::current()->PostTask( |
| 617 FROM_HERE, | 602 FROM_HERE, |
| 618 base::Bind(callback, | 603 base::Bind( |
| 619 HTTP_SUCCESS, | 604 callback, HTTP_SUCCESS, base::Passed(&resource_entry))); |
| 620 base::Passed(&resource_entry))); | |
| 621 return; | 605 return; |
| 622 } | 606 } |
| 623 } | 607 } |
| 624 } | 608 } |
| 625 } | 609 } |
| 626 } | 610 } |
| 627 | 611 |
| 628 scoped_ptr<ResourceEntry> null; | 612 scoped_ptr<ResourceEntry> null; |
| 629 MessageLoop::current()->PostTask( | 613 base::MessageLoop::current()->PostTask( |
| 630 FROM_HERE, | 614 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
| 631 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); | |
| 632 } | 615 } |
| 633 | 616 |
| 634 void FakeDriveService::RenameResource( | 617 void FakeDriveService::RenameResource( |
| 635 const std::string& resource_id, | 618 const std::string& resource_id, |
| 636 const std::string& new_name, | 619 const std::string& new_name, |
| 637 const EntryActionCallback& callback) { | 620 const EntryActionCallback& callback) { |
| 638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 639 DCHECK(!callback.is_null()); | 622 DCHECK(!callback.is_null()); |
| 640 | 623 |
| 641 if (offline_) { | 624 if (offline_) { |
| 642 MessageLoop::current()->PostTask( | 625 base::MessageLoop::current()->PostTask( |
| 643 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); | 626 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); |
| 644 return; | 627 return; |
| 645 } | 628 } |
| 646 | 629 |
| 647 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); | 630 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); |
| 648 if (entry) { | 631 if (entry) { |
| 649 entry->SetString("title.$t", new_name); | 632 entry->SetString("title.$t", new_name); |
| 650 AddNewChangestamp(entry); | 633 AddNewChangestamp(entry); |
| 651 MessageLoop::current()->PostTask( | 634 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 652 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); | 635 base::Bind(callback, HTTP_SUCCESS)); |
| 653 return; | 636 return; |
| 654 } | 637 } |
| 655 | 638 |
| 656 MessageLoop::current()->PostTask( | 639 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 657 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); | 640 base::Bind(callback, HTTP_NOT_FOUND)); |
| 658 } | 641 } |
| 659 | 642 |
| 660 void FakeDriveService::AddResourceToDirectory( | 643 void FakeDriveService::AddResourceToDirectory( |
| 661 const std::string& parent_resource_id, | 644 const std::string& parent_resource_id, |
| 662 const std::string& resource_id, | 645 const std::string& resource_id, |
| 663 const EntryActionCallback& callback) { | 646 const EntryActionCallback& callback) { |
| 664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 647 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 665 DCHECK(!callback.is_null()); | 648 DCHECK(!callback.is_null()); |
| 666 | 649 |
| 667 if (offline_) { | 650 if (offline_) { |
| 668 MessageLoop::current()->PostTask( | 651 base::MessageLoop::current()->PostTask( |
| 669 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); | 652 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); |
| 670 return; | 653 return; |
| 671 } | 654 } |
| 672 | 655 |
| 673 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); | 656 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); |
| 674 if (entry) { | 657 if (entry) { |
| 675 base::ListValue* links = NULL; | 658 base::ListValue* links = NULL; |
| 676 if (!entry->GetList("link", &links)) { | 659 if (!entry->GetList("link", &links)) { |
| 677 links = new base::ListValue; | 660 links = new base::ListValue; |
| 678 entry->Set("link", links); | 661 entry->Set("link", links); |
| 679 } | 662 } |
| 680 | 663 |
| 681 // On the real Drive server, resources do not necessary shape a tree | 664 // On the real Drive server, resources do not necessary shape a tree |
| 682 // structure. That is, each resource can have multiple parent. | 665 // structure. That is, each resource can have multiple parent. |
| 683 // We mimic the behavior here; AddResourceToDirectoy just adds | 666 // We mimic the behavior here; AddResourceToDirectoy just adds |
| 684 // one more parent link, not overwriting old links. | 667 // one more parent link, not overwriting old links. |
| 685 base::DictionaryValue* link = new base::DictionaryValue; | 668 base::DictionaryValue* link = new base::DictionaryValue; |
| 686 link->SetString("rel", "http://schemas.google.com/docs/2007#parent"); | 669 link->SetString("rel", "http://schemas.google.com/docs/2007#parent"); |
| 687 link->SetString( | 670 link->SetString( |
| 688 "href", GetFakeLinkUrl(parent_resource_id).spec()); | 671 "href", GetFakeLinkUrl(parent_resource_id).spec()); |
| 689 links->Append(link); | 672 links->Append(link); |
| 690 | 673 |
| 691 AddNewChangestamp(entry); | 674 AddNewChangestamp(entry); |
| 692 MessageLoop::current()->PostTask( | 675 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 693 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); | 676 base::Bind(callback, HTTP_SUCCESS)); |
| 694 return; | 677 return; |
| 695 } | 678 } |
| 696 | 679 |
| 697 MessageLoop::current()->PostTask( | 680 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 698 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); | 681 base::Bind(callback, HTTP_NOT_FOUND)); |
| 699 } | 682 } |
| 700 | 683 |
| 701 void FakeDriveService::RemoveResourceFromDirectory( | 684 void FakeDriveService::RemoveResourceFromDirectory( |
| 702 const std::string& parent_resource_id, | 685 const std::string& parent_resource_id, |
| 703 const std::string& resource_id, | 686 const std::string& resource_id, |
| 704 const EntryActionCallback& callback) { | 687 const EntryActionCallback& callback) { |
| 705 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 688 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 706 DCHECK(!callback.is_null()); | 689 DCHECK(!callback.is_null()); |
| 707 | 690 |
| 708 if (offline_) { | 691 if (offline_) { |
| 709 MessageLoop::current()->PostTask( | 692 base::MessageLoop::current()->PostTask( |
| 710 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); | 693 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); |
| 711 return; | 694 return; |
| 712 } | 695 } |
| 713 | 696 |
| 714 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); | 697 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); |
| 715 if (entry) { | 698 if (entry) { |
| 716 base::ListValue* links = NULL; | 699 base::ListValue* links = NULL; |
| 717 if (entry->GetList("link", &links)) { | 700 if (entry->GetList("link", &links)) { |
| 718 GURL parent_content_url = GetFakeLinkUrl(parent_resource_id); | 701 GURL parent_content_url = GetFakeLinkUrl(parent_resource_id); |
| 719 for (size_t i = 0; i < links->GetSize(); ++i) { | 702 for (size_t i = 0; i < links->GetSize(); ++i) { |
| 720 base::DictionaryValue* link = NULL; | 703 base::DictionaryValue* link = NULL; |
| 721 std::string rel; | 704 std::string rel; |
| 722 std::string href; | 705 std::string href; |
| 723 if (links->GetDictionary(i, &link) && | 706 if (links->GetDictionary(i, &link) && |
| 724 link->GetString("rel", &rel) && | 707 link->GetString("rel", &rel) && |
| 725 link->GetString("href", &href) && | 708 link->GetString("href", &href) && |
| 726 rel == "http://schemas.google.com/docs/2007#parent" && | 709 rel == "http://schemas.google.com/docs/2007#parent" && |
| 727 GURL(href) == parent_content_url) { | 710 GURL(href) == parent_content_url) { |
| 728 links->Remove(i, NULL); | 711 links->Remove(i, NULL); |
| 729 AddNewChangestamp(entry); | 712 AddNewChangestamp(entry); |
| 730 MessageLoop::current()->PostTask( | 713 base::MessageLoop::current()->PostTask( |
| 731 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); | 714 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); |
| 732 return; | 715 return; |
| 733 } | 716 } |
| 734 } | 717 } |
| 735 } | 718 } |
| 736 } | 719 } |
| 737 | 720 |
| 738 MessageLoop::current()->PostTask( | 721 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 739 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); | 722 base::Bind(callback, HTTP_NOT_FOUND)); |
| 740 } | 723 } |
| 741 | 724 |
| 742 void FakeDriveService::AddNewDirectory( | 725 void FakeDriveService::AddNewDirectory( |
| 743 const std::string& parent_resource_id, | 726 const std::string& parent_resource_id, |
| 744 const std::string& directory_name, | 727 const std::string& directory_name, |
| 745 const GetResourceEntryCallback& callback) { | 728 const GetResourceEntryCallback& callback) { |
| 746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 747 DCHECK(!callback.is_null()); | 730 DCHECK(!callback.is_null()); |
| 748 | 731 |
| 749 if (offline_) { | 732 if (offline_) { |
| 750 scoped_ptr<ResourceEntry> null; | 733 scoped_ptr<ResourceEntry> null; |
| 751 MessageLoop::current()->PostTask( | 734 base::MessageLoop::current()->PostTask( |
| 752 FROM_HERE, | 735 FROM_HERE, |
| 753 base::Bind(callback, | 736 base::Bind(callback, GDATA_NO_CONNECTION, base::Passed(&null))); |
| 754 GDATA_NO_CONNECTION, | |
| 755 base::Passed(&null))); | |
| 756 return; | 737 return; |
| 757 } | 738 } |
| 758 | 739 |
| 759 const char kContentType[] = "application/atom+xml;type=feed"; | 740 const char kContentType[] = "application/atom+xml;type=feed"; |
| 760 const base::DictionaryValue* new_entry = AddNewEntry(kContentType, | 741 const base::DictionaryValue* new_entry = AddNewEntry(kContentType, |
| 761 0, // content_length | 742 0, // content_length |
| 762 parent_resource_id, | 743 parent_resource_id, |
| 763 directory_name, | 744 directory_name, |
| 764 false, // shared_with_me | 745 false, // shared_with_me |
| 765 "folder"); | 746 "folder"); |
| 766 if (!new_entry) { | 747 if (!new_entry) { |
| 767 scoped_ptr<ResourceEntry> null; | 748 scoped_ptr<ResourceEntry> null; |
| 768 MessageLoop::current()->PostTask( | 749 base::MessageLoop::current()->PostTask( |
| 769 FROM_HERE, | 750 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
| 770 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); | |
| 771 return; | 751 return; |
| 772 } | 752 } |
| 773 | 753 |
| 774 scoped_ptr<ResourceEntry> parsed_entry(ResourceEntry::CreateFrom(*new_entry)); | 754 scoped_ptr<ResourceEntry> parsed_entry(ResourceEntry::CreateFrom(*new_entry)); |
| 775 MessageLoop::current()->PostTask( | 755 base::MessageLoop::current()->PostTask( |
| 776 FROM_HERE, | 756 FROM_HERE, |
| 777 base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry))); | 757 base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry))); |
| 778 } | 758 } |
| 779 | 759 |
| 780 void FakeDriveService::InitiateUploadNewFile( | 760 void FakeDriveService::InitiateUploadNewFile( |
| 781 const base::FilePath& drive_file_path, | 761 const base::FilePath& drive_file_path, |
| 782 const std::string& content_type, | 762 const std::string& content_type, |
| 783 int64 content_length, | 763 int64 content_length, |
| 784 const std::string& parent_resource_id, | 764 const std::string& parent_resource_id, |
| 785 const std::string& title, | 765 const std::string& title, |
| 786 const InitiateUploadCallback& callback) { | 766 const InitiateUploadCallback& callback) { |
| 787 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 767 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 788 DCHECK(!callback.is_null()); | 768 DCHECK(!callback.is_null()); |
| 789 | 769 |
| 790 if (offline_) { | 770 if (offline_) { |
| 791 MessageLoop::current()->PostTask( | 771 base::MessageLoop::current()->PostTask( |
| 792 FROM_HERE, | 772 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION, GURL())); |
| 793 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); | |
| 794 return; | 773 return; |
| 795 } | 774 } |
| 796 | 775 |
| 797 // Content length should be zero, as we'll create an empty file first. The | 776 // Content length should be zero, as we'll create an empty file first. The |
| 798 // content will be added in ResumeUpload(). | 777 // content will be added in ResumeUpload(). |
| 799 const base::DictionaryValue* new_entry = AddNewEntry(content_type, | 778 const base::DictionaryValue* new_entry = AddNewEntry(content_type, |
| 800 0, // content_length | 779 0, // content_length |
| 801 parent_resource_id, | 780 parent_resource_id, |
| 802 title, | 781 title, |
| 803 false, // shared_with_me | 782 false, // shared_with_me |
| 804 "file"); | 783 "file"); |
| 805 if (!new_entry) { | 784 if (!new_entry) { |
| 806 MessageLoop::current()->PostTask( | 785 base::MessageLoop::current()->PostTask( |
| 807 FROM_HERE, | 786 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, GURL())); |
| 808 base::Bind(callback, HTTP_NOT_FOUND, GURL())); | |
| 809 return; | 787 return; |
| 810 } | 788 } |
| 811 const GURL upload_url = GetUploadUrl(*new_entry); | 789 const GURL upload_url = GetUploadUrl(*new_entry); |
| 812 DCHECK(upload_url.is_valid()); | 790 DCHECK(upload_url.is_valid()); |
| 813 | 791 |
| 814 MessageLoop::current()->PostTask( | 792 base::MessageLoop::current()->PostTask( |
| 815 FROM_HERE, | 793 FROM_HERE, base::Bind(callback, HTTP_SUCCESS, upload_url)); |
| 816 base::Bind(callback, HTTP_SUCCESS, upload_url)); | |
| 817 } | 794 } |
| 818 | 795 |
| 819 void FakeDriveService::InitiateUploadExistingFile( | 796 void FakeDriveService::InitiateUploadExistingFile( |
| 820 const base::FilePath& drive_file_path, | 797 const base::FilePath& drive_file_path, |
| 821 const std::string& content_type, | 798 const std::string& content_type, |
| 822 int64 content_length, | 799 int64 content_length, |
| 823 const std::string& resource_id, | 800 const std::string& resource_id, |
| 824 const std::string& etag, | 801 const std::string& etag, |
| 825 const InitiateUploadCallback& callback) { | 802 const InitiateUploadCallback& callback) { |
| 826 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 803 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 827 DCHECK(!callback.is_null()); | 804 DCHECK(!callback.is_null()); |
| 828 | 805 |
| 829 if (offline_) { | 806 if (offline_) { |
| 830 MessageLoop::current()->PostTask( | 807 base::MessageLoop::current()->PostTask( |
| 831 FROM_HERE, | 808 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION, GURL())); |
| 832 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); | |
| 833 return; | 809 return; |
| 834 } | 810 } |
| 835 | 811 |
| 836 DictionaryValue* entry = FindEntryByResourceId(resource_id); | 812 DictionaryValue* entry = FindEntryByResourceId(resource_id); |
| 837 if (!entry) { | 813 if (!entry) { |
| 838 MessageLoop::current()->PostTask( | 814 base::MessageLoop::current()->PostTask( |
| 839 FROM_HERE, | 815 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, GURL())); |
| 840 base::Bind(callback, HTTP_NOT_FOUND, GURL())); | |
| 841 return; | 816 return; |
| 842 } | 817 } |
| 843 | 818 |
| 844 std::string entry_etag; | 819 std::string entry_etag; |
| 845 entry->GetString("gd$etag", &entry_etag); | 820 entry->GetString("gd$etag", &entry_etag); |
| 846 if (!etag.empty() && etag != entry_etag) { | 821 if (!etag.empty() && etag != entry_etag) { |
| 847 MessageLoop::current()->PostTask( | 822 base::MessageLoop::current()->PostTask( |
| 848 FROM_HERE, | 823 FROM_HERE, base::Bind(callback, HTTP_PRECONDITION, GURL())); |
| 849 base::Bind(callback, HTTP_PRECONDITION, GURL())); | |
| 850 return; | 824 return; |
| 851 } | 825 } |
| 852 entry->SetString("docs$size.$t", "0"); | 826 entry->SetString("docs$size.$t", "0"); |
| 853 | 827 |
| 854 const GURL upload_url = GetUploadUrl(*entry); | 828 const GURL upload_url = GetUploadUrl(*entry); |
| 855 DCHECK(upload_url.is_valid()); | 829 DCHECK(upload_url.is_valid()); |
| 856 | 830 |
| 857 MessageLoop::current()->PostTask( | 831 base::MessageLoop::current()->PostTask( |
| 858 FROM_HERE, | 832 FROM_HERE, base::Bind(callback, HTTP_SUCCESS, upload_url)); |
| 859 base::Bind(callback, HTTP_SUCCESS, upload_url)); | |
| 860 } | 833 } |
| 861 | 834 |
| 862 void FakeDriveService::GetUploadStatus( | 835 void FakeDriveService::GetUploadStatus( |
| 863 UploadMode upload_mode, | 836 UploadMode upload_mode, |
| 864 const base::FilePath& drive_file_path, | 837 const base::FilePath& drive_file_path, |
| 865 const GURL& upload_url, | 838 const GURL& upload_url, |
| 866 int64 content_length, | 839 int64 content_length, |
| 867 const UploadRangeCallback& callback) { | 840 const UploadRangeCallback& callback) { |
| 868 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 869 DCHECK(!callback.is_null()); | 842 DCHECK(!callback.is_null()); |
| 870 } | 843 } |
| 871 | 844 |
| 872 void FakeDriveService::ResumeUpload( | 845 void FakeDriveService::ResumeUpload( |
| 873 UploadMode upload_mode, | 846 UploadMode upload_mode, |
| 874 const base::FilePath& drive_file_path, | 847 const base::FilePath& drive_file_path, |
| 875 const GURL& upload_url, | 848 const GURL& upload_url, |
| 876 int64 start_position, | 849 int64 start_position, |
| 877 int64 end_position, | 850 int64 end_position, |
| 878 int64 content_length, | 851 int64 content_length, |
| 879 const std::string& content_type, | 852 const std::string& content_type, |
| 880 const scoped_refptr<net::IOBuffer>& buf, | 853 const scoped_refptr<net::IOBuffer>& buf, |
| 881 const UploadRangeCallback& callback, | 854 const UploadRangeCallback& callback, |
| 882 const ProgressCallback& progress_callback) { | 855 const ProgressCallback& progress_callback) { |
| 883 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 856 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 884 DCHECK(!callback.is_null()); | 857 DCHECK(!callback.is_null()); |
| 885 | 858 |
| 886 scoped_ptr<ResourceEntry> result_entry; | 859 scoped_ptr<ResourceEntry> result_entry; |
| 887 | 860 |
| 888 if (offline_) { | 861 if (offline_) { |
| 889 MessageLoop::current()->PostTask( | 862 base::MessageLoop::current()->PostTask( |
| 890 FROM_HERE, | 863 FROM_HERE, |
| 891 base::Bind(callback, | 864 base::Bind(callback, |
| 892 UploadRangeResponse(GDATA_NO_CONNECTION, | 865 UploadRangeResponse( |
| 893 start_position, | 866 GDATA_NO_CONNECTION, start_position, end_position), |
| 894 end_position), | |
| 895 base::Passed(&result_entry))); | 867 base::Passed(&result_entry))); |
| 896 return; | 868 return; |
| 897 } | 869 } |
| 898 | 870 |
| 899 DictionaryValue* entry = NULL; | 871 DictionaryValue* entry = NULL; |
| 900 entry = FindEntryByUploadUrl(upload_url); | 872 entry = FindEntryByUploadUrl(upload_url); |
| 901 if (!entry) { | 873 if (!entry) { |
| 902 MessageLoop::current()->PostTask( | 874 base::MessageLoop::current()->PostTask( |
| 903 FROM_HERE, | 875 FROM_HERE, |
| 904 base::Bind(callback, | 876 base::Bind( |
| 905 UploadRangeResponse(HTTP_NOT_FOUND, | 877 callback, |
| 906 start_position, | 878 UploadRangeResponse(HTTP_NOT_FOUND, start_position, end_position), |
| 907 end_position), | 879 base::Passed(&result_entry))); |
| 908 base::Passed(&result_entry))); | |
| 909 return; | 880 return; |
| 910 } | 881 } |
| 911 | 882 |
| 912 // Chunks are required to be sent in such a ways that they fill from the start | 883 // Chunks are required to be sent in such a ways that they fill from the start |
| 913 // of the not-yet-uploaded part with no gaps nor overlaps. | 884 // of the not-yet-uploaded part with no gaps nor overlaps. |
| 914 std::string current_size_string; | 885 std::string current_size_string; |
| 915 int64 current_size; | 886 int64 current_size; |
| 916 if (!entry->GetString("docs$size.$t", ¤t_size_string) || | 887 if (!entry->GetString("docs$size.$t", ¤t_size_string) || |
| 917 !base::StringToInt64(current_size_string, ¤t_size) || | 888 !base::StringToInt64(current_size_string, ¤t_size) || |
| 918 current_size != start_position) { | 889 current_size != start_position) { |
| 919 MessageLoop::current()->PostTask( | 890 base::MessageLoop::current()->PostTask( |
| 920 FROM_HERE, | 891 FROM_HERE, |
| 921 base::Bind(callback, | 892 base::Bind( |
| 922 UploadRangeResponse(HTTP_BAD_REQUEST, | 893 callback, |
| 923 start_position, | 894 UploadRangeResponse(HTTP_BAD_REQUEST, start_position, end_position), |
| 924 end_position), | 895 base::Passed(&result_entry))); |
| 925 base::Passed(&result_entry))); | |
| 926 return; | 896 return; |
| 927 } | 897 } |
| 928 | 898 |
| 929 entry->SetString("docs$size.$t", base::Int64ToString(end_position)); | 899 entry->SetString("docs$size.$t", base::Int64ToString(end_position)); |
| 930 | 900 |
| 931 if (!progress_callback.is_null()) { | 901 if (!progress_callback.is_null()) { |
| 932 // In the real GDataWapi/Drive DriveService, progress is reported in | 902 // In the real GDataWapi/Drive DriveService, progress is reported in |
| 933 // nondeterministic timing. In this fake implementation, we choose to call | 903 // nondeterministic timing. In this fake implementation, we choose to call |
| 934 // it twice per one ResumeUpload. This is for making sure that client code | 904 // it twice per one ResumeUpload. This is for making sure that client code |
| 935 // works fine even if the callback is invoked more than once; it is the | 905 // works fine even if the callback is invoked more than once; it is the |
| 936 // crucial difference of the progress callback from others. | 906 // crucial difference of the progress callback from others. |
| 937 // Note that progress is notified in the relative offset in each chunk. | 907 // Note that progress is notified in the relative offset in each chunk. |
| 938 const int64 chunk_size = end_position - start_position; | 908 const int64 chunk_size = end_position - start_position; |
| 939 MessageLoop::current()->PostTask( | 909 base::MessageLoop::current()->PostTask( |
| 940 FROM_HERE, base::Bind(progress_callback, chunk_size / 2, chunk_size)); | 910 FROM_HERE, base::Bind(progress_callback, chunk_size / 2, chunk_size)); |
| 941 MessageLoop::current()->PostTask( | 911 base::MessageLoop::current()->PostTask( |
| 942 FROM_HERE, base::Bind(progress_callback, chunk_size, chunk_size)); | 912 FROM_HERE, base::Bind(progress_callback, chunk_size, chunk_size)); |
| 943 } | 913 } |
| 944 | 914 |
| 945 if (content_length != end_position) { | 915 if (content_length != end_position) { |
| 946 MessageLoop::current()->PostTask( | 916 base::MessageLoop::current()->PostTask( |
| 947 FROM_HERE, | 917 FROM_HERE, |
| 948 base::Bind(callback, | 918 base::Bind(callback, |
| 949 UploadRangeResponse(HTTP_RESUME_INCOMPLETE, | 919 UploadRangeResponse( |
| 950 start_position, | 920 HTTP_RESUME_INCOMPLETE, start_position, end_position), |
| 951 end_position), | 921 base::Passed(&result_entry))); |
| 952 base::Passed(&result_entry))); | |
| 953 return; | 922 return; |
| 954 } | 923 } |
| 955 | 924 |
| 956 result_entry = ResourceEntry::CreateFrom(*entry).Pass(); | 925 result_entry = ResourceEntry::CreateFrom(*entry).Pass(); |
| 957 | 926 |
| 958 GDataErrorCode return_code = HTTP_SUCCESS; | 927 GDataErrorCode return_code = HTTP_SUCCESS; |
| 959 if (upload_mode == UPLOAD_NEW_FILE) | 928 if (upload_mode == UPLOAD_NEW_FILE) |
| 960 return_code = HTTP_CREATED; | 929 return_code = HTTP_CREATED; |
| 961 | 930 |
| 962 MessageLoop::current()->PostTask( | 931 base::MessageLoop::current()->PostTask( |
| 963 FROM_HERE, | 932 FROM_HERE, |
| 964 base::Bind(callback, | 933 base::Bind(callback, |
| 965 UploadRangeResponse(return_code, | 934 UploadRangeResponse(return_code, start_position, end_position), |
| 966 start_position, | |
| 967 end_position), | |
| 968 base::Passed(&result_entry))); | 935 base::Passed(&result_entry))); |
| 969 } | 936 } |
| 970 | 937 |
| 971 void FakeDriveService::AuthorizeApp(const std::string& resource_id, | 938 void FakeDriveService::AuthorizeApp(const std::string& resource_id, |
| 972 const std::string& app_id, | 939 const std::string& app_id, |
| 973 const AuthorizeAppCallback& callback) { | 940 const AuthorizeAppCallback& callback) { |
| 974 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 941 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 975 DCHECK(!callback.is_null()); | 942 DCHECK(!callback.is_null()); |
| 976 } | 943 } |
| 977 | 944 |
| 978 void FakeDriveService::AddNewFile(const std::string& content_type, | 945 void FakeDriveService::AddNewFile(const std::string& content_type, |
| 979 int64 content_length, | 946 int64 content_length, |
| 980 const std::string& parent_resource_id, | 947 const std::string& parent_resource_id, |
| 981 const std::string& title, | 948 const std::string& title, |
| 982 bool shared_with_me, | 949 bool shared_with_me, |
| 983 const GetResourceEntryCallback& callback) { | 950 const GetResourceEntryCallback& callback) { |
| 984 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 951 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 985 DCHECK(!callback.is_null()); | 952 DCHECK(!callback.is_null()); |
| 986 | 953 |
| 987 if (offline_) { | 954 if (offline_) { |
| 988 scoped_ptr<ResourceEntry> null; | 955 scoped_ptr<ResourceEntry> null; |
| 989 MessageLoop::current()->PostTask( | 956 base::MessageLoop::current()->PostTask( |
| 990 FROM_HERE, | 957 FROM_HERE, |
| 991 base::Bind(callback, | 958 base::Bind(callback, GDATA_NO_CONNECTION, base::Passed(&null))); |
| 992 GDATA_NO_CONNECTION, | |
| 993 base::Passed(&null))); | |
| 994 return; | 959 return; |
| 995 } | 960 } |
| 996 | 961 |
| 997 // Prepare "kind" for hosted documents. This only supports Google Document. | 962 // Prepare "kind" for hosted documents. This only supports Google Document. |
| 998 std::string entry_kind; | 963 std::string entry_kind; |
| 999 if (content_type == "application/vnd.google-apps.document") | 964 if (content_type == "application/vnd.google-apps.document") |
| 1000 entry_kind = "document"; | 965 entry_kind = "document"; |
| 1001 else | 966 else |
| 1002 entry_kind = "file"; | 967 entry_kind = "file"; |
| 1003 | 968 |
| 1004 const base::DictionaryValue* new_entry = AddNewEntry(content_type, | 969 const base::DictionaryValue* new_entry = AddNewEntry(content_type, |
| 1005 content_length, | 970 content_length, |
| 1006 parent_resource_id, | 971 parent_resource_id, |
| 1007 title, | 972 title, |
| 1008 shared_with_me, | 973 shared_with_me, |
| 1009 entry_kind); | 974 entry_kind); |
| 1010 if (!new_entry) { | 975 if (!new_entry) { |
| 1011 scoped_ptr<ResourceEntry> null; | 976 scoped_ptr<ResourceEntry> null; |
| 1012 MessageLoop::current()->PostTask( | 977 base::MessageLoop::current()->PostTask( |
| 1013 FROM_HERE, | 978 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
| 1014 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); | |
| 1015 return; | 979 return; |
| 1016 } | 980 } |
| 1017 | 981 |
| 1018 scoped_ptr<ResourceEntry> parsed_entry( | 982 scoped_ptr<ResourceEntry> parsed_entry( |
| 1019 ResourceEntry::CreateFrom(*new_entry)); | 983 ResourceEntry::CreateFrom(*new_entry)); |
| 1020 MessageLoop::current()->PostTask( | 984 base::MessageLoop::current()->PostTask( |
| 1021 FROM_HERE, | 985 FROM_HERE, |
| 1022 base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry))); | 986 base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry))); |
| 1023 } | 987 } |
| 1024 | 988 |
| 1025 void FakeDriveService::SetLastModifiedTime( | 989 void FakeDriveService::SetLastModifiedTime( |
| 1026 const std::string& resource_id, | 990 const std::string& resource_id, |
| 1027 const base::Time& last_modified_time, | 991 const base::Time& last_modified_time, |
| 1028 const GetResourceEntryCallback& callback) { | 992 const GetResourceEntryCallback& callback) { |
| 1029 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 993 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1030 DCHECK(!callback.is_null()); | 994 DCHECK(!callback.is_null()); |
| 1031 | 995 |
| 1032 if (offline_) { | 996 if (offline_) { |
| 1033 scoped_ptr<ResourceEntry> null; | 997 scoped_ptr<ResourceEntry> null; |
| 1034 MessageLoop::current()->PostTask( | 998 base::MessageLoop::current()->PostTask( |
| 1035 FROM_HERE, | 999 FROM_HERE, |
| 1036 base::Bind(callback, | 1000 base::Bind(callback, GDATA_NO_CONNECTION, base::Passed(&null))); |
| 1037 GDATA_NO_CONNECTION, | |
| 1038 base::Passed(&null))); | |
| 1039 return; | 1001 return; |
| 1040 } | 1002 } |
| 1041 | 1003 |
| 1042 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); | 1004 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); |
| 1043 if (!entry) { | 1005 if (!entry) { |
| 1044 scoped_ptr<ResourceEntry> null; | 1006 scoped_ptr<ResourceEntry> null; |
| 1045 MessageLoop::current()->PostTask( | 1007 base::MessageLoop::current()->PostTask( |
| 1046 FROM_HERE, | 1008 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
| 1047 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); | |
| 1048 return; | 1009 return; |
| 1049 } | 1010 } |
| 1050 | 1011 |
| 1051 entry->SetString("updated.$t", util::FormatTimeAsString(last_modified_time)); | 1012 entry->SetString("updated.$t", util::FormatTimeAsString(last_modified_time)); |
| 1052 | 1013 |
| 1053 scoped_ptr<ResourceEntry> parsed_entry( | 1014 scoped_ptr<ResourceEntry> parsed_entry( |
| 1054 ResourceEntry::CreateFrom(*entry)); | 1015 ResourceEntry::CreateFrom(*entry)); |
| 1055 MessageLoop::current()->PostTask( | 1016 base::MessageLoop::current()->PostTask( |
| 1056 FROM_HERE, | 1017 FROM_HERE, |
| 1057 base::Bind(callback, HTTP_SUCCESS, base::Passed(&parsed_entry))); | 1018 base::Bind(callback, HTTP_SUCCESS, base::Passed(&parsed_entry))); |
| 1058 } | 1019 } |
| 1059 | 1020 |
| 1060 base::DictionaryValue* FakeDriveService::FindEntryByResourceId( | 1021 base::DictionaryValue* FakeDriveService::FindEntryByResourceId( |
| 1061 const std::string& resource_id) { | 1022 const std::string& resource_id) { |
| 1062 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1023 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1063 | 1024 |
| 1064 base::DictionaryValue* resource_list_dict = NULL; | 1025 base::DictionaryValue* resource_list_dict = NULL; |
| 1065 base::ListValue* entries = NULL; | 1026 base::ListValue* entries = NULL; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 | 1207 |
| 1247 void FakeDriveService::GetResourceListInternal( | 1208 void FakeDriveService::GetResourceListInternal( |
| 1248 int64 start_changestamp, | 1209 int64 start_changestamp, |
| 1249 const std::string& search_query, | 1210 const std::string& search_query, |
| 1250 const std::string& directory_resource_id, | 1211 const std::string& directory_resource_id, |
| 1251 int start_offset, | 1212 int start_offset, |
| 1252 int max_results, | 1213 int max_results, |
| 1253 const GetResourceListCallback& callback) { | 1214 const GetResourceListCallback& callback) { |
| 1254 if (offline_) { | 1215 if (offline_) { |
| 1255 scoped_ptr<ResourceList> null; | 1216 scoped_ptr<ResourceList> null; |
| 1256 MessageLoop::current()->PostTask( | 1217 base::MessageLoop::current()->PostTask( |
| 1257 FROM_HERE, | 1218 FROM_HERE, |
| 1258 base::Bind(callback, | 1219 base::Bind(callback, GDATA_NO_CONNECTION, base::Passed(&null))); |
| 1259 GDATA_NO_CONNECTION, | |
| 1260 base::Passed(&null))); | |
| 1261 return; | 1220 return; |
| 1262 } | 1221 } |
| 1263 | 1222 |
| 1264 scoped_ptr<ResourceList> resource_list = | 1223 scoped_ptr<ResourceList> resource_list = |
| 1265 ResourceList::CreateFrom(*resource_list_value_); | 1224 ResourceList::CreateFrom(*resource_list_value_); |
| 1266 | 1225 |
| 1267 // Filter out entries per parameters like |directory_resource_id| and | 1226 // Filter out entries per parameters like |directory_resource_id| and |
| 1268 // |search_query|. | 1227 // |search_query|. |
| 1269 ScopedVector<ResourceEntry>* entries = resource_list->mutable_entries(); | 1228 ScopedVector<ResourceEntry>* entries = resource_list->mutable_entries(); |
| 1270 | 1229 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 next_url, "parent", directory_resource_id); | 1304 next_url, "parent", directory_resource_id); |
| 1346 } | 1305 } |
| 1347 | 1306 |
| 1348 Link* link = new Link; | 1307 Link* link = new Link; |
| 1349 link->set_type(Link::LINK_NEXT); | 1308 link->set_type(Link::LINK_NEXT); |
| 1350 link->set_href(next_url); | 1309 link->set_href(next_url); |
| 1351 resource_list->mutable_links()->push_back(link); | 1310 resource_list->mutable_links()->push_back(link); |
| 1352 } | 1311 } |
| 1353 | 1312 |
| 1354 ++resource_list_load_count_; | 1313 ++resource_list_load_count_; |
| 1355 MessageLoop::current()->PostTask( | 1314 base::MessageLoop::current()->PostTask( |
| 1356 FROM_HERE, | 1315 FROM_HERE, |
| 1357 base::Bind(callback, | 1316 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_list))); |
| 1358 HTTP_SUCCESS, | |
| 1359 base::Passed(&resource_list))); | |
| 1360 } | 1317 } |
| 1361 | 1318 |
| 1362 } // namespace google_apis | 1319 } // namespace google_apis |
| OLD | NEW |