summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google_apis
diff options
context:
space:
mode:
authorhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-04 13:44:21 +0000
committerhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-04 13:44:21 +0000
commit2547b65fa15904d748de5767de415fc6058d8ca6 (patch)
treec7a1b424c9d5d43634ee847937050989777dcad8 /chrome/browser/google_apis
parent8cea7fe46ffe7012a509906de98fe05e66609c6a (diff)
downloadchromium_src-2547b65fa15904d748de5767de415fc6058d8ca6.zip
chromium_src-2547b65fa15904d748de5767de415fc6058d8ca6.tar.gz
chromium_src-2547b65fa15904d748de5767de415fc6058d8ca6.tar.bz2
Implement GetAboutResource on GData WAPI.
This is a part of migration from GetAccountMetadata to GetAboutResrouce and GetAppList, which is designed based on the Drive API v2. This method is not actually used yet, but will be used in following CLs. BUG=174237 TEST=Ran unit_tests Review URL: https://chromiumcodereview.appspot.com/12395003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185890 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google_apis')
-rw-r--r--chrome/browser/google_apis/drive_api_parser.cc12
-rw-r--r--chrome/browser/google_apis/drive_api_parser.h9
-rw-r--r--chrome/browser/google_apis/drive_api_parser_unittest.cc19
-rw-r--r--chrome/browser/google_apis/fake_drive_service.cc13
-rw-r--r--chrome/browser/google_apis/gdata_wapi_service.cc45
5 files changed, 77 insertions, 21 deletions
diff --git a/chrome/browser/google_apis/drive_api_parser.cc b/chrome/browser/google_apis/drive_api_parser.cc
index 52faae2..be0fbec 100644
--- a/chrome/browser/google_apis/drive_api_parser.cc
+++ b/chrome/browser/google_apis/drive_api_parser.cc
@@ -198,6 +198,18 @@ scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) {
}
// static
+scoped_ptr<AboutResource> AboutResource::CreateFromAccountMetadata(
+ const AccountMetadata& account_metadata,
+ const std::string& root_resource_id) {
+ scoped_ptr<AboutResource> resource(new AboutResource);
+ resource->set_largest_change_id(account_metadata.largest_changestamp());
+ resource->set_quota_bytes_total(account_metadata.quota_bytes_total());
+ resource->set_quota_bytes_used(account_metadata.quota_bytes_used());
+ resource->set_root_folder_id(root_resource_id);
+ return resource.Pass();
+}
+
+// static
void AboutResource::RegisterJSONConverter(
base::JSONValueConverter<AboutResource>* converter) {
converter->RegisterCustomField<int64>(kLargestChangeId,
diff --git a/chrome/browser/google_apis/drive_api_parser.h b/chrome/browser/google_apis/drive_api_parser.h
index e1e7f99..e7612a4 100644
--- a/chrome/browser/google_apis/drive_api_parser.h
+++ b/chrome/browser/google_apis/drive_api_parser.h
@@ -50,6 +50,15 @@ class AboutResource {
// Creates about resource from parsed JSON.
static scoped_ptr<AboutResource> CreateFrom(const base::Value& value);
+ // Creates drive app icon instance from parsed AccountMetadata.
+ // It is also necessary to set |root_resource_id|, which is contained by
+ // AboutResource but not by AccountMetadata.
+ // This method is designed to migrate GData WAPI to Drive API v2.
+ // TODO(hidehiko): Remove this method once the migration is completed.
+ static scoped_ptr<AboutResource> CreateFromAccountMetadata(
+ const AccountMetadata& account_metadata,
+ const std::string& root_resource_id);
+
// Returns the largest change ID number.
int64 largest_change_id() const { return largest_change_id_; }
// Returns total number of quota bytes.
diff --git a/chrome/browser/google_apis/drive_api_parser_unittest.cc b/chrome/browser/google_apis/drive_api_parser_unittest.cc
index d280d6f..53a0f7b 100644
--- a/chrome/browser/google_apis/drive_api_parser_unittest.cc
+++ b/chrome/browser/google_apis/drive_api_parser_unittest.cc
@@ -42,6 +42,25 @@ TEST(DriveAPIParserTest, AboutResourceParser) {
EXPECT_EQ(8177LL, resource->largest_change_id());
}
+TEST(DriveAPIParserTest, AboutResourceFromAccountMetadata) {
+ AccountMetadata account_metadata;
+ // Set up AccountMetadata instance.
+ {
+ account_metadata.set_quota_bytes_total(10000);
+ account_metadata.set_quota_bytes_used(1000);
+ account_metadata.set_largest_changestamp(100);
+ }
+
+ scoped_ptr<AboutResource> about_resource(
+ AboutResource::CreateFromAccountMetadata(account_metadata,
+ "dummy_root_id"));
+
+ EXPECT_EQ(10000, about_resource->quota_bytes_total());
+ EXPECT_EQ(1000, about_resource->quota_bytes_used());
+ EXPECT_EQ(100, about_resource->largest_change_id());
+ EXPECT_EQ("dummy_root_id", about_resource->root_folder_id());
+}
+
// Test app list parsing.
TEST(DriveAPIParserTest, AppListParser) {
std::string error;
diff --git a/chrome/browser/google_apis/fake_drive_service.cc b/chrome/browser/google_apis/fake_drive_service.cc
index 129fc3e..6d8a8c9 100644
--- a/chrome/browser/google_apis/fake_drive_service.cc
+++ b/chrome/browser/google_apis/fake_drive_service.cc
@@ -388,15 +388,10 @@ void FakeDriveService::GetAboutResource(
}
++about_resource_load_count_;
- scoped_ptr<AccountMetadata> account_metadata =
- AccountMetadata::CreateFrom(*account_metadata_value_);
- scoped_ptr<AboutResource> about_resource(new AboutResource);
- about_resource->set_largest_change_id(
- account_metadata->largest_changestamp());
- about_resource->set_quota_bytes_total(account_metadata->quota_bytes_total());
- about_resource->set_quota_bytes_used(account_metadata->quota_bytes_used());
- about_resource->set_root_folder_id(GetRootResourceId());
-
+ scoped_ptr<AboutResource> about_resource(
+ AboutResource::CreateFromAccountMetadata(
+ *AccountMetadata::CreateFrom(*account_metadata_value_),
+ GetRootResourceId()));
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(callback,
diff --git a/chrome/browser/google_apis/gdata_wapi_service.cc b/chrome/browser/google_apis/gdata_wapi_service.cc
index c9f4051..df32d0a 100644
--- a/chrome/browser/google_apis/gdata_wapi_service.cc
+++ b/chrome/browser/google_apis/gdata_wapi_service.cc
@@ -28,6 +28,16 @@ namespace google_apis {
namespace {
+// OAuth2 scopes for the documents API.
+const char kDocsListScope[] = "https://docs.google.com/feeds/";
+const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/";
+const char kUserContentScope[] = "https://docs.googleusercontent.com/";
+const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps";
+
+// The resource ID for the root directory for WAPI is defined in the spec:
+// https://developers.google.com/google-apps/documents-list/
+const char kWapiRootDirectoryResourceId[] = "folder:root";
+
// Parses the JSON value to ResourceList.
scoped_ptr<ResourceList> ParseResourceListOnBlockingPool(
scoped_ptr<base::Value> value) {
@@ -121,6 +131,22 @@ void ExtractOpenLinkAndRun(const std::string app_id,
callback.Run(error, open_link);
}
+void ParseAboutResourceAndRun(
+ const GetAboutResourceCallback& callback,
+ GDataErrorCode error,
+ scoped_ptr<AccountMetadata> account_metadata) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!callback.is_null());
+
+ scoped_ptr<AboutResource> about_resource;
+ if (account_metadata) {
+ about_resource = AboutResource::CreateFromAccountMetadata(
+ *account_metadata, kWapiRootDirectoryResourceId);
+ }
+
+ callback.Run(error, about_resource.Pass());
+}
+
void ParseAppListAndRun(
const GetAppListCallback& callback,
GDataErrorCode error,
@@ -136,16 +162,6 @@ void ParseAppListAndRun(
callback.Run(error, app_list.Pass());
}
-// OAuth2 scopes for the documents API.
-const char kDocsListScope[] = "https://docs.google.com/feeds/";
-const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/";
-const char kUserContentScope[] = "https://docs.googleusercontent.com/";
-const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps";
-
-// The resource ID for the root directory for WAPI is defined in the spec:
-// https://developers.google.com/google-apps/documents-list/
-const char kWapiRootDirectoryResourceId[] = "folder:root";
-
} // namespace
GDataWapiService::GDataWapiService(
@@ -282,8 +298,13 @@ void GDataWapiService::GetAboutResource(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
- // TODO(hidehiko): Implement this.
- NOTREACHED();
+ runner_->StartOperationWithRetry(
+ new GetAccountMetadataOperation(
+ operation_registry(),
+ url_request_context_getter_,
+ url_generator_,
+ base::Bind(&ParseAboutResourceAndRun, callback),
+ false)); // Exclude installed apps.
}
void GDataWapiService::GetAppList(const GetAppListCallback& callback) {