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

Unified Diff: extensions/browser/api/management/management_api.cc

Issue 948413005: [Extensions] Make chrome://extensions use management.uninstall (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/management/management_api.cc
diff --git a/extensions/browser/api/management/management_api.cc b/extensions/browser/api/management/management_api.cc
index 4d2292c8105b8c4e46e765788b4ea32e7f92ea46..fa01bc2386e38c6729231050c571f75dec320377 100644
--- a/extensions/browser/api/management/management_api.cc
+++ b/extensions/browser/api/management/management_api.cc
@@ -511,7 +511,7 @@ ManagementUninstallFunctionBase::ManagementUninstallFunctionBase() {
ManagementUninstallFunctionBase::~ManagementUninstallFunctionBase() {
}
-bool ManagementUninstallFunctionBase::Uninstall(
+ExtensionFunction::ResponseAction ManagementUninstallFunctionBase::Uninstall(
const std::string& target_extension_id,
bool show_confirm_dialog) {
const ManagementAPIDelegate* delegate = ManagementAPI::GetFactoryInstance()
@@ -523,33 +523,37 @@ bool ManagementUninstallFunctionBase::Uninstall(
->GetExtensionById(extension_id_, ExtensionRegistry::EVERYTHING);
if (!target_extension ||
ShouldNotBeVisible(target_extension, browser_context())) {
- error_ =
- ErrorUtils::FormatErrorMessage(keys::kNoExtensionError, extension_id_);
- return false;
+ return RespondNow(Error(keys::kNoExtensionError, extension_id_));
}
ManagementPolicy* policy =
ExtensionSystem::Get(browser_context())->management_policy();
if (!policy->UserMayModifySettings(target_extension, nullptr) ||
policy->MustRemainInstalled(target_extension, nullptr)) {
- error_ = ErrorUtils::FormatErrorMessage(keys::kUserCantModifyError,
- extension_id_);
- return false;
+ return RespondNow(Error(keys::kUserCantModifyError, extension_id_));
}
- if (auto_confirm_for_test == DO_NOT_SKIP) {
- if (show_confirm_dialog) {
- AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled
- uninstall_dialog_ =
- delegate->UninstallFunctionDelegate(this, target_extension_id);
- } else {
- Finish(true);
- }
- } else {
- Finish(auto_confirm_for_test == PROCEED);
+ if (show_confirm_dialog && auto_confirm_for_test == DO_NOT_SKIP) {
not at google - send to devlin 2015/02/25 21:37:58 There are just too many checks for |auto_confirm_f
Devlin 2015/02/25 23:12:47 Done.
+ AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled
+ // TODO(devlin): A method called "UninstallFunctionDelegate" does not in
not at google - send to devlin 2015/02/25 21:37:58 Indeed!
+ // any way imply that this actually creates a dialog and runs it.
+ uninstall_dialog_ =
+ delegate->UninstallFunctionDelegate(this, target_extension_id);
+ } else { // No confirm dialog.
not at google - send to devlin 2015/02/25 21:37:58 This is (at least, allowing me to not squint at th
Devlin 2015/02/25 23:12:47 Duplicating a post task is particularly ugly, IMO.
+ // Uninstall should succeed, unless we would normally show the confirm
+ // dialog but are taking a shortcut to the cancel for a test.
+ bool should_uninstall =
+ !(auto_confirm_for_test == ABORT && show_confirm_dialog);
+ // We do this asynchronously because Finish() Respond()s, which assumes that
+ // this function doesn't.
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ManagementUninstallFunctionBase::Finish,
+ this,
+ should_uninstall)); // This bind adds a ref.
not at google - send to devlin 2015/02/25 21:37:58 Seems like an obvious thing to comment?
Devlin 2015/02/25 23:12:47 Done.
}
- return true;
+ return RespondLater();
}
// static
@@ -559,34 +563,33 @@ void ManagementUninstallFunctionBase::SetAutoConfirmForTest(
}
void ManagementUninstallFunctionBase::Finish(bool should_uninstall) {
- if (should_uninstall) {
- // The extension can be uninstalled in another window while the UI was
- // showing. Do nothing in that case.
- ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context());
- const Extension* extension = registry->GetExtensionById(
- extension_id_, ExtensionRegistry::EVERYTHING);
- if (!extension) {
- error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
- extension_id_);
- SendResponse(false);
- } else {
- const ManagementAPIDelegate* delegate =
- ManagementAPI::GetFactoryInstance()
- ->Get(browser_context())
- ->GetDelegate();
- bool success = delegate->UninstallExtension(
- browser_context(), extension_id_,
- extensions::UNINSTALL_REASON_MANAGEMENT_API,
- base::Bind(&base::DoNothing), NULL);
-
- // TODO set error_ if !success
- SendResponse(success);
- }
- } else {
- error_ = ErrorUtils::FormatErrorMessage(keys::kUninstallCanceledError,
- extension_id_);
- SendResponse(false);
+ if (!should_uninstall) {
+ Respond(Error(keys::kUninstallCanceledError, extension_id_));
+ return;
+ }
+
+ // The extension can be uninstalled in another window while the UI was
+ // showing. Do nothing in that case.
+ const Extension* extension =
+ extensions::ExtensionRegistry::Get(browser_context())
+ ->GetExtensionById(extension_id_, ExtensionRegistry::EVERYTHING);
+ if (!extension) {
+ Respond(Error(keys::kNoExtensionError, extension_id_));
+ return;
}
+
+ const ManagementAPIDelegate* delegate =
+ ManagementAPI::GetFactoryInstance()
+ ->Get(browser_context())
+ ->GetDelegate();
+ base::string16 error;
+ bool success = delegate->UninstallExtension(
+ browser_context(), extension_id_,
+ extensions::UNINSTALL_REASON_MANAGEMENT_API,
+ base::Bind(&base::DoNothing), &error);
+ ResponseValue response =
+ success ? NoArguments() : Error(base::UTF16ToUTF8(error));
+ Respond(response.Pass());
not at google - send to devlin 2015/02/25 21:37:57 Inline |response|?
Devlin 2015/02/25 23:12:47 Done.
}
void ManagementUninstallFunctionBase::ExtensionUninstallAccepted() {
@@ -605,24 +608,22 @@ ManagementUninstallFunction::ManagementUninstallFunction() {
ManagementUninstallFunction::~ManagementUninstallFunction() {
}
-bool ManagementUninstallFunction::RunAsync() {
+ExtensionFunction::ResponseAction ManagementUninstallFunction::Run() {
scoped_ptr<management::Uninstall::Params> params(
management::Uninstall::Params::Create(*args_));
- EXTENSION_FUNCTION_VALIDATE(extension_.get());
EXTENSION_FUNCTION_VALIDATE(params.get());
bool show_confirm_dialog = true;
// By default confirmation dialog isn't shown when uninstalling self, but this
// can be overridden with showConfirmDialog.
- if (params->id == extension_->id()) {
+ if (extension_.get() && params->id == extension_->id()) {
show_confirm_dialog = params->options.get() &&
params->options->show_confirm_dialog.get() &&
*params->options->show_confirm_dialog;
not at google - send to devlin 2015/02/25 21:37:57 The Base already does this checking logic, no need
Devlin 2015/02/25 23:12:47 Done, ish. Too messy for one line.
}
- if (show_confirm_dialog && !user_gesture()) {
- error_ = keys::kGestureNeededForUninstallError;
- return false;
- }
+ if (show_confirm_dialog && !user_gesture())
not at google - send to devlin 2015/02/25 21:37:58 The user gesture logic should be moved into the ba
Devlin 2015/02/25 23:12:47 Done.
+ return RespondNow(Error(keys::kGestureNeededForUninstallError));
+
return Uninstall(params->id, show_confirm_dialog);
}
@@ -632,14 +633,15 @@ ManagementUninstallSelfFunction::ManagementUninstallSelfFunction() {
ManagementUninstallSelfFunction::~ManagementUninstallSelfFunction() {
}
-bool ManagementUninstallSelfFunction::RunAsync() {
+ExtensionFunction::ResponseAction ManagementUninstallSelfFunction::Run() {
scoped_ptr<management::UninstallSelf::Params> params(
management::UninstallSelf::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
+ EXTENSION_FUNCTION_VALIDATE(extension_.get());
- bool show_confirm_dialog = false;
- if (params->options.get() && params->options->show_confirm_dialog.get())
- show_confirm_dialog = *params->options->show_confirm_dialog;
+ bool show_confirm_dialog = params->options.get() &&
+ params->options->show_confirm_dialog.get() &&
+ *params->options->show_confirm_dialog;
return Uninstall(extension_->id(), show_confirm_dialog);
}

Powered by Google App Engine
This is Rietveld 408576698