| 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/drive/fake_drive_service.h" | 5 #include "chrome/browser/drive/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 17 matching lines...) Expand all Loading... |
| 28 using google_apis::AboutResource; | 28 using google_apis::AboutResource; |
| 29 using google_apis::AccountMetadata; | 29 using google_apis::AccountMetadata; |
| 30 using google_apis::AppList; | 30 using google_apis::AppList; |
| 31 using google_apis::AuthorizeAppCallback; | 31 using google_apis::AuthorizeAppCallback; |
| 32 using google_apis::CancelCallback; | 32 using google_apis::CancelCallback; |
| 33 using google_apis::DownloadActionCallback; | 33 using google_apis::DownloadActionCallback; |
| 34 using google_apis::EntryActionCallback; | 34 using google_apis::EntryActionCallback; |
| 35 using google_apis::GDataErrorCode; | 35 using google_apis::GDataErrorCode; |
| 36 using google_apis::GDATA_FILE_ERROR; | 36 using google_apis::GDATA_FILE_ERROR; |
| 37 using google_apis::GDATA_NO_CONNECTION; | 37 using google_apis::GDATA_NO_CONNECTION; |
| 38 using google_apis::GDATA_OTHER_ERROR; |
| 38 using google_apis::GetAboutResourceCallback; | 39 using google_apis::GetAboutResourceCallback; |
| 39 using google_apis::GetAppListCallback; | 40 using google_apis::GetAppListCallback; |
| 40 using google_apis::GetContentCallback; | 41 using google_apis::GetContentCallback; |
| 41 using google_apis::GetResourceEntryCallback; | 42 using google_apis::GetResourceEntryCallback; |
| 42 using google_apis::GetResourceListCallback; | 43 using google_apis::GetResourceListCallback; |
| 43 using google_apis::HTTP_BAD_REQUEST; | 44 using google_apis::HTTP_BAD_REQUEST; |
| 44 using google_apis::HTTP_CREATED; | 45 using google_apis::HTTP_CREATED; |
| 45 using google_apis::HTTP_NOT_FOUND; | 46 using google_apis::HTTP_NOT_FOUND; |
| 46 using google_apis::HTTP_PRECONDITION; | 47 using google_apis::HTTP_PRECONDITION; |
| 47 using google_apis::HTTP_RESUME_INCOMPLETE; | 48 using google_apis::HTTP_RESUME_INCOMPLETE; |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 | 522 |
| 522 base::ListValue* entries = NULL; | 523 base::ListValue* entries = NULL; |
| 523 // Go through entries and remove the one that matches |resource_id|. | 524 // Go through entries and remove the one that matches |resource_id|. |
| 524 if (resource_list_value_->GetList("entry", &entries)) { | 525 if (resource_list_value_->GetList("entry", &entries)) { |
| 525 for (size_t i = 0; i < entries->GetSize(); ++i) { | 526 for (size_t i = 0; i < entries->GetSize(); ++i) { |
| 526 base::DictionaryValue* entry = NULL; | 527 base::DictionaryValue* entry = NULL; |
| 527 std::string current_resource_id; | 528 std::string current_resource_id; |
| 528 if (entries->GetDictionary(i, &entry) && | 529 if (entries->GetDictionary(i, &entry) && |
| 529 entry->GetString("gd$resourceId.$t", ¤t_resource_id) && | 530 entry->GetString("gd$resourceId.$t", ¤t_resource_id) && |
| 530 resource_id == current_resource_id) { | 531 resource_id == current_resource_id) { |
| 531 entries->Remove(i, NULL); | 532 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 533 if (entry->HasKey("gd$deleted")) { |
| 534 error = HTTP_NOT_FOUND; |
| 535 } else { |
| 536 entry->Set("gd$deleted", new DictionaryValue); |
| 537 AddNewChangestampAndETag(entry); |
| 538 error = HTTP_SUCCESS; |
| 539 } |
| 532 base::MessageLoop::current()->PostTask( | 540 base::MessageLoop::current()->PostTask( |
| 533 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); | 541 FROM_HERE, base::Bind(callback, error)); |
| 534 return CancelCallback(); | 542 return CancelCallback(); |
| 535 } | 543 } |
| 536 } | 544 } |
| 537 } | 545 } |
| 538 | 546 |
| 539 // TODO(satorux): Add support for returning "deleted" entries in | |
| 540 // changelists from GetResourceList(). | |
| 541 base::MessageLoop::current()->PostTask( | 547 base::MessageLoop::current()->PostTask( |
| 542 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); | 548 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); |
| 543 return CancelCallback(); | 549 return CancelCallback(); |
| 544 } | 550 } |
| 545 | 551 |
| 546 CancelCallback FakeDriveService::DownloadFile( | 552 CancelCallback FakeDriveService::DownloadFile( |
| 547 const base::FilePath& local_cache_path, | 553 const base::FilePath& local_cache_path, |
| 548 const GURL& download_url, | 554 const GURL& download_url, |
| 549 const DownloadActionCallback& download_action_callback, | 555 const DownloadActionCallback& download_action_callback, |
| 550 const GetContentCallback& get_content_callback, | 556 const GetContentCallback& get_content_callback, |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 should_exclude = true; | 1412 should_exclude = true; |
| 1407 } | 1413 } |
| 1408 | 1414 |
| 1409 // If |start_changestamp| is set, exclude the entry if the | 1415 // If |start_changestamp| is set, exclude the entry if the |
| 1410 // changestamp is older than |largest_changestamp|. | 1416 // changestamp is older than |largest_changestamp|. |
| 1411 // See https://developers.google.com/google-apps/documents-list/ | 1417 // See https://developers.google.com/google-apps/documents-list/ |
| 1412 // #retrieving_all_changes_since_a_given_changestamp | 1418 // #retrieving_all_changes_since_a_given_changestamp |
| 1413 if (start_changestamp > 0 && entry->changestamp() < start_changestamp) | 1419 if (start_changestamp > 0 && entry->changestamp() < start_changestamp) |
| 1414 should_exclude = true; | 1420 should_exclude = true; |
| 1415 | 1421 |
| 1422 // If the caller requests other list than change list by specifying |
| 1423 // zero-|start_changestamp|, exclude deleted entry from the result. |
| 1424 if (!start_changestamp && entry->deleted()) |
| 1425 should_exclude = true; |
| 1426 |
| 1416 // The entry matched the criteria for inclusion. | 1427 // The entry matched the criteria for inclusion. |
| 1417 if (!should_exclude) | 1428 if (!should_exclude) |
| 1418 ++num_entries_matched; | 1429 ++num_entries_matched; |
| 1419 | 1430 |
| 1420 // If |start_offset| is set, exclude the entry if the entry is before the | 1431 // If |start_offset| is set, exclude the entry if the entry is before the |
| 1421 // start index. <= instead of < as |num_entries_matched| was | 1432 // start index. <= instead of < as |num_entries_matched| was |
| 1422 // already incremented. | 1433 // already incremented. |
| 1423 if (start_offset > 0 && num_entries_matched <= start_offset) | 1434 if (start_offset > 0 && num_entries_matched <= start_offset) |
| 1424 should_exclude = true; | 1435 should_exclude = true; |
| 1425 | 1436 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 HTTP_SUCCESS, | 1480 HTTP_SUCCESS, |
| 1470 base::Passed(&resource_list))); | 1481 base::Passed(&resource_list))); |
| 1471 } | 1482 } |
| 1472 | 1483 |
| 1473 GURL FakeDriveService::GetNewUploadSessionUrl() { | 1484 GURL FakeDriveService::GetNewUploadSessionUrl() { |
| 1474 return GURL("https://upload_session_url/" + | 1485 return GURL("https://upload_session_url/" + |
| 1475 base::Int64ToString(next_upload_sequence_number_++)); | 1486 base::Int64ToString(next_upload_sequence_number_++)); |
| 1476 } | 1487 } |
| 1477 | 1488 |
| 1478 } // namespace drive | 1489 } // namespace drive |
| OLD | NEW |