summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorfukino <fukino@chromium.org>2015-11-25 22:02:13 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-26 06:03:27 +0000
commit2664bbdf7ea5c87ee7593f6278d3f7b627645567 (patch)
tree59747071da146fa4afb20fe0ed11c724b0216ce6 /google_apis
parent4ee22833b2193a698d512c63a43af0eeb05b7fba (diff)
downloadchromium_src-2664bbdf7ea5c87ee7593f6278d3f7b627645567.zip
chromium_src-2664bbdf7ea5c87ee7593f6278d3f7b627645567.tar.gz
chromium_src-2664bbdf7ea5c87ee7593f6278d3f7b627645567.tar.bz2
Files: Use new image server to download Drive thumbnails.
Files app and its companion apps should use new image server to get Drive thumbnails. The URL is like https://lh3.googleusercontent.com/d/<doc-id>[=options]. This CL adds a support for the new URL in DriveApiUrlGenerator, and updates its users accordingly. BUG=496969 TEST=run google_apis_unittests; confirm Drive thumbnails manually on Files, Gallery, and Video Player. Review URL: https://codereview.chromium.org/1474983002 Cr-Commit-Position: refs/heads/master@{#361829}
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/drive/drive_api_requests_unittest.cc2
-rw-r--r--google_apis/drive/drive_api_url_generator.cc25
-rw-r--r--google_apis/drive/drive_api_url_generator.h8
-rw-r--r--google_apis/drive/drive_api_url_generator_unittest.cc13
-rw-r--r--google_apis/drive/files_list_request_runner_unittest.cc3
5 files changed, 30 insertions, 21 deletions
diff --git a/google_apis/drive/drive_api_requests_unittest.cc b/google_apis/drive/drive_api_requests_unittest.cc
index 817fffa..1df9680 100644
--- a/google_apis/drive/drive_api_requests_unittest.cc
+++ b/google_apis/drive/drive_api_requests_unittest.cc
@@ -160,7 +160,7 @@ class DriveApiRequestsTest : public testing::Test {
GURL test_base_url = test_util::GetBaseUrlForTesting(test_server_.port());
url_generator_.reset(
- new DriveApiUrlGenerator(test_base_url, test_base_url));
+ new DriveApiUrlGenerator(test_base_url, test_base_url, test_base_url));
// Reset the server's expected behavior just in case.
ResetExpectedResponse();
diff --git a/google_apis/drive/drive_api_url_generator.cc b/google_apis/drive/drive_api_url_generator.cc
index 14da8a3..a097527 100644
--- a/google_apis/drive/drive_api_url_generator.cc
+++ b/google_apis/drive/drive_api_url_generator.cc
@@ -32,7 +32,8 @@ const char kDriveV2UploadExistingFileUrlPrefix[] = "upload/drive/v2/files/";
const char kDriveV2BatchUploadUrl[] = "upload/drive";
const char kDriveV2PermissionsUrlFormat[] = "drive/v2/files/%s/permissions";
const char kDriveV2DownloadUrlFormat[] = "host/%s";
-const char kDriveV2ThumbnailUrlFormat[] = "thumb/%s?width=%d&height=%d";
+const char kDriveV2ThumbnailUrlFormat[] = "d/%s=w%d-h%d";
+const char kDriveV2ThumbnailUrlWithCropFormat[] = "d/%s=w%d-h%d-c";
// apps.delete and file.authorize API is exposed through a special endpoint
// v2internal that is accessible only by the official API key for Chrome.
@@ -53,9 +54,11 @@ GURL AddMultipartUploadParam(const GURL& url) {
} // namespace
DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url,
- const GURL& base_download_url)
+ const GURL& base_download_url,
+ const GURL& base_thumbnail_url)
: base_url_(base_url),
- base_download_url_(base_download_url) {
+ base_download_url_(base_download_url),
+ base_thumbnail_url_(base_thumbnail_url) {
// Do nothing.
}
@@ -73,6 +76,9 @@ const char DriveApiUrlGenerator::kBaseDownloadUrlForProduction[] =
"https://www.googledrive.com";
#endif
+const char DriveApiUrlGenerator::kBaseThumbnailUrlForProduction[] =
+ "https://lh3.googleusercontent.com";
+
GURL DriveApiUrlGenerator::GetAboutGetUrl() const {
return base_url_.Resolve(kDriveV2AboutUrl);
}
@@ -298,15 +304,10 @@ GURL DriveApiUrlGenerator::GetThumbnailUrl(const std::string& resource_id,
int width,
int height,
bool crop) const {
- GURL url = base_download_url_.Resolve(
- base::StringPrintf(kDriveV2ThumbnailUrlFormat,
- net::EscapePath(resource_id).c_str(), width, height));
-
- // crop is "false" by default.
- if (crop)
- url = net::AppendOrReplaceQueryParameter(url, "crop", "true");
-
- return url;
+ return base_thumbnail_url_.Resolve(
+ base::StringPrintf(
+ crop ? kDriveV2ThumbnailUrlWithCropFormat : kDriveV2ThumbnailUrlFormat,
+ net::EscapePath(resource_id).c_str(), width, height));
}
GURL DriveApiUrlGenerator::GetBatchUploadUrl() const {
diff --git a/google_apis/drive/drive_api_url_generator.h b/google_apis/drive/drive_api_url_generator.h
index 7e498fb..67f402f 100644
--- a/google_apis/drive/drive_api_url_generator.h
+++ b/google_apis/drive/drive_api_url_generator.h
@@ -17,7 +17,9 @@ class DriveApiUrlGenerator {
public:
// |base_url| is the path to the target drive api server.
// Note that this is an injecting point for a testing server.
- DriveApiUrlGenerator(const GURL& base_url, const GURL& base_download_url);
+ DriveApiUrlGenerator(const GURL& base_url,
+ const GURL& base_download_url,
+ const GURL& base_thumbnail_url);
~DriveApiUrlGenerator();
// The base URL for communicating with the production drive api server.
@@ -26,6 +28,9 @@ class DriveApiUrlGenerator {
// The base URL for the file download server for production.
static const char kBaseDownloadUrlForProduction[];
+ // The base URL for the thumbnail download server for production.
+ static const char kBaseThumbnailUrlForProduction[];
+
// Returns a URL to invoke "About: get" method.
GURL GetAboutGetUrl() const;
@@ -121,6 +126,7 @@ class DriveApiUrlGenerator {
private:
const GURL base_url_;
const GURL base_download_url_;
+ const GURL base_thumbnail_url_;
// This class is copyable hence no DISALLOW_COPY_AND_ASSIGN here.
};
diff --git a/google_apis/drive/drive_api_url_generator_unittest.cc b/google_apis/drive/drive_api_url_generator_unittest.cc
index 28e79c4..1240b24 100644
--- a/google_apis/drive/drive_api_url_generator_unittest.cc
+++ b/google_apis/drive/drive_api_url_generator_unittest.cc
@@ -15,13 +15,15 @@ namespace {
// OS, so use testing base urls.
const char kBaseUrlForTesting[] = "https://www.example.com";
const char kBaseDownloadUrlForTesting[] = "https://download.example.com/p/";
+const char kBaseThumbnailUrlForTesting[] = "https://thumbnail.example.com";
} // namespace
class DriveApiUrlGeneratorTest : public testing::Test {
public:
DriveApiUrlGeneratorTest()
: url_generator_(GURL(kBaseUrlForTesting),
- GURL(kBaseDownloadUrlForTesting)) {}
+ GURL(kBaseDownloadUrlForTesting),
+ GURL(kBaseThumbnailUrlForTesting)) {}
protected:
DriveApiUrlGenerator url_generator_;
@@ -369,13 +371,12 @@ TEST_F(DriveApiUrlGeneratorTest, GeneratePermissionsInsertUrl) {
TEST_F(DriveApiUrlGeneratorTest, GenerateThumbnailUrl) {
EXPECT_EQ(
- "https://download.example.com/p/thumb/0ADK06pfg?width=500&height=500",
- url_generator_.GetThumbnailUrl("0ADK06pfg", 500, 500, false).spec());
+ "https://thumbnail.example.com/d/0ADK06pfg=w500-h480",
+ url_generator_.GetThumbnailUrl("0ADK06pfg", 500, 480, false).spec());
EXPECT_EQ(
- "https://download.example.com/p/thumb/"
- "0ADK06pfg?width=360&height=360&crop=true",
- url_generator_.GetThumbnailUrl("0ADK06pfg", 360, 360, true).spec());
+ "https://thumbnail.example.com/d/0ADK06pfg=w360-h380-c",
+ url_generator_.GetThumbnailUrl("0ADK06pfg", 360, 380, true).spec());
}
TEST_F(DriveApiUrlGeneratorTest, BatchUploadUrl) {
diff --git a/google_apis/drive/files_list_request_runner_unittest.cc b/google_apis/drive/files_list_request_runner_unittest.cc
index d8d8e78..51b72c6 100644
--- a/google_apis/drive/files_list_request_runner_unittest.cc
+++ b/google_apis/drive/files_list_request_runner_unittest.cc
@@ -78,7 +78,8 @@ class FilesListRequestRunnerTest : public testing::Test {
runner_.reset(new FilesListRequestRunner(
request_sender_.get(),
google_apis::DriveApiUrlGenerator(test_server_.base_url(),
- test_server_.GetURL("/download/"))));
+ test_server_.GetURL("/download/"),
+ test_server_.GetURL("/thumbnail/"))));
}
void TearDown() override {