diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-05 02:12:46 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-05 02:12:46 +0000 |
commit | 63049bbbeeebdeaf7eced730f8b247d5c8e6928e (patch) | |
tree | 585b477fd56779dce255d103cadf4bf335396581 /google_apis | |
parent | f6d2cba2529f2e4d828bd0e516eec7ab8169fdd6 (diff) | |
download | chromium_src-63049bbbeeebdeaf7eced730f8b247d5c8e6928e.zip chromium_src-63049bbbeeebdeaf7eced730f8b247d5c8e6928e.tar.gz chromium_src-63049bbbeeebdeaf7eced730f8b247d5c8e6928e.tar.bz2 |
Parse "removable" and "productId" fields from apps.list response.
BUG=334966
R=hashimoto@chromium.org
Review URL: https://codereview.chromium.org/132333006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248831 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/drive/drive_api_parser.cc | 11 | ||||
-rw-r--r-- | google_apis/drive/drive_api_parser.h | 15 | ||||
-rw-r--r-- | google_apis/drive/drive_api_parser_unittest.cc | 10 | ||||
-rw-r--r-- | google_apis/drive/drive_api_requests.cc | 6 | ||||
-rw-r--r-- | google_apis/drive/drive_api_requests.h | 2 | ||||
-rw-r--r-- | google_apis/drive/drive_api_requests_unittest.cc | 1 | ||||
-rw-r--r-- | google_apis/drive/drive_api_url_generator.cc | 7 | ||||
-rw-r--r-- | google_apis/drive/drive_api_url_generator.h | 4 | ||||
-rw-r--r-- | google_apis/drive/drive_api_url_generator_unittest.cc | 7 |
9 files changed, 39 insertions, 24 deletions
diff --git a/google_apis/drive/drive_api_parser.cc b/google_apis/drive/drive_api_parser.cc index cefbc21..48fe312 100644 --- a/google_apis/drive/drive_api_parser.cc +++ b/google_apis/drive/drive_api_parser.cc @@ -97,11 +97,12 @@ const char kIconUrl[] = "iconUrl"; const char kAppKind[] = "drive#app"; const char kName[] = "name"; const char kObjectType[] = "objectType"; +const char kProductId[] = "productId"; const char kSupportsCreate[] = "supportsCreate"; const char kSupportsImport[] = "supportsImport"; const char kInstalled[] = "installed"; const char kAuthorized[] = "authorized"; -const char kProductUrl[] = "productUrl"; +const char kRemovable[] = "removable"; const char kPrimaryMimeTypes[] = "primaryMimeTypes"; const char kSecondaryMimeTypes[] = "secondaryMimeTypes"; const char kPrimaryFileExtensions[] = "primaryFileExtensions"; @@ -302,7 +303,8 @@ AppResource::AppResource() : supports_create_(false), supports_import_(false), installed_(false), - authorized_(false) { + authorized_(false), + removable_(false) { } AppResource::~AppResource() {} @@ -313,13 +315,12 @@ void AppResource::RegisterJSONConverter( converter->RegisterStringField(kId, &AppResource::application_id_); converter->RegisterStringField(kName, &AppResource::name_); converter->RegisterStringField(kObjectType, &AppResource::object_type_); + converter->RegisterStringField(kProductId, &AppResource::product_id_); converter->RegisterBoolField(kSupportsCreate, &AppResource::supports_create_); converter->RegisterBoolField(kSupportsImport, &AppResource::supports_import_); converter->RegisterBoolField(kInstalled, &AppResource::installed_); converter->RegisterBoolField(kAuthorized, &AppResource::authorized_); - converter->RegisterCustomField<GURL>(kProductUrl, - &AppResource::product_url_, - GetGURLFromString); + converter->RegisterBoolField(kRemovable, &AppResource::removable_); converter->RegisterRepeatedString(kPrimaryMimeTypes, &AppResource::primary_mimetypes_); converter->RegisterRepeatedString(kSecondaryMimeTypes, diff --git a/google_apis/drive/drive_api_parser.h b/google_apis/drive/drive_api_parser.h index f43325d..478c9b7 100644 --- a/google_apis/drive/drive_api_parser.h +++ b/google_apis/drive/drive_api_parser.h @@ -168,6 +168,9 @@ class AppResource { // If empty, application name is used instead. const std::string& object_type() const { return object_type_; } + // Returns the product ID. + const std::string& product_id() const { return product_id_; } + // Returns whether this application supports creating new objects. bool supports_create() const { return supports_create_; } @@ -181,8 +184,8 @@ class AppResource { // user's Drive. bool is_authorized() const { return authorized_; } - // Returns the product URL, e.g. at Chrome Web Store. - const GURL& product_url() const { return product_url_; } + // Returns whether this application is removable by apps.delete API. + bool is_removable() const { return removable_; } // Returns the create URL, i.e., the URL for opening a new file by the app. const GURL& create_url() const { return create_url_; } @@ -229,6 +232,7 @@ class AppResource { void set_object_type(const std::string& object_type) { object_type_ = object_type; } + void set_product_id(const std::string& id) { product_id_ = id; } void set_supports_create(bool supports_create) { supports_create_ = supports_create; } @@ -237,9 +241,7 @@ class AppResource { } void set_installed(bool installed) { installed_ = installed; } void set_authorized(bool authorized) { authorized_ = authorized; } - void set_product_url(const GURL& product_url) { - product_url_ = product_url; - } + void set_removable(bool removable) { removable_ = removable; } void set_primary_mimetypes( ScopedVector<std::string> primary_mimetypes) { primary_mimetypes_ = primary_mimetypes.Pass(); @@ -274,11 +276,12 @@ class AppResource { std::string application_id_; std::string name_; std::string object_type_; + std::string product_id_; bool supports_create_; bool supports_import_; bool installed_; bool authorized_; - GURL product_url_; + bool removable_; GURL create_url_; ScopedVector<std::string> primary_mimetypes_; ScopedVector<std::string> secondary_mimetypes_; diff --git a/google_apis/drive/drive_api_parser_unittest.cc b/google_apis/drive/drive_api_parser_unittest.cc index 0c9f7a9..911ae6f 100644 --- a/google_apis/drive/drive_api_parser_unittest.cc +++ b/google_apis/drive/drive_api_parser_unittest.cc @@ -53,9 +53,8 @@ TEST(DriveAPIParserTest, AppListParser) { EXPECT_TRUE(app1.supports_import()); EXPECT_TRUE(app1.is_installed()); EXPECT_FALSE(app1.is_authorized()); - EXPECT_EQ("https://chrome.google.com/webstore/detail/" - "abcdefghabcdefghabcdefghabcdefgh", - app1.product_url().spec()); + EXPECT_TRUE(app1.is_removable()); + EXPECT_EQ("abcdefghabcdefghabcdefghabcdefgh", app1.product_id()); ASSERT_EQ(1U, app1.primary_mimetypes().size()); EXPECT_EQ("application/vnd.google-apps.drive-sdk.123456788192", @@ -93,9 +92,8 @@ TEST(DriveAPIParserTest, AppListParser) { EXPECT_FALSE(app2.supports_import()); EXPECT_TRUE(app2.is_installed()); EXPECT_FALSE(app2.is_authorized()); - EXPECT_EQ("https://chrome.google.com/webstore/detail/" - "hgfedcbahgfedcbahgfedcbahgfedcba", - app2.product_url().spec()); + EXPECT_FALSE(app2.is_removable()); + EXPECT_EQ("hgfedcbahgfedcbahgfedcbahgfedcba", app2.product_id()); ASSERT_EQ(3U, app2.primary_mimetypes().size()); EXPECT_EQ("image/jpeg", *app2.primary_mimetypes()[0]); diff --git a/google_apis/drive/drive_api_requests.cc b/google_apis/drive/drive_api_requests.cc index e9794ba..4fc56df 100644 --- a/google_apis/drive/drive_api_requests.cc +++ b/google_apis/drive/drive_api_requests.cc @@ -523,18 +523,20 @@ GURL ChangesListNextPageRequest::GetURLInternal() const { AppsListRequest::AppsListRequest( RequestSender* sender, const DriveApiUrlGenerator& url_generator, + bool use_internal_endpoint, const AppListCallback& callback) : DriveApiDataRequest( sender, base::Bind(&ParseJsonAndRun<AppList>, callback)), - url_generator_(url_generator) { + url_generator_(url_generator), + use_internal_endpoint_(use_internal_endpoint) { DCHECK(!callback.is_null()); } AppsListRequest::~AppsListRequest() {} GURL AppsListRequest::GetURLInternal() const { - return url_generator_.GetAppsListUrl(); + return url_generator_.GetAppsListUrl(use_internal_endpoint_); } //============================== AppsDeleteRequest =========================== diff --git a/google_apis/drive/drive_api_requests.h b/google_apis/drive/drive_api_requests.h index 866197e..c534e09 100644 --- a/google_apis/drive/drive_api_requests.h +++ b/google_apis/drive/drive_api_requests.h @@ -523,6 +523,7 @@ class AppsListRequest : public DriveApiDataRequest { public: AppsListRequest(RequestSender* sender, const DriveApiUrlGenerator& url_generator, + bool use_internal_endpoint, const AppListCallback& callback); virtual ~AppsListRequest(); @@ -532,6 +533,7 @@ class AppsListRequest : public DriveApiDataRequest { private: const DriveApiUrlGenerator url_generator_; + bool use_internal_endpoint_; DISALLOW_COPY_AND_ASSIGN(AppsListRequest); }; diff --git a/google_apis/drive/drive_api_requests_unittest.cc b/google_apis/drive/drive_api_requests_unittest.cc index cbbba29..b05af4b 100644 --- a/google_apis/drive/drive_api_requests_unittest.cc +++ b/google_apis/drive/drive_api_requests_unittest.cc @@ -585,6 +585,7 @@ TEST_F(DriveApiRequestsTest, AppsListRequest) { drive::AppsListRequest* request = new drive::AppsListRequest( request_sender_.get(), *url_generator_, + false, // use_internal_endpoint test_util::CreateQuitCallback( &run_loop, test_util::CreateCopyResultCallback(&error, &app_list))); diff --git a/google_apis/drive/drive_api_url_generator.cc b/google_apis/drive/drive_api_url_generator.cc index e8660cc..a68938c 100644 --- a/google_apis/drive/drive_api_url_generator.cc +++ b/google_apis/drive/drive_api_url_generator.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" +#include "google_apis/google_api_keys.h" #include "net/base/escape.h" #include "net/base/url_util.h" @@ -32,6 +33,7 @@ const char kDriveV2InitiateUploadExistingFileUrlPrefix[] = // apps.delete and file.authorize API is exposed through a special endpoint // v2internal that is accessible only by the official API key for Chrome. +const char kDriveV2InternalAppsUrl[] = "/drive/v2internal/apps"; const char kDriveV2AppsDeleteUrlFormat[] = "/drive/v2internal/apps/%s"; const char kDriveV2FilesAuthorizeUrlFormat[] = "/drive/v2internal/files/%s/authorize?appId=%s"; @@ -62,8 +64,9 @@ GURL DriveApiUrlGenerator::GetAboutGetUrl() const { return base_url_.Resolve(kDriveV2AboutUrl); } -GURL DriveApiUrlGenerator::GetAppsListUrl() const { - return base_url_.Resolve(kDriveV2AppsUrl); +GURL DriveApiUrlGenerator::GetAppsListUrl(bool use_internal_endpoint) const { + return base_url_.Resolve(use_internal_endpoint ? + kDriveV2InternalAppsUrl : kDriveV2AppsUrl); } GURL DriveApiUrlGenerator::GetAppsDeleteUrl(const std::string& app_id) const { diff --git a/google_apis/drive/drive_api_url_generator.h b/google_apis/drive/drive_api_url_generator.h index 512577d..d587db1 100644 --- a/google_apis/drive/drive_api_url_generator.h +++ b/google_apis/drive/drive_api_url_generator.h @@ -30,7 +30,9 @@ class DriveApiUrlGenerator { GURL GetAboutGetUrl() const; // Returns a URL to invoke "Apps: list" method. - GURL GetAppsListUrl() const; + // Set |use_internal_endpoint| to true if official Chrome's API key is used + // and retrieving more information (related to App uninstall) is necessary. + GURL GetAppsListUrl(bool use_internal_endpoint) const; // Returns a URL to uninstall an app with the give |app_id|. GURL GetAppsDeleteUrl(const std::string& app_id) const; diff --git a/google_apis/drive/drive_api_url_generator_unittest.cc b/google_apis/drive/drive_api_url_generator_unittest.cc index 00e7d8a..50a48a3 100644 --- a/google_apis/drive/drive_api_url_generator_unittest.cc +++ b/google_apis/drive/drive_api_url_generator_unittest.cc @@ -35,10 +35,13 @@ TEST_F(DriveApiUrlGeneratorTest, GetAboutGetUrl) { } TEST_F(DriveApiUrlGeneratorTest, GetAppsListUrl) { + const bool use_internal_url = true; + EXPECT_EQ("https://www.googleapis.com/drive/v2internal/apps", + url_generator_.GetAppsListUrl(use_internal_url).spec()); EXPECT_EQ("https://www.googleapis.com/drive/v2/apps", - url_generator_.GetAppsListUrl().spec()); + url_generator_.GetAppsListUrl(!use_internal_url).spec()); EXPECT_EQ("http://127.0.0.1:12345/drive/v2/apps", - test_url_generator_.GetAppsListUrl().spec()); + test_url_generator_.GetAppsListUrl(!use_internal_url).spec()); } TEST_F(DriveApiUrlGeneratorTest, GetAppsDeleteUrl) { |