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

Unified Diff: chrome/browser/google_apis/fake_drive_service.cc

Issue 11827045: google_apis: Add set_offline() to FakeDriveService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 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 168d02f8ec591c07a9ca78d97b621fe4043ee19a..b8c88ea8665dfc407438f199543f2aed91884128 100644
--- a/chrome/browser/google_apis/fake_drive_service.cc
+++ b/chrome/browser/google_apis/fake_drive_service.cc
@@ -17,7 +17,8 @@ using content::BrowserThread;
namespace google_apis {
FakeDriveService::FakeDriveService()
- : resource_id_count_(0) {
+ : resource_id_count_(0),
+ offline_(false) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
@@ -108,6 +109,16 @@ void FakeDriveService::GetResourceList(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+ if (offline_) {
+ scoped_ptr<ResourceList> null;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ GDATA_NO_CONNECTION,
+ base::Passed(&null)));
+ return;
+ }
+
scoped_ptr<ResourceList> resource_list =
ResourceList::CreateFrom(*resource_list_value_);
MessageLoop::current()->PostTask(
@@ -123,6 +134,16 @@ void FakeDriveService::GetResourceEntry(
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> resource_entry =
@@ -144,6 +165,15 @@ void FakeDriveService::GetAccountMetadata(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+ if (offline_) {
+ scoped_ptr<AccountMetadataFeed> null;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ GDATA_NO_CONNECTION,
+ base::Passed(&null)));
+ return;
+ }
scoped_ptr<AccountMetadataFeed> account_metadata =
AccountMetadataFeed::CreateFrom(*account_metadata_value_);
MessageLoop::current()->PostTask(
@@ -158,6 +188,16 @@ void FakeDriveService::GetApplicationInfo(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+ if (offline_) {
+ scoped_ptr<base::Value> null;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ GDATA_NO_CONNECTION,
+ base::Passed(&null)));
+ return;
+ }
+
scoped_ptr<base::Value> copied_app_info_value(
app_info_value_->DeepCopy());
MessageLoop::current()->PostTask(
@@ -174,6 +214,12 @@ void FakeDriveService::DeleteResource(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+ if (offline_) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION));
+ return;
+ }
+
base::DictionaryValue* resource_list_dict = NULL;
base::ListValue* entries = NULL;
// Go through entries and remove the one that matches |edit_url|.
@@ -226,6 +272,15 @@ void FakeDriveService::DownloadFile(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!download_action_callback.is_null());
+ if (offline_) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(download_action_callback,
+ GDATA_NO_CONNECTION,
+ FilePath()));
+ return;
+ }
+
base::DictionaryValue* entry = FindEntryByContentUrl(content_url);
if (!entry) {
base::MessageLoopProxy::current()->PostTask(
@@ -257,6 +312,16 @@ void FakeDriveService::CopyHostedDocument(
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* resource_list_dict = NULL;
base::ListValue* entries = NULL;
// Go through entries and copy the one that matches |resource_id|.
@@ -320,6 +385,12 @@ void FakeDriveService::RenameResource(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+ if (offline_) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION));
+ return;
+ }
+
base::DictionaryValue* entry = FindEntryByEditUrl(edit_url);
if (entry) {
entry->SetString("title.$t",
@@ -340,6 +411,12 @@ void FakeDriveService::AddResourceToDirectory(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+ if (offline_) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION));
+ return;
+ }
+
base::DictionaryValue* entry = FindEntryByEditUrl(edit_url);
if (entry) {
base::ListValue* links = NULL;
@@ -381,6 +458,12 @@ void FakeDriveService::RemoveResourceFromDirectory(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+ if (offline_) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION));
+ return;
+ }
+
base::DictionaryValue* entry = FindEntryByResourceId(resource_id);
if (entry) {
base::ListValue* links = NULL;
@@ -414,6 +497,16 @@ void FakeDriveService::AddNewDirectory(
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;
+ }
+
// If the parent content URL is not empty, the parent should exist.
if (!parent_content_url.is_empty()) {
base::DictionaryValue* parent_entry =
@@ -590,6 +683,8 @@ base::DictionaryValue* FakeDriveService::FindEntryByContentUrl(
}
std::string FakeDriveService::GetNewResourceId() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
++resource_id_count_;
return base::StringPrintf("resource_id_%d", resource_id_count_);
}
« 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