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

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

Issue 2380053003: Add Finch flag for the WebAPK server URL (Closed)
Patch Set: Merge branch 'master' into webapk_server_url 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 | no next file » | 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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/metrics/field_trial.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "base/task_runner_util.h" 20 #include "base/task_runner_util.h"
20 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
21 #include "chrome/browser/android/shortcut_helper.h" 22 #include "chrome/browser/android/shortcut_helper.h"
22 #include "chrome/browser/android/webapk/webapk.pb.h" 23 #include "chrome/browser/android/webapk/webapk.pb.h"
23 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" 24 #include "chrome/browser/android/webapk/webapk_icon_hasher.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "components/version_info/version_info.h" 27 #include "components/version_info/version_info.h"
27 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
28 #include "content/public/common/manifest_util.h" 29 #include "content/public/common/manifest_util.h"
29 #include "jni/WebApkInstaller_jni.h" 30 #include "jni/WebApkInstaller_jni.h"
30 #include "net/http/http_status_code.h" 31 #include "net/http/http_status_code.h"
31 #include "net/url_request/url_fetcher.h" 32 #include "net/url_request/url_fetcher.h"
32 #include "ui/gfx/codec/png_codec.h" 33 #include "ui/gfx/codec/png_codec.h"
33 #include "url/gurl.h" 34 #include "url/gurl.h"
34 35
35 namespace { 36 namespace {
36 37
38 // Flag for setting the WebAPK server URL.
39 const char kWebApkServerFinchFlag[] = "WebApkServerUrl";
40
37 // The default WebAPK server URL. 41 // The default WebAPK server URL.
38 const char kDefaultWebApkServerUrl[] = 42 const char kDefaultWebApkServerUrl[] =
39 "https://webapk.googleapis.com/v1alpha/webApks/"; 43 "https://webapk.googleapis.com/v1alpha/webApks/";
40 44
41 // The response format type expected from the WebAPK server. 45 // The response format type expected from the WebAPK server.
42 const char kDefaultWebApkServerUrlResponseType[] = "?alt=proto"; 46 const char kDefaultWebApkServerUrlResponseType[] = "?alt=proto";
43 47
44 // The MIME type of the POST data sent to the server. 48 // The MIME type of the POST data sent to the server.
45 const char kProtoMimeType[] = "application/x-protobuf"; 49 const char kProtoMimeType[] = "application/x-protobuf";
46 50
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return webapk; 122 return webapk;
119 } 123 }
120 124
121 // Returns task runner for running background tasks. 125 // Returns task runner for running background tasks.
122 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { 126 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() {
123 return content::BrowserThread::GetBlockingPool() 127 return content::BrowserThread::GetBlockingPool()
124 ->GetTaskRunnerWithShutdownBehavior( 128 ->GetTaskRunnerWithShutdownBehavior(
125 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 129 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
126 } 130 }
127 131
132 GURL GetBaseServerUrl() {
133 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
134 if (command_line->HasSwitch(switches::kWebApkServerUrl))
135 return GURL(command_line->GetSwitchValueASCII(switches::kWebApkServerUrl));
136 std::string server_url =
137 base::FieldTrialList::FindFullName(kWebApkServerFinchFlag);
138 if (!server_url.empty())
139 return GURL(server_url);
140 return GURL(kDefaultWebApkServerUrl);
141 }
142
128 GURL GetServerUrlForUpdate(const GURL& server_url, 143 GURL GetServerUrlForUpdate(const GURL& server_url,
129 const std::string& webapk_package) { 144 const std::string& webapk_package) {
130 // crbug.com/636552. Simplify the server URL. 145 // crbug.com/636552. Simplify the server URL.
131 return GURL(server_url.spec() + webapk_package + "/" + 146 return GURL(server_url.spec() + webapk_package + "/" +
132 kDefaultWebApkServerUrlResponseType); 147 kDefaultWebApkServerUrlResponseType);
133 } 148 }
134 149
135 // Creates a directory depending on the type of the task, and set permissions. 150 // 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, 151 // It also creates any parent directory along the path if doesn't exist,
137 // and sets permissions as well. 152 // and sets permissions as well.
(...skipping 25 matching lines...) Expand all
163 178
164 return output_dir; 179 return output_dir;
165 } 180 }
166 181
167 } // anonymous namespace 182 } // anonymous namespace
168 183
169 WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info, 184 WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info,
170 const SkBitmap& shortcut_icon) 185 const SkBitmap& shortcut_icon)
171 : shortcut_info_(shortcut_info), 186 : shortcut_info_(shortcut_info),
172 shortcut_icon_(shortcut_icon), 187 shortcut_icon_(shortcut_icon),
188 server_url_(GetBaseServerUrl()),
173 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), 189 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs),
174 download_timeout_ms_(kDownloadTimeoutMs), 190 download_timeout_ms_(kDownloadTimeoutMs),
175 task_type_(UNDEFINED), 191 task_type_(UNDEFINED),
176 weak_ptr_factory_(this) { 192 weak_ptr_factory_(this) {
177 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
178 server_url_ =
179 GURL(command_line->HasSwitch(switches::kWebApkServerUrl)
180 ? command_line->GetSwitchValueASCII(switches::kWebApkServerUrl)
181 : kDefaultWebApkServerUrl);
182 CreateJavaRef(); 193 CreateJavaRef();
183 } 194 }
184 195
185 void WebApkInstaller::CreateJavaRef() { 196 void WebApkInstaller::CreateJavaRef() {
186 JNIEnv* env = base::android::AttachCurrentThread(); 197 JNIEnv* env = base::android::AttachCurrentThread();
187 java_ref_.Reset(Java_WebApkInstaller_create( 198 java_ref_.Reset(Java_WebApkInstaller_create(
188 env, reinterpret_cast<intptr_t>(this))); 199 env, reinterpret_cast<intptr_t>(this)));
189 } 200 }
190 201
191 WebApkInstaller::~WebApkInstaller() { 202 WebApkInstaller::~WebApkInstaller() {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 std::string webapk_package = webapk_package_; 482 std::string webapk_package = webapk_package_;
472 delete this; 483 delete this;
473 callback.Run(true, webapk_package); 484 callback.Run(true, webapk_package);
474 } 485 }
475 486
476 void WebApkInstaller::OnFailure() { 487 void WebApkInstaller::OnFailure() {
477 FinishCallback callback = finish_callback_; 488 FinishCallback callback = finish_callback_;
478 delete this; 489 delete this;
479 callback.Run(false, ""); 490 callback.Run(false, "");
480 } 491 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698