OLD | NEW |
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/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
| 19 #include "base/task_scheduler/post_task.h" |
19 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
20 #include "base/timer/elapsed_timer.h" | 21 #include "base/timer/elapsed_timer.h" |
21 #include "chrome/browser/android/shortcut_helper.h" | 22 #include "chrome/browser/android/shortcut_helper.h" |
22 #include "chrome/browser/android/webapk/chrome_webapk_host.h" | 23 #include "chrome/browser/android/webapk/chrome_webapk_host.h" |
23 #include "chrome/browser/android/webapk/webapk.pb.h" | 24 #include "chrome/browser/android/webapk/webapk.pb.h" |
24 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" | 25 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" |
25 #include "chrome/browser/android/webapk/webapk_install_service.h" | 26 #include "chrome/browser/android/webapk/webapk_install_service.h" |
26 #include "chrome/browser/android/webapk/webapk_metrics.h" | 27 #include "chrome/browser/android/webapk/webapk_metrics.h" |
27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 107 } |
107 | 108 |
108 // Populates webapk::WebApk and returns it. | 109 // Populates webapk::WebApk and returns it. |
109 // Must be called on a worker thread because it encodes an SkBitmap. | 110 // Must be called on a worker thread because it encodes an SkBitmap. |
110 std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground( | 111 std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground( |
111 const ShortcutInfo& shortcut_info, | 112 const ShortcutInfo& shortcut_info, |
112 const SkBitmap& primary_icon, | 113 const SkBitmap& primary_icon, |
113 const SkBitmap& badge_icon, | 114 const SkBitmap& badge_icon, |
114 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 115 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
115 bool is_manifest_stale) { | 116 bool is_manifest_stale) { |
116 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | |
117 | |
118 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); | 117 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); |
119 webapk->set_manifest_url(shortcut_info.manifest_url.spec()); | 118 webapk->set_manifest_url(shortcut_info.manifest_url.spec()); |
120 webapk->set_requester_application_package( | 119 webapk->set_requester_application_package( |
121 base::android::BuildInfo::GetInstance()->package_name()); | 120 base::android::BuildInfo::GetInstance()->package_name()); |
122 webapk->set_requester_application_version(version_info::GetVersionNumber()); | 121 webapk->set_requester_application_version(version_info::GetVersionNumber()); |
123 webapk->set_android_abi(getCurrentAbi()); | 122 webapk->set_android_abi(getCurrentAbi()); |
124 webapk->set_stale_manifest(is_manifest_stale); | 123 webapk->set_stale_manifest(is_manifest_stale); |
125 | 124 |
126 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); | 125 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); |
127 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); | 126 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 172 |
174 // Calls the callback when the |webapk| request is created. | 173 // Calls the callback when the |webapk| request is created. |
175 void OnWebApkProtoBuilt( | 174 void OnWebApkProtoBuilt( |
176 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, | 175 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
177 std::unique_ptr<webapk::WebApk> webapk) { | 176 std::unique_ptr<webapk::WebApk> webapk) { |
178 callback.Run(std::move(webapk)); | 177 callback.Run(std::move(webapk)); |
179 } | 178 } |
180 | 179 |
181 // Returns task runner for running background tasks. | 180 // Returns task runner for running background tasks. |
182 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { | 181 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() { |
183 return content::BrowserThread::GetBlockingPool() | 182 return base::CreateTaskRunnerWithTraits( |
184 ->GetTaskRunnerWithShutdownBehavior( | 183 base::TaskTraits() |
185 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 184 .MayBlock() |
| 185 .WithPriority(base::TaskPriority::BACKGROUND) |
| 186 .WithShutdownBehavior(base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN)); |
186 } | 187 } |
187 | 188 |
188 } // anonymous namespace | 189 } // anonymous namespace |
189 | 190 |
190 WebApkInstaller::~WebApkInstaller() { | 191 WebApkInstaller::~WebApkInstaller() { |
191 JNIEnv* env = base::android::AttachCurrentThread(); | 192 JNIEnv* env = base::android::AttachCurrentThread(); |
192 Java_WebApkInstaller_destroy(env, java_ref_); | 193 Java_WebApkInstaller_destroy(env, java_ref_); |
193 java_ref_.Reset(); | 194 java_ref_.Reset(); |
194 } | 195 } |
195 | 196 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); | 500 net::URLFetcher::Create(server_url, net::URLFetcher::POST, this); |
500 url_fetcher_->SetRequestContext(request_context_getter_); | 501 url_fetcher_->SetRequestContext(request_context_getter_); |
501 std::string serialized_request; | 502 std::string serialized_request; |
502 request_proto->SerializeToString(&serialized_request); | 503 request_proto->SerializeToString(&serialized_request); |
503 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); | 504 url_fetcher_->SetUploadData(kProtoMimeType, serialized_request); |
504 url_fetcher_->SetLoadFlags( | 505 url_fetcher_->SetLoadFlags( |
505 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES | | 506 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES | |
506 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA); | 507 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA); |
507 url_fetcher_->Start(); | 508 url_fetcher_->Start(); |
508 } | 509 } |
OLD | NEW |