| 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 15 matching lines...) Expand all Loading... |
| 26 #include "net/base/url_util.h" | 26 #include "net/base/url_util.h" |
| 27 | 27 |
| 28 using content::BrowserThread; | 28 using content::BrowserThread; |
| 29 using google_apis::AboutResource; | 29 using google_apis::AboutResource; |
| 30 using google_apis::AboutResourceCallback; | 30 using google_apis::AboutResourceCallback; |
| 31 using google_apis::AppList; | 31 using google_apis::AppList; |
| 32 using google_apis::AppListCallback; | 32 using google_apis::AppListCallback; |
| 33 using google_apis::AuthStatusCallback; | 33 using google_apis::AuthStatusCallback; |
| 34 using google_apis::AuthorizeAppCallback; | 34 using google_apis::AuthorizeAppCallback; |
| 35 using google_apis::CancelCallback; | 35 using google_apis::CancelCallback; |
| 36 using google_apis::ChangeList; |
| 37 using google_apis::ChangeListCallback; |
| 36 using google_apis::ChangeResource; | 38 using google_apis::ChangeResource; |
| 37 using google_apis::DownloadActionCallback; | 39 using google_apis::DownloadActionCallback; |
| 38 using google_apis::EntryActionCallback; | 40 using google_apis::EntryActionCallback; |
| 39 using google_apis::FileResource; | 41 using google_apis::FileResource; |
| 40 using google_apis::GDATA_FILE_ERROR; | 42 using google_apis::GDATA_FILE_ERROR; |
| 41 using google_apis::GDATA_NO_CONNECTION; | 43 using google_apis::GDATA_NO_CONNECTION; |
| 42 using google_apis::GDATA_OTHER_ERROR; | 44 using google_apis::GDATA_OTHER_ERROR; |
| 43 using google_apis::GDataErrorCode; | 45 using google_apis::GDataErrorCode; |
| 44 using google_apis::GetContentCallback; | 46 using google_apis::GetContentCallback; |
| 45 using google_apis::GetResourceEntryCallback; | 47 using google_apis::GetResourceEntryCallback; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 63 namespace test_util = google_apis::test_util; | 65 namespace test_util = google_apis::test_util; |
| 64 | 66 |
| 65 namespace drive { | 67 namespace drive { |
| 66 namespace { | 68 namespace { |
| 67 | 69 |
| 68 // Returns true if a resource entry matches with the search query. | 70 // Returns true if a resource entry matches with the search query. |
| 69 // Supports queries consist of following format. | 71 // Supports queries consist of following format. |
| 70 // - Phrases quoted by double/single quotes | 72 // - Phrases quoted by double/single quotes |
| 71 // - AND search for multiple words/phrases segmented by space | 73 // - AND search for multiple words/phrases segmented by space |
| 72 // - Limited attribute search. Only "title:" is supported. | 74 // - Limited attribute search. Only "title:" is supported. |
| 73 bool EntryMatchWithQuery(const ResourceEntry& entry, | 75 bool EntryMatchWithQuery(const ChangeResource& entry, |
| 74 const std::string& query) { | 76 const std::string& query) { |
| 75 base::StringTokenizer tokenizer(query, " "); | 77 base::StringTokenizer tokenizer(query, " "); |
| 76 tokenizer.set_quote_chars("\"'"); | 78 tokenizer.set_quote_chars("\"'"); |
| 77 while (tokenizer.GetNext()) { | 79 while (tokenizer.GetNext()) { |
| 78 std::string key, value; | 80 std::string key, value; |
| 79 const std::string& token = tokenizer.token(); | 81 const std::string& token = tokenizer.token(); |
| 80 if (token.find(':') == std::string::npos) { | 82 if (token.find(':') == std::string::npos) { |
| 81 base::TrimString(token, "\"'", &value); | 83 base::TrimString(token, "\"'", &value); |
| 82 } else { | 84 } else { |
| 83 base::StringTokenizer key_value(token, ":"); | 85 base::StringTokenizer key_value(token, ":"); |
| 84 key_value.set_quote_chars("\"'"); | 86 key_value.set_quote_chars("\"'"); |
| 85 if (!key_value.GetNext()) | 87 if (!key_value.GetNext()) |
| 86 return false; | 88 return false; |
| 87 key = key_value.token(); | 89 key = key_value.token(); |
| 88 if (!key_value.GetNext()) | 90 if (!key_value.GetNext()) |
| 89 return false; | 91 return false; |
| 90 base::TrimString(key_value.token(), "\"'", &value); | 92 base::TrimString(key_value.token(), "\"'", &value); |
| 91 } | 93 } |
| 92 | 94 |
| 93 // TODO(peria): Deal with other attributes than title. | 95 // TODO(peria): Deal with other attributes than title. |
| 94 if (!key.empty() && key != "title") | 96 if (!key.empty() && key != "title") |
| 95 return false; | 97 return false; |
| 96 // Search query in the title. | 98 // Search query in the title. |
| 97 if (entry.title().find(value) == std::string::npos) | 99 if (!entry.file() || |
| 100 entry.file()->title().find(value) == std::string::npos) |
| 98 return false; | 101 return false; |
| 99 } | 102 } |
| 100 return true; | 103 return true; |
| 101 } | 104 } |
| 102 | 105 |
| 103 void ScheduleUploadRangeCallback(const UploadRangeCallback& callback, | 106 void ScheduleUploadRangeCallback(const UploadRangeCallback& callback, |
| 104 int64 start_position, | 107 int64 start_position, |
| 105 int64 end_position, | 108 int64 end_position, |
| 106 GDataErrorCode error, | 109 GDataErrorCode error, |
| 107 scoped_ptr<ResourceEntry> entry) { | 110 scoped_ptr<ResourceEntry> entry) { |
| 108 base::MessageLoop::current()->PostTask( | 111 base::MessageLoop::current()->PostTask( |
| 109 FROM_HERE, | 112 FROM_HERE, |
| 110 base::Bind(callback, | 113 base::Bind(callback, |
| 111 UploadRangeResponse(error, | 114 UploadRangeResponse(error, |
| 112 start_position, | 115 start_position, |
| 113 end_position), | 116 end_position), |
| 114 base::Passed(&entry))); | 117 base::Passed(&entry))); |
| 115 } | 118 } |
| 116 | 119 |
| 117 void EntryActionCallbackAdapter( | 120 void EntryActionCallbackAdapter( |
| 118 const EntryActionCallback& callback, | 121 const EntryActionCallback& callback, |
| 119 GDataErrorCode error, scoped_ptr<ResourceEntry> resource_entry) { | 122 GDataErrorCode error, scoped_ptr<ResourceEntry> resource_entry) { |
| 120 callback.Run(error); | 123 callback.Run(error); |
| 121 } | 124 } |
| 122 | 125 |
| 126 void GetResourceListCallbackAdapter(const GetResourceListCallback& callback, |
| 127 GDataErrorCode error, |
| 128 scoped_ptr<ChangeList> change_list) { |
| 129 callback.Run(error, change_list ? |
| 130 util::ConvertChangeListToResourceList(*change_list) : |
| 131 scoped_ptr<ResourceList>()); |
| 132 } |
| 133 |
| 123 } // namespace | 134 } // namespace |
| 124 | 135 |
| 125 struct FakeDriveService::EntryInfo { | 136 struct FakeDriveService::EntryInfo { |
| 126 google_apis::ChangeResource change_resource; | 137 google_apis::ChangeResource change_resource; |
| 127 GURL share_url; | 138 GURL share_url; |
| 128 std::string content_data; | 139 std::string content_data; |
| 129 }; | 140 }; |
| 130 | 141 |
| 131 struct FakeDriveService::UploadSession { | 142 struct FakeDriveService::UploadSession { |
| 132 std::string content_type; | 143 std::string content_type; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 ++blocked_resource_list_load_count_; | 279 ++blocked_resource_list_load_count_; |
| 269 return CancelCallback(); | 280 return CancelCallback(); |
| 270 } | 281 } |
| 271 | 282 |
| 272 GetResourceListInternal(0, // start changestamp | 283 GetResourceListInternal(0, // start changestamp |
| 273 std::string(), // empty search query | 284 std::string(), // empty search query |
| 274 std::string(), // no directory resource id, | 285 std::string(), // no directory resource id, |
| 275 0, // start offset | 286 0, // start offset |
| 276 default_max_results_, | 287 default_max_results_, |
| 277 &resource_list_load_count_, | 288 &resource_list_load_count_, |
| 278 callback); | 289 base::Bind(&GetResourceListCallbackAdapter, |
| 290 callback)); |
| 279 return CancelCallback(); | 291 return CancelCallback(); |
| 280 } | 292 } |
| 281 | 293 |
| 282 CancelCallback FakeDriveService::GetResourceListInDirectory( | 294 CancelCallback FakeDriveService::GetResourceListInDirectory( |
| 283 const std::string& directory_resource_id, | 295 const std::string& directory_resource_id, |
| 284 const GetResourceListCallback& callback) { | 296 const GetResourceListCallback& callback) { |
| 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 286 DCHECK(!directory_resource_id.empty()); | 298 DCHECK(!directory_resource_id.empty()); |
| 287 DCHECK(!callback.is_null()); | 299 DCHECK(!callback.is_null()); |
| 288 | 300 |
| 289 GetResourceListInternal(0, // start changestamp | 301 GetResourceListInternal(0, // start changestamp |
| 290 std::string(), // empty search query | 302 std::string(), // empty search query |
| 291 directory_resource_id, | 303 directory_resource_id, |
| 292 0, // start offset | 304 0, // start offset |
| 293 default_max_results_, | 305 default_max_results_, |
| 294 &directory_load_count_, | 306 &directory_load_count_, |
| 295 callback); | 307 base::Bind(&GetResourceListCallbackAdapter, |
| 308 callback)); |
| 296 return CancelCallback(); | 309 return CancelCallback(); |
| 297 } | 310 } |
| 298 | 311 |
| 299 CancelCallback FakeDriveService::Search( | 312 CancelCallback FakeDriveService::Search( |
| 300 const std::string& search_query, | 313 const std::string& search_query, |
| 301 const GetResourceListCallback& callback) { | 314 const GetResourceListCallback& callback) { |
| 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 303 DCHECK(!search_query.empty()); | 316 DCHECK(!search_query.empty()); |
| 304 DCHECK(!callback.is_null()); | 317 DCHECK(!callback.is_null()); |
| 305 | 318 |
| 306 GetResourceListInternal(0, // start changestamp | 319 GetResourceListInternal(0, // start changestamp |
| 307 search_query, | 320 search_query, |
| 308 std::string(), // no directory resource id, | 321 std::string(), // no directory resource id, |
| 309 0, // start offset | 322 0, // start offset |
| 310 default_max_results_, | 323 default_max_results_, |
| 311 NULL, | 324 NULL, |
| 312 callback); | 325 base::Bind(&GetResourceListCallbackAdapter, |
| 326 callback)); |
| 313 return CancelCallback(); | 327 return CancelCallback(); |
| 314 } | 328 } |
| 315 | 329 |
| 316 CancelCallback FakeDriveService::SearchByTitle( | 330 CancelCallback FakeDriveService::SearchByTitle( |
| 317 const std::string& title, | 331 const std::string& title, |
| 318 const std::string& directory_resource_id, | 332 const std::string& directory_resource_id, |
| 319 const GetResourceListCallback& callback) { | 333 const GetResourceListCallback& callback) { |
| 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 321 DCHECK(!title.empty()); | 335 DCHECK(!title.empty()); |
| 322 DCHECK(!callback.is_null()); | 336 DCHECK(!callback.is_null()); |
| 323 | 337 |
| 324 // Note: the search implementation here doesn't support quotation unescape, | 338 // Note: the search implementation here doesn't support quotation unescape, |
| 325 // so don't escape here. | 339 // so don't escape here. |
| 326 GetResourceListInternal(0, // start changestamp | 340 GetResourceListInternal(0, // start changestamp |
| 327 base::StringPrintf("title:'%s'", title.c_str()), | 341 base::StringPrintf("title:'%s'", title.c_str()), |
| 328 directory_resource_id, | 342 directory_resource_id, |
| 329 0, // start offset | 343 0, // start offset |
| 330 default_max_results_, | 344 default_max_results_, |
| 331 NULL, | 345 NULL, |
| 332 callback); | 346 base::Bind(&GetResourceListCallbackAdapter, |
| 347 callback)); |
| 333 return CancelCallback(); | 348 return CancelCallback(); |
| 334 } | 349 } |
| 335 | 350 |
| 336 CancelCallback FakeDriveService::GetChangeList( | 351 CancelCallback FakeDriveService::GetChangeList( |
| 337 int64 start_changestamp, | 352 int64 start_changestamp, |
| 338 const GetResourceListCallback& callback) { | 353 const ChangeListCallback& callback) { |
| 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 340 DCHECK(!callback.is_null()); | 355 DCHECK(!callback.is_null()); |
| 341 | 356 |
| 342 GetResourceListInternal(start_changestamp, | 357 GetResourceListInternal(start_changestamp, |
| 343 std::string(), // empty search query | 358 std::string(), // empty search query |
| 344 std::string(), // no directory resource id, | 359 std::string(), // no directory resource id, |
| 345 0, // start offset | 360 0, // start offset |
| 346 default_max_results_, | 361 default_max_results_, |
| 347 &change_list_load_count_, | 362 &change_list_load_count_, |
| 348 callback); | 363 callback); |
| 349 return CancelCallback(); | 364 return CancelCallback(); |
| 350 } | 365 } |
| 351 | 366 |
| 352 CancelCallback FakeDriveService::GetRemainingChangeList( | 367 CancelCallback FakeDriveService::GetRemainingChangeList( |
| 353 const GURL& next_link, | 368 const GURL& next_link, |
| 354 const GetResourceListCallback& callback) { | 369 const ChangeListCallback& callback) { |
| 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 356 DCHECK(!next_link.is_empty()); | 371 DCHECK(!next_link.is_empty()); |
| 357 DCHECK(!callback.is_null()); | 372 DCHECK(!callback.is_null()); |
| 358 | 373 |
| 359 // "changestamp", "q", "parent" and "start-offset" are parameters to | 374 // "changestamp", "q", "parent" and "start-offset" are parameters to |
| 360 // implement "paging" of the result on FakeDriveService. | 375 // implement "paging" of the result on FakeDriveService. |
| 361 // The URL should be the one filled in GetResourceListInternal of the | 376 // The URL should be the one filled in GetResourceListInternal of the |
| 362 // previous method invocation, so it should start with "http://localhost/?". | 377 // previous method invocation, so it should start with "http://localhost/?". |
| 363 // See also GetResourceListInternal. | 378 // See also GetResourceListInternal. |
| 364 DCHECK_EQ(next_link.host(), "localhost"); | 379 DCHECK_EQ(next_link.host(), "localhost"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 return CancelCallback(); | 412 return CancelCallback(); |
| 398 } | 413 } |
| 399 | 414 |
| 400 CancelCallback FakeDriveService::GetRemainingFileList( | 415 CancelCallback FakeDriveService::GetRemainingFileList( |
| 401 const GURL& next_link, | 416 const GURL& next_link, |
| 402 const GetResourceListCallback& callback) { | 417 const GetResourceListCallback& callback) { |
| 403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 404 DCHECK(!next_link.is_empty()); | 419 DCHECK(!next_link.is_empty()); |
| 405 DCHECK(!callback.is_null()); | 420 DCHECK(!callback.is_null()); |
| 406 | 421 |
| 407 return GetRemainingChangeList(next_link, callback); | 422 return GetRemainingChangeList( |
| 423 next_link, base::Bind(&GetResourceListCallbackAdapter, callback)); |
| 408 } | 424 } |
| 409 | 425 |
| 410 CancelCallback FakeDriveService::GetResourceEntry( | 426 CancelCallback FakeDriveService::GetResourceEntry( |
| 411 const std::string& resource_id, | 427 const std::string& resource_id, |
| 412 const GetResourceEntryCallback& callback) { | 428 const GetResourceEntryCallback& callback) { |
| 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 414 DCHECK(!callback.is_null()); | 430 DCHECK(!callback.is_null()); |
| 415 | 431 |
| 416 if (offline_) { | 432 if (offline_) { |
| 417 scoped_ptr<ResourceEntry> null; | 433 scoped_ptr<ResourceEntry> null; |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 return raw_new_entry; | 1385 return raw_new_entry; |
| 1370 } | 1386 } |
| 1371 | 1387 |
| 1372 void FakeDriveService::GetResourceListInternal( | 1388 void FakeDriveService::GetResourceListInternal( |
| 1373 int64 start_changestamp, | 1389 int64 start_changestamp, |
| 1374 const std::string& search_query, | 1390 const std::string& search_query, |
| 1375 const std::string& directory_resource_id, | 1391 const std::string& directory_resource_id, |
| 1376 int start_offset, | 1392 int start_offset, |
| 1377 int max_results, | 1393 int max_results, |
| 1378 int* load_counter, | 1394 int* load_counter, |
| 1379 const GetResourceListCallback& callback) { | 1395 const ChangeListCallback& callback) { |
| 1380 if (offline_) { | 1396 if (offline_) { |
| 1381 base::MessageLoop::current()->PostTask( | 1397 base::MessageLoop::current()->PostTask( |
| 1382 FROM_HERE, | 1398 FROM_HERE, |
| 1383 base::Bind(callback, | 1399 base::Bind(callback, |
| 1384 GDATA_NO_CONNECTION, | 1400 GDATA_NO_CONNECTION, |
| 1385 base::Passed(scoped_ptr<ResourceList>()))); | 1401 base::Passed(scoped_ptr<ChangeList>()))); |
| 1386 return; | 1402 return; |
| 1387 } | 1403 } |
| 1388 | 1404 |
| 1389 // Filter out entries per parameters like |directory_resource_id| and | 1405 // Filter out entries per parameters like |directory_resource_id| and |
| 1390 // |search_query|. | 1406 // |search_query|. |
| 1391 ScopedVector<ResourceEntry> entries; | 1407 ScopedVector<ChangeResource> entries; |
| 1392 int num_entries_matched = 0; | 1408 int num_entries_matched = 0; |
| 1393 for (EntryInfoMap::iterator it = entries_.begin(); it != entries_.end(); | 1409 for (EntryInfoMap::iterator it = entries_.begin(); it != entries_.end(); |
| 1394 ++it) { | 1410 ++it) { |
| 1395 scoped_ptr<ResourceEntry> entry = | 1411 const ChangeResource& entry = it->second->change_resource; |
| 1396 util::ConvertChangeResourceToResourceEntry(it->second->change_resource); | |
| 1397 bool should_exclude = false; | 1412 bool should_exclude = false; |
| 1398 | 1413 |
| 1399 // If |directory_resource_id| is set, exclude the entry if it's not in | 1414 // If |directory_resource_id| is set, exclude the entry if it's not in |
| 1400 // the target directory. | 1415 // the target directory. |
| 1401 if (!directory_resource_id.empty()) { | 1416 if (!directory_resource_id.empty()) { |
| 1402 // Get the parent resource ID of the entry. | 1417 // Get the parent resource ID of the entry. |
| 1403 std::string parent_resource_id; | 1418 std::string parent_resource_id; |
| 1404 const google_apis::Link* parent_link = | 1419 if (entry.file() && !entry.file()->parents().empty()) |
| 1405 entry->GetLinkByType(Link::LINK_PARENT); | 1420 parent_resource_id = entry.file()->parents()[0].file_id(); |
| 1406 if (parent_link) { | 1421 |
| 1407 parent_resource_id = | |
| 1408 net::UnescapeURLComponent(parent_link->href().ExtractFileName(), | |
| 1409 net::UnescapeRule::URL_SPECIAL_CHARS); | |
| 1410 } | |
| 1411 if (directory_resource_id != parent_resource_id) | 1422 if (directory_resource_id != parent_resource_id) |
| 1412 should_exclude = true; | 1423 should_exclude = true; |
| 1413 } | 1424 } |
| 1414 | 1425 |
| 1415 // If |search_query| is set, exclude the entry if it does not contain the | 1426 // If |search_query| is set, exclude the entry if it does not contain the |
| 1416 // search query in the title. | 1427 // search query in the title. |
| 1417 if (!should_exclude && !search_query.empty() && | 1428 if (!should_exclude && !search_query.empty() && |
| 1418 !EntryMatchWithQuery(*entry, search_query)) { | 1429 !EntryMatchWithQuery(entry, search_query)) { |
| 1419 should_exclude = true; | 1430 should_exclude = true; |
| 1420 } | 1431 } |
| 1421 | 1432 |
| 1422 // If |start_changestamp| is set, exclude the entry if the | 1433 // If |start_changestamp| is set, exclude the entry if the |
| 1423 // changestamp is older than |largest_changestamp|. | 1434 // changestamp is older than |largest_changestamp|. |
| 1424 // See https://developers.google.com/google-apps/documents-list/ | 1435 // See https://developers.google.com/google-apps/documents-list/ |
| 1425 // #retrieving_all_changes_since_a_given_changestamp | 1436 // #retrieving_all_changes_since_a_given_changestamp |
| 1426 if (start_changestamp > 0 && entry->changestamp() < start_changestamp) | 1437 if (start_changestamp > 0 && entry.change_id() < start_changestamp) |
| 1427 should_exclude = true; | 1438 should_exclude = true; |
| 1428 | 1439 |
| 1429 // If the caller requests other list than change list by specifying | 1440 // If the caller requests other list than change list by specifying |
| 1430 // zero-|start_changestamp|, exclude deleted entry from the result. | 1441 // zero-|start_changestamp|, exclude deleted entry from the result. |
| 1431 if (!start_changestamp && entry->deleted()) | 1442 const bool deleted = entry.is_deleted() || |
| 1443 (entry.file() && entry.file()->labels().is_trashed()); |
| 1444 if (!start_changestamp && deleted) |
| 1432 should_exclude = true; | 1445 should_exclude = true; |
| 1433 | 1446 |
| 1434 // The entry matched the criteria for inclusion. | 1447 // The entry matched the criteria for inclusion. |
| 1435 if (!should_exclude) | 1448 if (!should_exclude) |
| 1436 ++num_entries_matched; | 1449 ++num_entries_matched; |
| 1437 | 1450 |
| 1438 // If |start_offset| is set, exclude the entry if the entry is before the | 1451 // If |start_offset| is set, exclude the entry if the entry is before the |
| 1439 // start index. <= instead of < as |num_entries_matched| was | 1452 // start index. <= instead of < as |num_entries_matched| was |
| 1440 // already incremented. | 1453 // already incremented. |
| 1441 if (start_offset > 0 && num_entries_matched <= start_offset) | 1454 if (start_offset > 0 && num_entries_matched <= start_offset) |
| 1442 should_exclude = true; | 1455 should_exclude = true; |
| 1443 | 1456 |
| 1444 if (!should_exclude) | 1457 if (!should_exclude) { |
| 1445 entries.push_back(entry.release()); | 1458 scoped_ptr<ChangeResource> entry_copied(new ChangeResource); |
| 1459 entry_copied->set_change_id(entry.change_id()); |
| 1460 entry_copied->set_file_id(entry.file_id()); |
| 1461 entry_copied->set_deleted(entry.is_deleted()); |
| 1462 if (entry.file()) { |
| 1463 entry_copied->set_file( |
| 1464 make_scoped_ptr(new FileResource(*entry.file()))); |
| 1465 } |
| 1466 entry_copied->set_modification_date(entry.modification_date()); |
| 1467 entries.push_back(entry_copied.release()); |
| 1468 } |
| 1446 } | 1469 } |
| 1447 | 1470 |
| 1448 scoped_ptr<ResourceList> resource_list(new ResourceList); | 1471 scoped_ptr<ChangeList> change_list(new ChangeList); |
| 1449 if (start_changestamp > 0 && start_offset == 0) { | 1472 if (start_changestamp > 0 && start_offset == 0) { |
| 1450 resource_list->set_largest_changestamp( | 1473 change_list->set_largest_change_id(about_resource_->largest_change_id()); |
| 1451 about_resource_->largest_change_id()); | |
| 1452 } | 1474 } |
| 1453 | 1475 |
| 1454 // If |max_results| is set, trim the entries if the number exceeded the max | 1476 // If |max_results| is set, trim the entries if the number exceeded the max |
| 1455 // results. | 1477 // results. |
| 1456 if (max_results > 0 && entries.size() > static_cast<size_t>(max_results)) { | 1478 if (max_results > 0 && entries.size() > static_cast<size_t>(max_results)) { |
| 1457 entries.erase(entries.begin() + max_results, entries.end()); | 1479 entries.erase(entries.begin() + max_results, entries.end()); |
| 1458 // Adds the next URL. | 1480 // Adds the next URL. |
| 1459 // Here, we embed information which is needed for continuing the | 1481 // Here, we embed information which is needed for continuing the |
| 1460 // GetResourceList request in the next invocation into url query | 1482 // GetResourceList request in the next invocation into url query |
| 1461 // parameters. | 1483 // parameters. |
| 1462 GURL next_url(base::StringPrintf( | 1484 GURL next_url(base::StringPrintf( |
| 1463 "http://localhost/?start-offset=%d&max-results=%d", | 1485 "http://localhost/?start-offset=%d&max-results=%d", |
| 1464 start_offset + max_results, | 1486 start_offset + max_results, |
| 1465 max_results)); | 1487 max_results)); |
| 1466 if (start_changestamp > 0) { | 1488 if (start_changestamp > 0) { |
| 1467 next_url = net::AppendOrReplaceQueryParameter( | 1489 next_url = net::AppendOrReplaceQueryParameter( |
| 1468 next_url, "changestamp", | 1490 next_url, "changestamp", |
| 1469 base::Int64ToString(start_changestamp).c_str()); | 1491 base::Int64ToString(start_changestamp).c_str()); |
| 1470 } | 1492 } |
| 1471 if (!search_query.empty()) { | 1493 if (!search_query.empty()) { |
| 1472 next_url = net::AppendOrReplaceQueryParameter( | 1494 next_url = net::AppendOrReplaceQueryParameter( |
| 1473 next_url, "q", search_query); | 1495 next_url, "q", search_query); |
| 1474 } | 1496 } |
| 1475 if (!directory_resource_id.empty()) { | 1497 if (!directory_resource_id.empty()) { |
| 1476 next_url = net::AppendOrReplaceQueryParameter( | 1498 next_url = net::AppendOrReplaceQueryParameter( |
| 1477 next_url, "parent", directory_resource_id); | 1499 next_url, "parent", directory_resource_id); |
| 1478 } | 1500 } |
| 1479 | 1501 |
| 1480 Link* link = new Link; | 1502 change_list->set_next_link(next_url); |
| 1481 link->set_type(Link::LINK_NEXT); | |
| 1482 link->set_href(next_url); | |
| 1483 resource_list->mutable_links()->push_back(link); | |
| 1484 } | 1503 } |
| 1485 resource_list->set_entries(entries.Pass()); | 1504 *change_list->mutable_items() = entries.Pass(); |
| 1486 | 1505 |
| 1487 if (load_counter) | 1506 if (load_counter) |
| 1488 *load_counter += 1; | 1507 *load_counter += 1; |
| 1489 base::MessageLoop::current()->PostTask( | 1508 base::MessageLoop::current()->PostTask( |
| 1490 FROM_HERE, | 1509 FROM_HERE, |
| 1491 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_list))); | 1510 base::Bind(callback, HTTP_SUCCESS, base::Passed(&change_list))); |
| 1492 } | 1511 } |
| 1493 | 1512 |
| 1494 GURL FakeDriveService::GetNewUploadSessionUrl() { | 1513 GURL FakeDriveService::GetNewUploadSessionUrl() { |
| 1495 return GURL("https://upload_session_url/" + | 1514 return GURL("https://upload_session_url/" + |
| 1496 base::Int64ToString(next_upload_sequence_number_++)); | 1515 base::Int64ToString(next_upload_sequence_number_++)); |
| 1497 } | 1516 } |
| 1498 | 1517 |
| 1499 google_apis::CancelCallback FakeDriveService::AddPermission( | 1518 google_apis::CancelCallback FakeDriveService::AddPermission( |
| 1500 const std::string& resource_id, | 1519 const std::string& resource_id, |
| 1501 const std::string& email, | 1520 const std::string& email, |
| 1502 google_apis::drive::PermissionRole role, | 1521 google_apis::drive::PermissionRole role, |
| 1503 const google_apis::EntryActionCallback& callback) { | 1522 const google_apis::EntryActionCallback& callback) { |
| 1504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1505 DCHECK(!callback.is_null()); | 1524 DCHECK(!callback.is_null()); |
| 1506 | 1525 |
| 1507 NOTREACHED(); | 1526 NOTREACHED(); |
| 1508 return CancelCallback(); | 1527 return CancelCallback(); |
| 1509 } | 1528 } |
| 1510 | 1529 |
| 1511 } // namespace drive | 1530 } // namespace drive |
| OLD | NEW |