Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: chrome/browser/google_apis/fake_drive_service.cc

Issue 13510003: google_apis: Introduce AddNewFile() and SetLastModifiedTime() in FakeDriveService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
16 #include "base/strings/string_tokenizer.h" 16 #include "base/strings/string_tokenizer.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "chrome/browser/google_apis/drive_api_parser.h" 18 #include "chrome/browser/google_apis/drive_api_parser.h"
19 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 19 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
20 #include "chrome/browser/google_apis/test_util.h" 20 #include "chrome/browser/google_apis/test_util.h"
21 #include "chrome/browser/google_apis/time_util.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "net/base/escape.h" 23 #include "net/base/escape.h"
23 24
24 using content::BrowserThread; 25 using content::BrowserThread;
25 26
26 namespace google_apis { 27 namespace google_apis {
27 namespace { 28 namespace {
28 29
29 // Rel property of upload link in the entries dictionary value. 30 // Rel property of upload link in the entries dictionary value.
30 const char kUploadUrlRel[] = 31 const char kUploadUrlRel[] =
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 base::Passed(&result_entry))); 913 base::Passed(&result_entry)));
913 } 914 }
914 915
915 void FakeDriveService::AuthorizeApp(const std::string& resource_id, 916 void FakeDriveService::AuthorizeApp(const std::string& resource_id,
916 const std::string& app_id, 917 const std::string& app_id,
917 const AuthorizeAppCallback& callback) { 918 const AuthorizeAppCallback& callback) {
918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
919 DCHECK(!callback.is_null()); 920 DCHECK(!callback.is_null());
920 } 921 }
921 922
923 void FakeDriveService::AddNewFile(const std::string& content_type,
924 int64 content_length,
925 const std::string& parent_resource_id,
926 const std::string& title,
927 const GetResourceEntryCallback& callback) {
928 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
929 DCHECK(!callback.is_null());
930
931 if (offline_) {
932 scoped_ptr<ResourceEntry> null;
933 MessageLoop::current()->PostTask(
934 FROM_HERE,
935 base::Bind(callback,
936 GDATA_NO_CONNECTION,
937 base::Passed(&null)));
938 return;
939 }
940
941 const base::DictionaryValue* new_entry = AddNewEntry(content_type,
942 content_length,
943 parent_resource_id,
944 title,
945 "file");
946 if (!new_entry) {
947 scoped_ptr<ResourceEntry> null;
948 MessageLoop::current()->PostTask(
949 FROM_HERE,
950 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null)));
951 return;
952 }
953
954 scoped_ptr<ResourceEntry> parsed_entry(
955 ResourceEntry::CreateFrom(*new_entry));
956 MessageLoop::current()->PostTask(
957 FROM_HERE,
958 base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry)));
959 }
960
961 void FakeDriveService::SetLastModifiedTime(
962 const std::string& resource_id,
963 const base::Time& last_modified_time,
964 const GetResourceEntryCallback& callback) {
965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
966 DCHECK(!callback.is_null());
967
968 if (offline_) {
969 scoped_ptr<ResourceEntry> null;
970 MessageLoop::current()->PostTask(
971 FROM_HERE,
972 base::Bind(callback,
973 GDATA_NO_CONNECTION,
974 base::Passed(&null)));
975 return;
976 }
977
978 base::DictionaryValue* entry = FindEntryByResourceId(resource_id);
979 if (!entry) {
980 scoped_ptr<ResourceEntry> null;
981 MessageLoop::current()->PostTask(
982 FROM_HERE,
983 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null)));
984 return;
985 }
986
987 entry->SetString("updated.$t", util::FormatTimeAsString(last_modified_time));
988
989 scoped_ptr<ResourceEntry> parsed_entry(
990 ResourceEntry::CreateFrom(*entry));
991 MessageLoop::current()->PostTask(
992 FROM_HERE,
993 base::Bind(callback, HTTP_SUCCESS, base::Passed(&parsed_entry)));
994 }
995
922 base::DictionaryValue* FakeDriveService::FindEntryByResourceId( 996 base::DictionaryValue* FakeDriveService::FindEntryByResourceId(
923 const std::string& resource_id) { 997 const std::string& resource_id) {
924 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 998 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
925 999
926 base::DictionaryValue* resource_list_dict = NULL; 1000 base::DictionaryValue* resource_list_dict = NULL;
927 base::ListValue* entries = NULL; 1001 base::ListValue* entries = NULL;
928 // Go through entries and return the one that matches |resource_id|. 1002 // Go through entries and return the one that matches |resource_id|.
929 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && 1003 if (resource_list_value_->GetAsDictionary(&resource_list_dict) &&
930 resource_list_dict->GetList("entry", &entries)) { 1004 resource_list_dict->GetList("entry", &entries)) {
931 for (size_t i = 0; i < entries->GetSize(); ++i) { 1005 for (size_t i = 0; i < entries->GetSize(); ++i) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 1164
1091 base::DictionaryValue* raw_new_entry = new_entry.release(); 1165 base::DictionaryValue* raw_new_entry = new_entry.release();
1092 base::ListValue* entries = NULL; 1166 base::ListValue* entries = NULL;
1093 if (resource_list_dict->GetList("entry", &entries)) 1167 if (resource_list_dict->GetList("entry", &entries))
1094 entries->Append(raw_new_entry); 1168 entries->Append(raw_new_entry);
1095 1169
1096 return raw_new_entry; 1170 return raw_new_entry;
1097 } 1171 }
1098 1172
1099 } // namespace google_apis 1173 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/fake_drive_service.h ('k') | chrome/browser/google_apis/fake_drive_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698