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

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

Issue 2441203002: Add field trial for the WebAPK server URL (Closed)
Patch Set: ABCD Created 4 years, 1 month 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
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"
13 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
15 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
16 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
19 #include "base/task_runner_util.h" 18 #include "base/task_runner_util.h"
20 #include "base/threading/sequenced_worker_pool.h" 19 #include "base/threading/sequenced_worker_pool.h"
20 #include "chrome/browser/android/chrome_feature_list.h"
21 #include "chrome/browser/android/shortcut_helper.h" 21 #include "chrome/browser/android/shortcut_helper.h"
22 #include "chrome/browser/android/webapk/webapk.pb.h" 22 #include "chrome/browser/android/webapk/webapk.pb.h"
23 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" 23 #include "chrome/browser/android/webapk/webapk_icon_hasher.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/common/chrome_switches.h" 25 #include "components/variations/variations_associated_data.h"
26 #include "components/version_info/version_info.h" 26 #include "components/version_info/version_info.h"
27 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/common/manifest_util.h" 28 #include "content/public/common/manifest_util.h"
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 kDefaultServerUrl[] =
39 "https://webapk.googleapis.com/v1alpha/webApks/?alt=proto"; 39 "https://webapk.googleapis.com/v1alpha/webApks/?alt=proto";
40 40
41 // Flag for setting the WebAPK server URL.
42 const char kServerUrlVariationsParamKey[] = "ServerUrl";
43
41 // The MIME type of the POST data sent to the server. 44 // The MIME type of the POST data sent to the server.
42 const char kProtoMimeType[] = "application/x-protobuf"; 45 const char kProtoMimeType[] = "application/x-protobuf";
43 46
44 // The default number of milliseconds to wait for the WebAPK download URL from 47 // The default number of milliseconds to wait for the WebAPK download URL from
45 // the WebAPK server. 48 // the WebAPK server.
46 const int kWebApkDownloadUrlTimeoutMs = 60000; 49 const int kWebApkDownloadUrlTimeoutMs = 60000;
47 50
48 // The default number of milliseconds to wait for the WebAPK download to 51 // The default number of milliseconds to wait for the WebAPK download to
49 // complete. 52 // complete.
50 const int kDownloadTimeoutMs = 60000; 53 const int kDownloadTimeoutMs = 60000;
51 54
52 const int kWorldReadableFilePermission = base::FILE_PERMISSION_READ_BY_USER | 55 const int kWorldReadableFilePermission = base::FILE_PERMISSION_READ_BY_USER |
53 base::FILE_PERMISSION_READ_BY_GROUP | 56 base::FILE_PERMISSION_READ_BY_GROUP |
54 base::FILE_PERMISSION_READ_BY_OTHERS; 57 base::FILE_PERMISSION_READ_BY_OTHERS;
55 58
59 // Returns the WebAPK server URL based on the command line flags and the
60 // currently active field trials.
61 GURL GetServerUrl() {
62 GURL server_url(variations::GetVariationParamValueByFeature(
63 chrome::android::kWebApks, kServerUrlVariationsParamKey));
64 return server_url.is_valid() ? server_url : GURL(kDefaultServerUrl);
65 }
66
56 // Returns the scope from |info| if it is specified. Otherwise, returns the 67 // Returns the scope from |info| if it is specified. Otherwise, returns the
57 // default scope. 68 // default scope.
58 GURL GetScope(const ShortcutInfo& info) { 69 GURL GetScope(const ShortcutInfo& info) {
59 return (info.scope.is_valid()) 70 return (info.scope.is_valid())
60 ? info.scope 71 ? info.scope
61 : ShortcutHelper::GetScopeFromURL(info.url); 72 : ShortcutHelper::GetScopeFromURL(info.url);
62 } 73 }
63 74
64 // Converts a color from the format specified in content::Manifest to a CSS 75 // Converts a color from the format specified in content::Manifest to a CSS
65 // string. 76 // string.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 164
154 return output_dir; 165 return output_dir;
155 } 166 }
156 167
157 } // anonymous namespace 168 } // anonymous namespace
158 169
159 WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info, 170 WebApkInstaller::WebApkInstaller(const ShortcutInfo& shortcut_info,
160 const SkBitmap& shortcut_icon) 171 const SkBitmap& shortcut_icon)
161 : shortcut_info_(shortcut_info), 172 : shortcut_info_(shortcut_info),
162 shortcut_icon_(shortcut_icon), 173 shortcut_icon_(shortcut_icon),
174 server_url_(GetServerUrl()),
163 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), 175 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs),
164 download_timeout_ms_(kDownloadTimeoutMs), 176 download_timeout_ms_(kDownloadTimeoutMs),
165 task_type_(UNDEFINED), 177 task_type_(UNDEFINED),
166 weak_ptr_factory_(this) { 178 weak_ptr_factory_(this) {
167 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
168 server_url_ =
169 GURL(command_line->HasSwitch(switches::kWebApkServerUrl)
170 ? command_line->GetSwitchValueASCII(switches::kWebApkServerUrl)
171 : kDefaultWebApkServerUrl);
172 CreateJavaRef(); 179 CreateJavaRef();
173 } 180 }
174 181
175 void WebApkInstaller::CreateJavaRef() { 182 void WebApkInstaller::CreateJavaRef() {
176 JNIEnv* env = base::android::AttachCurrentThread(); 183 JNIEnv* env = base::android::AttachCurrentThread();
177 java_ref_.Reset(Java_WebApkInstaller_create( 184 java_ref_.Reset(Java_WebApkInstaller_create(
178 env, reinterpret_cast<intptr_t>(this))); 185 env, reinterpret_cast<intptr_t>(this)));
179 } 186 }
180 187
181 WebApkInstaller::~WebApkInstaller() { 188 WebApkInstaller::~WebApkInstaller() {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 481
475 void WebApkInstaller::OnSuccess() { 482 void WebApkInstaller::OnSuccess() {
476 finish_callback_.Run(true, webapk_package_); 483 finish_callback_.Run(true, webapk_package_);
477 delete this; 484 delete this;
478 } 485 }
479 486
480 void WebApkInstaller::OnFailure() { 487 void WebApkInstaller::OnFailure() {
481 finish_callback_.Run(false, webapk_package_); 488 finish_callback_.Run(false, webapk_package_);
482 delete this; 489 delete this;
483 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698