Chromium Code Reviews| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 using google_apis::ResourceEntry; | 55 using google_apis::ResourceEntry; |
| 56 using google_apis::ResourceList; | 56 using google_apis::ResourceList; |
| 57 using google_apis::UploadRangeCallback; | 57 using google_apis::UploadRangeCallback; |
| 58 using google_apis::UploadRangeResponse; | 58 using google_apis::UploadRangeResponse; |
| 59 namespace test_util = google_apis::test_util; | 59 namespace test_util = google_apis::test_util; |
| 60 namespace util = google_apis::util; | 60 namespace util = google_apis::util; |
| 61 | 61 |
| 62 namespace drive { | 62 namespace drive { |
| 63 namespace { | 63 namespace { |
| 64 | 64 |
| 65 // Rel property of upload link in the entries dictionary value. | 65 // Rel property of an upload link in the entries dictionary value. |
| 66 const char kUploadUrlRel[] = | 66 const char kUploadUrlRel[] = |
| 67 "http://schemas.google.com/g/2005#resumable-create-media"; | 67 "http://schemas.google.com/g/2005#resumable-create-media"; |
| 68 | 68 |
| 69 // Rel property of a share link in the entries dictionary value. | |
| 70 const char kShareUrlRel[] = | |
| 71 "http://schemas.google.com/docs/2007#share"; | |
| 72 | |
| 69 // Returns true if a resource entry matches with the search query. | 73 // Returns true if a resource entry matches with the search query. |
| 70 // Supports queries consist of following format. | 74 // Supports queries consist of following format. |
| 71 // - Phrases quoted by double/single quotes | 75 // - Phrases quoted by double/single quotes |
| 72 // - AND search for multiple words/phrases segmented by space | 76 // - AND search for multiple words/phrases segmented by space |
| 73 // - Limited attribute search. Only "title:" is supported. | 77 // - Limited attribute search. Only "title:" is supported. |
| 74 bool EntryMatchWithQuery(const ResourceEntry& entry, | 78 bool EntryMatchWithQuery(const ResourceEntry& entry, |
| 75 const std::string& query) { | 79 const std::string& query) { |
| 76 base::StringTokenizer tokenizer(query, " "); | 80 base::StringTokenizer tokenizer(query, " "); |
| 77 tokenizer.set_quote_chars("\"'"); | 81 tokenizer.set_quote_chars("\"'"); |
| 78 while (tokenizer.GetNext()) { | 82 while (tokenizer.GetNext()) { |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 928 scoped_ptr<ResourceEntry> null; | 932 scoped_ptr<ResourceEntry> null; |
| 929 base::MessageLoop::current()->PostTask( | 933 base::MessageLoop::current()->PostTask( |
| 930 FROM_HERE, | 934 FROM_HERE, |
| 931 base::Bind(callback, | 935 base::Bind(callback, |
| 932 GDATA_NO_CONNECTION, | 936 GDATA_NO_CONNECTION, |
| 933 base::Passed(&null))); | 937 base::Passed(&null))); |
| 934 return CancelCallback(); | 938 return CancelCallback(); |
| 935 } | 939 } |
| 936 | 940 |
| 937 const char kContentType[] = "application/atom+xml;type=feed"; | 941 const char kContentType[] = "application/atom+xml;type=feed"; |
| 942 const GURL share_url = share_url_base_.Resolve("?" + directory_title); | |
|
hidehiko
2013/08/05 15:07:44
Seems not used?
mtomasz
2013/08/05 15:18:31
Done.
| |
| 938 const base::DictionaryValue* new_entry = AddNewEntry(kContentType, | 943 const base::DictionaryValue* new_entry = AddNewEntry(kContentType, |
| 939 "", // content_data | 944 "", // content_data |
| 940 parent_resource_id, | 945 parent_resource_id, |
| 941 directory_title, | 946 directory_title, |
| 942 false, // shared_with_me | 947 false, // shared_with_me |
| 943 "folder"); | 948 "folder"); |
| 944 if (!new_entry) { | 949 if (!new_entry) { |
| 945 scoped_ptr<ResourceEntry> null; | 950 scoped_ptr<ResourceEntry> null; |
| 946 base::MessageLoop::current()->PostTask( | 951 base::MessageLoop::current()->PostTask( |
| 947 FROM_HERE, | 952 FROM_HERE, |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1382 | 1387 |
| 1383 base::DictionaryValue* edit_link = new base::DictionaryValue; | 1388 base::DictionaryValue* edit_link = new base::DictionaryValue; |
| 1384 edit_link->SetString("href", "https://xxx/edit/" + escaped_resource_id); | 1389 edit_link->SetString("href", "https://xxx/edit/" + escaped_resource_id); |
| 1385 edit_link->SetString("rel", "edit"); | 1390 edit_link->SetString("rel", "edit"); |
| 1386 links->Append(edit_link); | 1391 links->Append(edit_link); |
| 1387 | 1392 |
| 1388 base::DictionaryValue* upload_link = new base::DictionaryValue; | 1393 base::DictionaryValue* upload_link = new base::DictionaryValue; |
| 1389 upload_link->SetString("href", upload_url.spec()); | 1394 upload_link->SetString("href", upload_url.spec()); |
| 1390 upload_link->SetString("rel", kUploadUrlRel); | 1395 upload_link->SetString("rel", kUploadUrlRel); |
| 1391 links->Append(upload_link); | 1396 links->Append(upload_link); |
| 1397 | |
| 1398 const GURL share_url = share_url_base_.Resolve("?" + title); | |
|
hidehiko
2013/08/05 15:07:44
nit: Usually, we have key=value style query param.
mtomasz
2013/08/05 15:18:31
Sounds good to me.
| |
| 1399 base::DictionaryValue* share_link = new base::DictionaryValue; | |
| 1400 upload_link->SetString("href", share_url.spec()); | |
| 1401 upload_link->SetString("rel", kShareUrlRel); | |
| 1402 links->Append(share_link); | |
| 1392 new_entry->Set("link", links); | 1403 new_entry->Set("link", links); |
| 1393 | 1404 |
| 1394 AddNewChangestampAndETag(new_entry.get()); | 1405 AddNewChangestampAndETag(new_entry.get()); |
| 1395 | 1406 |
| 1396 base::Time published_date = | 1407 base::Time published_date = |
| 1397 base::Time() + base::TimeDelta::FromMilliseconds(++published_date_seq_); | 1408 base::Time() + base::TimeDelta::FromMilliseconds(++published_date_seq_); |
| 1398 new_entry->SetString("published.$t", | 1409 new_entry->SetString("published.$t", |
| 1399 util::FormatTimeAsString(published_date)); | 1410 util::FormatTimeAsString(published_date)); |
| 1400 | 1411 |
| 1401 // If there are no entries, prepare an empty entry to add. | 1412 // If there are no entries, prepare an empty entry to add. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1533 FROM_HERE, | 1544 FROM_HERE, |
| 1534 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_list))); | 1545 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_list))); |
| 1535 } | 1546 } |
| 1536 | 1547 |
| 1537 GURL FakeDriveService::GetNewUploadSessionUrl() { | 1548 GURL FakeDriveService::GetNewUploadSessionUrl() { |
| 1538 return GURL("https://upload_session_url/" + | 1549 return GURL("https://upload_session_url/" + |
| 1539 base::Int64ToString(next_upload_sequence_number_++)); | 1550 base::Int64ToString(next_upload_sequence_number_++)); |
| 1540 } | 1551 } |
| 1541 | 1552 |
| 1542 } // namespace drive | 1553 } // namespace drive |
| OLD | NEW |