Chromium Code Reviews| 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 c349337f0be0f4cbb71f423ca8f16cef794c120c..e02ce2d33e0d66727fee2aa3e08a201275cd229d 100644 |
| --- a/chrome/browser/google_apis/fake_drive_service.cc |
| +++ b/chrome/browser/google_apis/fake_drive_service.cc |
| @@ -5,6 +5,9 @@ |
| #include "chrome/browser/google_apis/fake_drive_service.h" |
| #include "base/logging.h" |
| +#include "base/message_loop.h" |
| +#include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| +#include "chrome/browser/google_apis/test_util.h" |
| #include "content/public/browser/browser_thread.h" |
| using content::BrowserThread; |
| @@ -19,6 +22,31 @@ FakeDriveService::~FakeDriveService() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| } |
| +bool FakeDriveService::LoadResourceListForWapi( |
| + const std::string& relative_path) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + scoped_ptr<Value> raw_value = test_util::LoadJSONFile(relative_path); |
| + base::DictionaryValue* as_dict = NULL; |
| + base::Value* feed = NULL; |
| + base::DictionaryValue* feed_as_dict = NULL; |
| + |
| + // Extract the "feed" from the raw value and take the ownership. |
| + if (raw_value->GetAsDictionary(&as_dict) && |
| + as_dict->Remove("feed", &feed) && |
| + feed->GetAsDictionary(&feed_as_dict)) { |
| + resource_list_value_.reset(feed_as_dict); |
|
kinaba
2013/01/08 08:26:53
Is this safe? |feed_as_dict| looks to be simultane
satorux1
2013/01/09 00:50:49
Should be safe. Remove() above transfers the owner
kinaba
2013/01/09 01:36:23
Ah, sorry, you're right.
|
| + } |
| + |
| + return resource_list_value_; |
| +} |
| + |
| +bool FakeDriveService::LoadAccountMetadataForWapi( |
| + const std::string& relative_path) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + account_metadata_value_ = test_util::LoadJSONFile(relative_path); |
| + return account_metadata_value_; |
| +} |
| + |
| void FakeDriveService::Initialize(Profile* profile) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| } |
| @@ -68,6 +96,14 @@ void FakeDriveService::GetResourceList( |
| const GetResourceListCallback& callback) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| DCHECK(!callback.is_null()); |
| + |
| + scoped_ptr<ResourceList> resource_list = |
| + ResourceList::CreateFrom(*resource_list_value_); |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(callback, |
| + HTTP_SUCCESS, |
| + base::Passed(&resource_list))); |
| } |
| void FakeDriveService::GetResourceEntry( |
| @@ -75,12 +111,43 @@ void FakeDriveService::GetResourceEntry( |
| const GetResourceEntryCallback& callback) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| DCHECK(!callback.is_null()); |
| + |
| + base::DictionaryValue* resource_list_dict = NULL; |
| + base::ListValue* entries = NULL; |
| + // Go through entries and return the one that matches |resource_id. |
| + if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| + resource_list_dict->GetList("entry", &entries)) { |
| + for (size_t i = 0; i < entries->GetSize(); ++i) { |
| + base::DictionaryValue* entry = NULL; |
| + base::DictionaryValue* resource_id_dict = NULL; |
| + std::string current_resource_id; |
| + if (entries->GetDictionary(i, &entry) && |
| + entry->GetDictionary("gd$resourceId", &resource_id_dict) && |
| + resource_id_dict->GetString("$t", ¤t_resource_id) && |
| + resource_id == current_resource_id) { |
| + scoped_ptr<ResourceEntry> resource_entry = |
| + ResourceEntry::CreateFrom(*entry); |
| + callback.Run(HTTP_SUCCESS, resource_entry.Pass()); |
|
kinaba
2013/01/08 08:26:53
We should better do PostTask here as well as in Ge
satorux1
2013/01/09 00:50:49
Good catch! Done.
|
| + return; |
| + } |
| + } |
| + } |
| + |
| + callback.Run(HTTP_NOT_FOUND, scoped_ptr<ResourceEntry>(NULL)); |
| } |
| void FakeDriveService::GetAccountMetadata( |
| const GetAccountMetadataCallback& callback) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| DCHECK(!callback.is_null()); |
| + |
| + scoped_ptr<AccountMetadataFeed> account_metadata = |
| + AccountMetadataFeed::CreateFrom(*account_metadata_value_); |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(callback, |
| + HTTP_SUCCESS, |
| + base::Passed(&account_metadata))); |
| } |
| void FakeDriveService::GetApplicationInfo( |
| @@ -94,6 +161,36 @@ void FakeDriveService::DeleteResource( |
| const EntryActionCallback& callback) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| DCHECK(!callback.is_null()); |
| + |
| + base::DictionaryValue* resource_list_dict = NULL; |
| + base::ListValue* entries = NULL; |
| + // Go through entries and remove one that matches |edit_url|. |
| + if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| + resource_list_dict->GetList("entry", &entries)) { |
| + for (size_t i = 0; i < entries->GetSize(); ++i) { |
| + base::DictionaryValue* entry = NULL; |
| + base::ListValue* links = NULL; |
| + if (entries->GetDictionary(i, &entry) && |
| + entry->GetList("link", &links)) { |
| + for (size_t j = 0; j < links->GetSize(); ++j) { |
| + base::DictionaryValue* link = NULL; |
| + std::string rel; |
| + std::string href; |
| + if (links->GetDictionary(j, &link) && |
| + link->GetString("rel", &rel) && |
| + link->GetString("href", &href) && |
| + rel == "edit" && |
| + GURL(href) == edit_url) { |
| + entries->Remove(i, NULL); |
| + callback.Run(HTTP_SUCCESS); |
| + return; |
| + } |
| + } |
| + } |
| + } |
| + } |
| + |
| + callback.Run(HTTP_NOT_FOUND); |
| } |
| void FakeDriveService::DownloadHostedDocument( |