Index: chrome/browser/google_apis/fake_drive_service.cc |
diff --git a/chrome/browser/google_apis/fake_drive_service.cc b/chrome/browser/google_apis/fake_drive_service.cc |
index 423b0c8d57349c1897be413550883aa0b0c40ce3..8ba0b080d3e8adcae4b66c5f5e6a4c19576e5ff1 100644 |
--- a/chrome/browser/google_apis/fake_drive_service.cc |
+++ b/chrome/browser/google_apis/fake_drive_service.cc |
@@ -8,6 +8,7 @@ |
#include "base/logging.h" |
#include "base/message_loop.h" |
#include "base/string_number_conversions.h" |
+#include "base/string_split.h" |
#include "base/stringprintf.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/google_apis/gdata_wapi_parser.h" |
@@ -21,6 +22,7 @@ namespace google_apis { |
FakeDriveService::FakeDriveService() |
: largest_changestamp_(0), |
+ default_max_results_(0), |
resource_id_count_(0), |
resource_list_load_count_(0), |
account_metadata_load_count_(0), |
@@ -148,12 +150,27 @@ void FakeDriveService::GetResourceList( |
return; |
} |
+ int start_index = 0; |
kinaba
2013/01/19 03:28:18
The usage of "start-index" url parameter looks dif
satorux1
2013/01/22 17:44:09
That's a great catch! I wasn't aware of this incom
|
+ int max_results = default_max_results_; |
+ std::vector<std::pair<std::string, std::string> > parameters; |
+ if (base::SplitStringIntoKeyValuePairs( |
+ feed_url.query(), '=', '&', ¶meters)) { |
+ for (size_t i = 0; i < parameters.size(); ++i) { |
+ if (parameters[i].first == "start-index") |
+ base::StringToInt(parameters[i].second, &start_index); |
+ if (parameters[i].first == "max-results") |
+ base::StringToInt(parameters[i].second, &max_results); |
+ } |
+ } |
+ |
scoped_ptr<ResourceList> resource_list = |
ResourceList::CreateFrom(*resource_list_value_); |
// Filter out entries per parameters like |directory_resource_id| and |
// |search_query|. |
ScopedVector<ResourceEntry>* entries = resource_list->mutable_entries(); |
+ |
+ int num_entries_matched = 0; |
for (size_t i = 0; i < entries->size();) { |
ResourceEntry* entry = (*entries)[i]; |
bool should_exclude = false; |
@@ -182,15 +199,22 @@ void FakeDriveService::GetResourceList( |
should_exclude = true; |
} |
- // If |start_changestamp| is non-zero, exclude the entry if the |
+ // If |start_changestamp| is set, exclude the entry if the |
// changestamp is older than |largest_changestamp|. |
// See https://developers.google.com/google-apps/documents-list/ |
// #retrieving_all_changes_since_a_given_changestamp |
- if (start_changestamp > 0) { |
- if (entry->changestamp() < start_changestamp) { |
- should_exclude = true; |
- } |
- } |
+ if (start_changestamp > 0 && entry->changestamp() < start_changestamp) |
+ should_exclude = true; |
+ |
+ // The entry matched the criteria for inclusion. |
+ if (!should_exclude) |
+ ++num_entries_matched; |
+ |
+ // If |start_index| is set, exclude the entry if the entry is before the |
+ // start index. <= instead of < as |num_entries_matched| was |
+ // already incremented. |
+ if (start_index > 0 && num_entries_matched <= start_index) |
+ should_exclude = true; |
if (should_exclude) |
entries->erase(entries->begin() + i); |
@@ -198,6 +222,22 @@ void FakeDriveService::GetResourceList( |
++i; |
} |
+ // If |max_results| is set, trim the entries if the number exceeded the max |
+ // results. |
+ if (max_results > 0 && entries->size() > static_cast<size_t>(max_results)) { |
+ entries->erase(entries->begin() + max_results, entries->end()); |
+ // Adds the next URL. |
+ const GURL next_url( |
+ base::StringPrintf( |
+ "http://localhost/?start-index=%d&max-results=%d", |
+ start_index + max_results, |
+ max_results)); |
+ Link* link = new Link; |
+ link->set_type(Link::LINK_NEXT); |
+ link->set_href(next_url); |
+ resource_list->mutable_links()->push_back(link); |
+ } |
+ |
++resource_list_load_count_; |
MessageLoop::current()->PostTask( |
FROM_HERE, |