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

Side by Side Diff: chrome/browser/chromeos/app_mode/kiosk_app_data.cc

Issue 2883273002: Remove usage of SequencedWorkerPool::GetNamedSequenceToken from kiosk_app_data.cc. (Closed)
Patch Set: Created 3 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chromeos/app_mode/kiosk_app_data.h" 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted_memory.h" 13 #include "base/memory/ref_counted_memory.h"
14 #include "base/task_scheduler/post_task.h" 14 #include "base/task_scheduler/post_task.h"
15 #include "base/threading/sequenced_worker_pool.h"
16 #include "base/values.h" 15 #include "base/values.h"
17 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/chromeos/app_mode/kiosk_app_data_delegate.h" 17 #include "chrome/browser/chromeos/app_mode/kiosk_app_data_delegate.h"
19 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 18 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
20 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/extension_util.h" 20 #include "chrome/browser/extensions/extension_util.h"
22 #include "chrome/browser/extensions/webstore_data_fetcher.h" 21 #include "chrome/browser/extensions/webstore_data_fetcher.h"
23 #include "chrome/browser/extensions/webstore_install_helper.h" 22 #include "chrome/browser/extensions/webstore_install_helper.h"
24 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
25 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 //////////////////////////////////////////////////////////////////////////////// 70 ////////////////////////////////////////////////////////////////////////////////
72 // KioskAppData::CrxLoader 71 // KioskAppData::CrxLoader
73 // Loads meta data from crx file. 72 // Loads meta data from crx file.
74 73
75 class KioskAppData::CrxLoader : public extensions::SandboxedUnpackerClient { 74 class KioskAppData::CrxLoader : public extensions::SandboxedUnpackerClient {
76 public: 75 public:
77 CrxLoader(const base::WeakPtr<KioskAppData>& client, 76 CrxLoader(const base::WeakPtr<KioskAppData>& client,
78 const base::FilePath& crx_file) 77 const base::FilePath& crx_file)
79 : client_(client), 78 : client_(client),
80 crx_file_(crx_file), 79 crx_file_(crx_file),
81 success_(false) { 80 success_(false),
82 } 81 task_runner_(base::CreateSequencedTaskRunnerWithTraits(
82 {base::MayBlock(), base::TaskPriority::BACKGROUND,
83 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})) {}
83 84
84 void Start() { 85 void Start() {
85 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
86 base::SequencedWorkerPool::SequenceToken token =
87 pool->GetNamedSequenceToken("KioskAppData.CrxLoaderWorker");
fdoray 2017/05/16 17:58:56 Before my CL, the named sequence token provided mu
xiyuan 2017/05/16 19:41:45 I would like to keep the existing behavior. Crx un
fdoray 2017/05/19 19:06:52 The TaskScheduler is already limiting the rate at
88 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior(
89 token,
90 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
91 task_runner_->PostTask(FROM_HERE, 86 task_runner_->PostTask(FROM_HERE,
92 base::Bind(&CrxLoader::StartOnBlockingPool, this)); 87 base::BindOnce(&CrxLoader::StartInThreadPool, this));
93 } 88 }
94 89
95 bool success() const { return success_; } 90 bool success() const { return success_; }
96 const base::FilePath& crx_file() const { return crx_file_; } 91 const base::FilePath& crx_file() const { return crx_file_; }
97 const std::string& name() const { return name_; } 92 const std::string& name() const { return name_; }
98 const SkBitmap& icon() const { return icon_; } 93 const SkBitmap& icon() const { return icon_; }
99 const std::string& required_platform_version() const { 94 const std::string& required_platform_version() const {
100 return required_platform_version_; 95 return required_platform_version_;
101 } 96 }
102 97
(...skipping 12 matching lines...) Expand all
115 extensions::KioskModeInfo::Get(extension); 110 extensions::KioskModeInfo::Get(extension);
116 if (info == nullptr) { 111 if (info == nullptr) {
117 LOG(ERROR) << extension->id() << " is not a valid kiosk app."; 112 LOG(ERROR) << extension->id() << " is not a valid kiosk app.";
118 success_ = false; 113 success_ = false;
119 } else { 114 } else {
120 success_ = true; 115 success_ = true;
121 name_ = extension->name(); 116 name_ = extension->name();
122 icon_ = install_icon; 117 icon_ = install_icon;
123 required_platform_version_ = info->required_platform_version; 118 required_platform_version_ = info->required_platform_version;
124 } 119 }
125 NotifyFinishedOnBlockingPool(); 120 NotifyFinishedInThreadPool();
126 } 121 }
127 void OnUnpackFailure(const extensions::CrxInstallError& error) override { 122 void OnUnpackFailure(const extensions::CrxInstallError& error) override {
128 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 123 DCHECK(task_runner_->RunsTasksOnCurrentThread());
129 124
130 success_ = false; 125 success_ = false;
131 NotifyFinishedOnBlockingPool(); 126 NotifyFinishedInThreadPool();
132 } 127 }
133 128
134 void StartOnBlockingPool() { 129 void StartInThreadPool() {
135 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 130 DCHECK(task_runner_->RunsTasksOnCurrentThread());
136 131
137 if (!temp_dir_.CreateUniqueTempDir()) { 132 if (!temp_dir_.CreateUniqueTempDir()) {
138 success_ = false; 133 success_ = false;
139 NotifyFinishedOnBlockingPool(); 134 NotifyFinishedInThreadPool();
140 return; 135 return;
141 } 136 }
142 137
143 scoped_refptr<extensions::SandboxedUnpacker> unpacker( 138 scoped_refptr<extensions::SandboxedUnpacker> unpacker(
144 new extensions::SandboxedUnpacker( 139 new extensions::SandboxedUnpacker(
145 extensions::Manifest::INTERNAL, extensions::Extension::NO_FLAGS, 140 extensions::Manifest::INTERNAL, extensions::Extension::NO_FLAGS,
146 temp_dir_.GetPath(), task_runner_.get(), this)); 141 temp_dir_.GetPath(), task_runner_.get(), this));
147 unpacker->StartWithCrx(extensions::CRXFileInfo(crx_file_)); 142 unpacker->StartWithCrx(extensions::CRXFileInfo(crx_file_));
148 } 143 }
149 144
150 void NotifyFinishedOnBlockingPool() { 145 void NotifyFinishedInThreadPool() {
151 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 146 DCHECK(task_runner_->RunsTasksOnCurrentThread());
152 147
153 if (!temp_dir_.Delete()) { 148 if (!temp_dir_.Delete()) {
154 LOG(WARNING) << "Can not delete temp directory at " 149 LOG(WARNING) << "Can not delete temp directory at "
155 << temp_dir_.GetPath().value(); 150 << temp_dir_.GetPath().value();
156 } 151 }
157 152
158 BrowserThread::PostTask( 153 BrowserThread::PostTask(
159 BrowserThread::UI, FROM_HERE, 154 BrowserThread::UI, FROM_HERE,
160 base::Bind(&CrxLoader::NotifyFinishedOnUIThread, this)); 155 base::Bind(&CrxLoader::NotifyFinishedOnUIThread, this));
161 } 156 }
162 157
163 void NotifyFinishedOnUIThread() { 158 void NotifyFinishedOnUIThread() {
164 DCHECK_CURRENTLY_ON(BrowserThread::UI); 159 DCHECK_CURRENTLY_ON(BrowserThread::UI);
165 160
166 if (client_) 161 if (client_)
167 client_->OnCrxLoadFinished(this); 162 client_->OnCrxLoadFinished(this);
168 } 163 }
169 164
170 base::WeakPtr<KioskAppData> client_; 165 base::WeakPtr<KioskAppData> client_;
171 base::FilePath crx_file_; 166 base::FilePath crx_file_;
172 bool success_; 167 bool success_;
173 168
174 scoped_refptr<base::SequencedTaskRunner> task_runner_; 169 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
175 base::ScopedTempDir temp_dir_; 170 base::ScopedTempDir temp_dir_;
176 171
177 // Extracted meta data. 172 // Extracted meta data.
178 std::string name_; 173 std::string name_;
179 SkBitmap icon_; 174 SkBitmap icon_;
180 std::string required_platform_version_; 175 std::string required_platform_version_;
181 176
182 DISALLOW_COPY_AND_ASSIGN(CrxLoader); 177 DISALLOW_COPY_AND_ASSIGN(CrxLoader);
183 }; 178 };
184 179
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 533
539 SkBitmap icon = crx_loader->icon(); 534 SkBitmap icon = crx_loader->icon();
540 if (icon.empty()) 535 if (icon.empty())
541 icon = *extensions::util::GetDefaultAppIcon().bitmap(); 536 icon = *extensions::util::GetDefaultAppIcon().bitmap();
542 SetCache(crx_loader->name(), icon, crx_loader->required_platform_version()); 537 SetCache(crx_loader->name(), icon, crx_loader->required_platform_version());
543 538
544 SetStatus(STATUS_LOADED); 539 SetStatus(STATUS_LOADED);
545 } 540 }
546 541
547 } // namespace chromeos 542 } // namespace chromeos
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