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

Side by Side Diff: chrome/browser/android/webapk/webapk_installer.cc

Issue 2408263002: Make install and update WebAPK URLs the same (Closed)
Patch Set: Merge branch 'master' into webapk_installer_update Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/android/webapk/webapk_installer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/webapk/webapk_installer.h" 5 #include "chrome/browser/android/webapk/webapk_installer.h"
6 6
7 #include "base/android/build_info.h" 7 #include "base/android/build_info.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/path_utils.h" 10 #include "base/android/path_utils.h"
(...skipping 18 matching lines...) Expand all
29 #include "jni/WebApkInstaller_jni.h" 29 #include "jni/WebApkInstaller_jni.h"
30 #include "net/http/http_status_code.h" 30 #include "net/http/http_status_code.h"
31 #include "net/url_request/url_fetcher.h" 31 #include "net/url_request/url_fetcher.h"
32 #include "ui/gfx/codec/png_codec.h" 32 #include "ui/gfx/codec/png_codec.h"
33 #include "url/gurl.h" 33 #include "url/gurl.h"
34 34
35 namespace { 35 namespace {
36 36
37 // The default WebAPK server URL. 37 // The default WebAPK server URL.
38 const char kDefaultWebApkServerUrl[] = 38 const char kDefaultWebApkServerUrl[] =
39 "https://webapk.googleapis.com/v1alpha/webApks/"; 39 "https://webapk.googleapis.com/v1alpha/webApks/?alt=proto";
40
41 // The response format type expected from the WebAPK server.
42 const char kDefaultWebApkServerUrlResponseType[] = "?alt=proto";
43 40
44 // The MIME type of the POST data sent to the server. 41 // The MIME type of the POST data sent to the server.
45 const char kProtoMimeType[] = "application/x-protobuf"; 42 const char kProtoMimeType[] = "application/x-protobuf";
46 43
47 // The default number of milliseconds to wait for the WebAPK download URL from 44 // The default number of milliseconds to wait for the WebAPK download URL from
48 // the WebAPK server. 45 // the WebAPK server.
49 const int kWebApkDownloadUrlTimeoutMs = 60000; 46 const int kWebApkDownloadUrlTimeoutMs = 60000;
50 47
51 // The default number of milliseconds to wait for the WebAPK download to 48 // The default number of milliseconds to wait for the WebAPK download to
52 // complete. 49 // complete.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return webapk; 115 return webapk;
119 } 116 }
120 117
121 // Returns task runner for running background tasks. 118 // Returns task runner for running background tasks.
122 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { 119 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() {
123 return content::BrowserThread::GetBlockingPool() 120 return content::BrowserThread::GetBlockingPool()
124 ->GetTaskRunnerWithShutdownBehavior( 121 ->GetTaskRunnerWithShutdownBehavior(
125 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 122 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
126 } 123 }
127 124
128 GURL GetServerUrlForUpdate(const GURL& server_url,
129 const std::string& webapk_package) {
130 // crbug.com/636552. Simplify the server URL.
131 return GURL(server_url.spec() + webapk_package + "/" +
132 kDefaultWebApkServerUrlResponseType);
133 }
134
135 // Creates a directory depending on the type of the task, and set permissions. 125 // Creates a directory depending on the type of the task, and set permissions.
136 // It also creates any parent directory along the path if doesn't exist, 126 // It also creates any parent directory along the path if doesn't exist,
137 // and sets permissions as well. 127 // and sets permissions as well.
138 // The previously downloaded APKs are deleted in order to clean up unused cached 128 // The previously downloaded APKs are deleted in order to clean up unused cached
139 // data. 129 // data.
140 base::FilePath CreateSubDirAndSetPermissionsInBackground( 130 base::FilePath CreateSubDirAndSetPermissionsInBackground(
141 const base::StringPiece& output_dir_name, 131 const base::StringPiece& output_dir_name,
142 const std::string& package_name) { 132 const std::string& package_name) {
143 base::FilePath output_root_dir; 133 base::FilePath output_root_dir;
144 base::android::GetCacheDirectory(&output_root_dir); 134 base::android::GetCacheDirectory(&output_root_dir);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 base::PostTaskAndReplyWithResult( 336 base::PostTaskAndReplyWithResult(
347 GetBackgroundTaskRunner().get(), FROM_HERE, 337 GetBackgroundTaskRunner().get(), FROM_HERE,
348 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, 338 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_,
349 shortcut_icon_, shortcut_icon_murmur2_hash_), 339 shortcut_icon_, shortcut_icon_murmur2_hash_),
350 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, 340 base::Bind(&WebApkInstaller::SendCreateWebApkRequest,
351 weak_ptr_factory_.GetWeakPtr())); 341 weak_ptr_factory_.GetWeakPtr()));
352 } 342 }
353 343
354 void WebApkInstaller::SendCreateWebApkRequest( 344 void WebApkInstaller::SendCreateWebApkRequest(
355 std::unique_ptr<webapk::WebApk> webapk) { 345 std::unique_ptr<webapk::WebApk> webapk) {
356 GURL server_url(server_url_.spec() + kDefaultWebApkServerUrlResponseType); 346 SendRequest(std::move(webapk), net::URLFetcher::POST, server_url_);
357 SendRequest(std::move(webapk), net::URLFetcher::POST, server_url);
358 } 347 }
359 348
360 void WebApkInstaller::SendUpdateWebApkRequest( 349 void WebApkInstaller::SendUpdateWebApkRequest(
361 std::unique_ptr<webapk::WebApk> webapk) { 350 std::unique_ptr<webapk::WebApk> webapk) {
362 webapk->set_package_name(webapk_package_); 351 webapk->set_package_name(webapk_package_);
363 webapk->set_version(std::to_string(webapk_version_)); 352 webapk->set_version(std::to_string(webapk_version_));
364 353
365 SendRequest(std::move(webapk), net::URLFetcher::PUT, 354 SendRequest(std::move(webapk), net::URLFetcher::PUT, server_url_);
366 GetServerUrlForUpdate(server_url_, webapk_package_));
367 } 355 }
368 356
369 void WebApkInstaller::SendRequest(std::unique_ptr<webapk::WebApk> request_proto, 357 void WebApkInstaller::SendRequest(std::unique_ptr<webapk::WebApk> request_proto,
370 net::URLFetcher::RequestType request_type, 358 net::URLFetcher::RequestType request_type,
371 const GURL& server_url) { 359 const GURL& server_url) {
372 timer_.Start( 360 timer_.Start(
373 FROM_HERE, 361 FROM_HERE,
374 base::TimeDelta::FromMilliseconds(webapk_download_url_timeout_ms_), 362 base::TimeDelta::FromMilliseconds(webapk_download_url_timeout_ms_),
375 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr())); 363 base::Bind(&WebApkInstaller::OnTimeout, weak_ptr_factory_.GetWeakPtr()));
376 364
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 std::string webapk_package = webapk_package_; 477 std::string webapk_package = webapk_package_;
490 delete this; 478 delete this;
491 callback.Run(true, webapk_package); 479 callback.Run(true, webapk_package);
492 } 480 }
493 481
494 void WebApkInstaller::OnFailure() { 482 void WebApkInstaller::OnFailure() {
495 FinishCallback callback = finish_callback_; 483 FinishCallback callback = finish_callback_;
496 delete this; 484 delete this;
497 callback.Run(false, ""); 485 callback.Run(false, "");
498 } 486 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/webapk/webapk_installer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698