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

Side by Side Diff: chrome/browser/extensions/crx_installer.cc

Issue 2825963003: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/extensions (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/crx_installer.h" 5 #include "chrome/browser/extensions/crx_installer.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 180
181 NotifyCrxInstallBegin(); 181 NotifyCrxInstallBegin();
182 182
183 source_file_ = source_file.path; 183 source_file_ = source_file.path;
184 184
185 scoped_refptr<SandboxedUnpacker> unpacker(new SandboxedUnpacker( 185 scoped_refptr<SandboxedUnpacker> unpacker(new SandboxedUnpacker(
186 install_source_, creation_flags_, install_directory_, 186 install_source_, creation_flags_, install_directory_,
187 installer_task_runner_.get(), this)); 187 installer_task_runner_.get(), this));
188 188
189 if (!installer_task_runner_->PostTask( 189 if (!installer_task_runner_->PostTask(
190 FROM_HERE, base::Bind(&SandboxedUnpacker::StartWithCrx, 190 FROM_HERE, base::BindOnce(&SandboxedUnpacker::StartWithCrx, unpacker,
191 unpacker, source_file))) { 191 source_file))) {
192 NOTREACHED(); 192 NOTREACHED();
193 } 193 }
194 } 194 }
195 195
196 void CrxInstaller::InstallUserScript(const base::FilePath& source_file, 196 void CrxInstaller::InstallUserScript(const base::FilePath& source_file,
197 const GURL& download_url) { 197 const GURL& download_url) {
198 DCHECK(!download_url.is_empty()); 198 DCHECK(!download_url.is_empty());
199 199
200 NotifyCrxInstallBegin(); 200 NotifyCrxInstallBegin();
201 201
202 source_file_ = source_file; 202 source_file_ = source_file;
203 download_url_ = download_url; 203 download_url_ = download_url;
204 204
205 if (!installer_task_runner_->PostTask( 205 if (!installer_task_runner_->PostTask(
206 FROM_HERE, 206 FROM_HERE,
207 base::Bind(&CrxInstaller::ConvertUserScriptOnFileThread, this))) 207 base::BindOnce(&CrxInstaller::ConvertUserScriptOnFileThread, this)))
208 NOTREACHED(); 208 NOTREACHED();
209 } 209 }
210 210
211 void CrxInstaller::ConvertUserScriptOnFileThread() { 211 void CrxInstaller::ConvertUserScriptOnFileThread() {
212 base::string16 error; 212 base::string16 error;
213 scoped_refptr<Extension> extension = ConvertUserScriptToExtension( 213 scoped_refptr<Extension> extension = ConvertUserScriptToExtension(
214 source_file_, download_url_, install_directory_, &error); 214 source_file_, download_url_, install_directory_, &error);
215 if (!extension.get()) { 215 if (!extension.get()) {
216 ReportFailureFromFileThread(CrxInstallError(error)); 216 ReportFailureFromFileThread(CrxInstallError(error));
217 return; 217 return;
218 } 218 }
219 219
220 OnUnpackSuccess(extension->path(), extension->path(), nullptr, 220 OnUnpackSuccess(extension->path(), extension->path(), nullptr,
221 extension.get(), SkBitmap()); 221 extension.get(), SkBitmap());
222 } 222 }
223 223
224 void CrxInstaller::InstallWebApp(const WebApplicationInfo& web_app) { 224 void CrxInstaller::InstallWebApp(const WebApplicationInfo& web_app) {
225 NotifyCrxInstallBegin(); 225 NotifyCrxInstallBegin();
226 226
227 if (!installer_task_runner_->PostTask( 227 if (!installer_task_runner_->PostTask(
228 FROM_HERE, 228 FROM_HERE, base::BindOnce(&CrxInstaller::ConvertWebAppOnFileThread,
229 base::Bind(&CrxInstaller::ConvertWebAppOnFileThread, this, web_app))) 229 this, web_app)))
230 NOTREACHED(); 230 NOTREACHED();
231 } 231 }
232 232
233 void CrxInstaller::ConvertWebAppOnFileThread( 233 void CrxInstaller::ConvertWebAppOnFileThread(
234 const WebApplicationInfo& web_app) { 234 const WebApplicationInfo& web_app) {
235 scoped_refptr<Extension> extension(ConvertWebAppToExtension( 235 scoped_refptr<Extension> extension(ConvertWebAppToExtension(
236 web_app, base::Time::Now(), install_directory_)); 236 web_app, base::Time::Now(), install_directory_));
237 if (!extension.get()) { 237 if (!extension.get()) {
238 // Validation should have stopped any potential errors before getting here. 238 // Validation should have stopped any potential errors before getting here.
239 NOTREACHED() << "Could not convert web app to extension."; 239 NOTREACHED() << "Could not convert web app to extension.";
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // We don't have to delete the unpack dir explicity since it is a child of 446 // We don't have to delete the unpack dir explicity since it is a child of
447 // the temp dir. 447 // the temp dir.
448 unpacked_extension_root_ = extension_dir; 448 unpacked_extension_root_ = extension_dir;
449 449
450 CrxInstallError error = AllowInstall(extension); 450 CrxInstallError error = AllowInstall(extension);
451 if (error.type() != CrxInstallError::ERROR_NONE) { 451 if (error.type() != CrxInstallError::ERROR_NONE) {
452 ReportFailureFromFileThread(error); 452 ReportFailureFromFileThread(error);
453 return; 453 return;
454 } 454 }
455 455
456 if (!BrowserThread::PostTask(BrowserThread::UI, 456 if (!BrowserThread::PostTask(
457 FROM_HERE, 457 BrowserThread::UI, FROM_HERE,
458 base::Bind(&CrxInstaller::CheckInstall, this))) 458 base::BindOnce(&CrxInstaller::CheckInstall, this)))
459 NOTREACHED(); 459 NOTREACHED();
460 } 460 }
461 461
462 void CrxInstaller::CheckInstall() { 462 void CrxInstaller::CheckInstall() {
463 DCHECK_CURRENTLY_ON(BrowserThread::UI); 463 DCHECK_CURRENTLY_ON(BrowserThread::UI);
464 ExtensionService* service = service_weak_.get(); 464 ExtensionService* service = service_weak_.get();
465 if (!service || service->browser_terminating()) 465 if (!service || service->browser_terminating())
466 return; 466 return;
467 467
468 // TODO(crbug.com/420147): Move this code to a utility class to avoid 468 // TODO(crbug.com/420147): Move this code to a utility class to avoid
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } 675 }
676 676
677 void CrxInstaller::UpdateCreationFlagsAndCompleteInstall() { 677 void CrxInstaller::UpdateCreationFlagsAndCompleteInstall() {
678 creation_flags_ = extension()->creation_flags() | Extension::REQUIRE_KEY; 678 creation_flags_ = extension()->creation_flags() | Extension::REQUIRE_KEY;
679 // If the extension was already installed and had file access, also grant file 679 // If the extension was already installed and had file access, also grant file
680 // access to the updated extension. 680 // access to the updated extension.
681 if (ExtensionPrefs::Get(profile())->AllowFileAccess(extension()->id())) 681 if (ExtensionPrefs::Get(profile())->AllowFileAccess(extension()->id()))
682 creation_flags_ |= Extension::ALLOW_FILE_ACCESS; 682 creation_flags_ |= Extension::ALLOW_FILE_ACCESS;
683 683
684 if (!installer_task_runner_->PostTask( 684 if (!installer_task_runner_->PostTask(
685 FROM_HERE, base::Bind(&CrxInstaller::CompleteInstall, this))) { 685 FROM_HERE, base::BindOnce(&CrxInstaller::CompleteInstall, this))) {
686 NOTREACHED(); 686 NOTREACHED();
687 } 687 }
688 } 688 }
689 689
690 void CrxInstaller::CompleteInstall() { 690 void CrxInstaller::CompleteInstall() {
691 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); 691 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread());
692 692
693 if (current_version_.IsValid() && 693 if (current_version_.IsValid() &&
694 current_version_.CompareTo(*(extension()->version())) > 0) { 694 current_version_.CompareTo(*(extension()->version())) > 0) {
695 ReportFailureFromFileThread(CrxInstallError( 695 ReportFailureFromFileThread(CrxInstallError(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 } else { 746 } else {
747 LOG(ERROR) << error << " " << extension_id << " " << download_url_; 747 LOG(ERROR) << error << " " << extension_id << " " << download_url_;
748 ReportFailureFromFileThread(CrxInstallError(base::UTF8ToUTF16(error))); 748 ReportFailureFromFileThread(CrxInstallError(base::UTF8ToUTF16(error)));
749 } 749 }
750 } 750 }
751 751
752 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallError& error) { 752 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallError& error) {
753 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); 753 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread());
754 if (!BrowserThread::PostTask( 754 if (!BrowserThread::PostTask(
755 BrowserThread::UI, FROM_HERE, 755 BrowserThread::UI, FROM_HERE,
756 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { 756 base::BindOnce(&CrxInstaller::ReportFailureFromUIThread, this,
757 error))) {
757 NOTREACHED(); 758 NOTREACHED();
758 } 759 }
759 } 760 }
760 761
761 void CrxInstaller::ReportFailureFromUIThread(const CrxInstallError& error) { 762 void CrxInstaller::ReportFailureFromUIThread(const CrxInstallError& error) {
762 DCHECK_CURRENTLY_ON(BrowserThread::UI); 763 DCHECK_CURRENTLY_ON(BrowserThread::UI);
763 764
764 if (!service_weak_.get() || service_weak_->browser_terminating()) 765 if (!service_weak_.get() || service_weak_->browser_terminating())
765 return; 766 return;
766 767
(...skipping 23 matching lines...) Expand all
790 791
791 void CrxInstaller::ReportSuccessFromFileThread() { 792 void CrxInstaller::ReportSuccessFromFileThread() {
792 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); 793 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread());
793 794
794 // Tracking number of extensions installed by users 795 // Tracking number of extensions installed by users
795 if (install_cause() == extension_misc::INSTALL_CAUSE_USER_DOWNLOAD) 796 if (install_cause() == extension_misc::INSTALL_CAUSE_USER_DOWNLOAD)
796 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionInstalled", 1, 2); 797 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionInstalled", 1, 2);
797 798
798 if (!BrowserThread::PostTask( 799 if (!BrowserThread::PostTask(
799 BrowserThread::UI, FROM_HERE, 800 BrowserThread::UI, FROM_HERE,
800 base::Bind(&CrxInstaller::ReportSuccessFromUIThread, this))) 801 base::BindOnce(&CrxInstaller::ReportSuccessFromUIThread, this)))
801 NOTREACHED(); 802 NOTREACHED();
802 803
803 // Delete temporary files. 804 // Delete temporary files.
804 CleanupTempFiles(); 805 CleanupTempFiles();
805 } 806 }
806 807
807 void CrxInstaller::ReportSuccessFromUIThread() { 808 void CrxInstaller::ReportSuccessFromUIThread() {
808 DCHECK_CURRENTLY_ON(BrowserThread::UI); 809 DCHECK_CURRENTLY_ON(BrowserThread::UI);
809 810
810 if (!service_weak_.get() || service_weak_->browser_terminating()) 811 if (!service_weak_.get() || service_weak_->browser_terminating())
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 InstallTrackerFactory::GetForBrowserContext(profile()) 854 InstallTrackerFactory::GetForBrowserContext(profile())
854 ->OnFinishCrxInstall(success ? extension()->id() : expected_id_, success); 855 ->OnFinishCrxInstall(success ? extension()->id() : expected_id_, success);
855 856
856 if (success) 857 if (success)
857 ConfirmReEnable(); 858 ConfirmReEnable();
858 } 859 }
859 860
860 void CrxInstaller::CleanupTempFiles() { 861 void CrxInstaller::CleanupTempFiles() {
861 if (!installer_task_runner_->RunsTasksOnCurrentThread()) { 862 if (!installer_task_runner_->RunsTasksOnCurrentThread()) {
862 if (!installer_task_runner_->PostTask( 863 if (!installer_task_runner_->PostTask(
863 FROM_HERE, 864 FROM_HERE, base::BindOnce(&CrxInstaller::CleanupTempFiles, this))) {
864 base::Bind(&CrxInstaller::CleanupTempFiles, this))) {
865 NOTREACHED(); 865 NOTREACHED();
866 } 866 }
867 return; 867 return;
868 } 868 }
869 869
870 // Delete the temp directory and crx file as necessary. 870 // Delete the temp directory and crx file as necessary.
871 if (!temp_dir_.value().empty()) { 871 if (!temp_dir_.value().empty()) {
872 file_util::DeleteFile(temp_dir_, true); 872 file_util::DeleteFile(temp_dir_, true);
873 temp_dir_ = base::FilePath(); 873 temp_dir_ = base::FilePath();
874 } 874 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension( 920 ExtensionInstallPrompt::GetReEnablePromptTypeForExtension(
921 service->profile(), extension()); 921 service->profile(), extension());
922 client_->ShowDialog(base::Bind(&CrxInstaller::OnInstallPromptDone, this), 922 client_->ShowDialog(base::Bind(&CrxInstaller::OnInstallPromptDone, this),
923 extension(), nullptr, 923 extension(), nullptr,
924 base::MakeUnique<ExtensionInstallPrompt::Prompt>(type), 924 base::MakeUnique<ExtensionInstallPrompt::Prompt>(type),
925 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); 925 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
926 } 926 }
927 } 927 }
928 928
929 } // namespace extensions 929 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/content_verifier_browsertest.cc ('k') | chrome/browser/extensions/event_router_forwarder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698