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

Unified 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: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
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 f0163ab0488cf5757b6484f7432136461f48f0e8..62c529ea7dc0349aa47d58a64ec60cd92bf6ea44 100644
--- a/chrome/browser/google_apis/fake_drive_service.cc
+++ b/chrome/browser/google_apis/fake_drive_service.cc
@@ -18,6 +18,7 @@
#include "chrome/browser/google_apis/drive_api_parser.h"
#include "chrome/browser/google_apis/gdata_wapi_parser.h"
#include "chrome/browser/google_apis/test_util.h"
+#include "chrome/browser/google_apis/time_util.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/escape.h"
@@ -919,6 +920,79 @@ void FakeDriveService::AuthorizeApp(const std::string& resource_id,
DCHECK(!callback.is_null());
}
+void FakeDriveService::AddNewFile(const std::string& content_type,
+ int64 content_length,
+ const std::string& parent_resource_id,
+ const std::string& title,
+ const GetResourceEntryCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!callback.is_null());
+
+ if (offline_) {
+ scoped_ptr<ResourceEntry> null;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ GDATA_NO_CONNECTION,
+ base::Passed(&null)));
+ return;
+ }
+
+ const base::DictionaryValue* new_entry = AddNewEntry(content_type,
+ content_length,
+ parent_resource_id,
+ title,
+ "file");
+ if (!new_entry) {
+ scoped_ptr<ResourceEntry> null;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null)));
+ return;
+ }
+
+ scoped_ptr<ResourceEntry> parsed_entry(
+ ResourceEntry::CreateFrom(*new_entry));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry)));
+}
+
+void FakeDriveService::SetLastModifiedTime(
+ const std::string& resource_id,
+ const base::Time& last_modified_time,
+ const GetResourceEntryCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!callback.is_null());
+
+ if (offline_) {
+ scoped_ptr<ResourceEntry> null;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ GDATA_NO_CONNECTION,
+ base::Passed(&null)));
+ return;
+ }
+
+ base::DictionaryValue* entry = FindEntryByResourceId(resource_id);
+ if (!entry) {
+ scoped_ptr<ResourceEntry> null;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null)));
+ return;
+ }
+
+ entry->SetString("updated.$t", util::FormatTimeAsString(last_modified_time));
+
+ scoped_ptr<ResourceEntry> parsed_entry(
+ ResourceEntry::CreateFrom(*entry));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, HTTP_CREATED, base::Passed(&parsed_entry)));
kinaba 2013/04/03 08:17:33 Header comment says it returns HTTP_SUCCESS rather
satorux1 2013/04/03 08:33:32 oops. you are right! fixed
+}
+
base::DictionaryValue* FakeDriveService::FindEntryByResourceId(
const std::string& resource_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

Powered by Google App Engine
This is Rietveld 408576698