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

Unified Diff: chrome/browser/ui/extensions/extension_enable_flow.cc

Issue 11644077: Put extension enable logic into a ExtensionEnableFlow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + address comments in #1 Created 7 years, 11 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: chrome/browser/ui/extensions/extension_enable_flow.cc
diff --git a/chrome/browser/ui/extensions/extension_enable_flow.cc b/chrome/browser/ui/extensions/extension_enable_flow.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2c4f2758550991e33e589f32aeb2e89cc92a9014
--- /dev/null
+++ b/chrome/browser/ui/extensions/extension_enable_flow.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/extensions/extension_enable_flow.h"
+
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
+
+using extensions::Extension;
+
+ExtensionEnableFlow::ExtensionEnableFlow(Profile* profile,
+ const std::string& extension_id,
+ ExtensionEnableFlowDelegate* delegate)
+ : profile_(profile),
+ extension_id_(extension_id),
+ delegate_(delegate) {
+}
+
+ExtensionEnableFlow::~ExtensionEnableFlow() {
+}
+
+void ExtensionEnableFlow::Start() {
+ ExtensionService* service =
+ extensions::ExtensionSystem::Get(profile_)->extension_service();
+ const Extension* extension = service->GetExtensionById(extension_id_, true);
+ if (!extension) {
+ extension = service->GetTerminatedExtension(extension_id_);
+ // It's possible (though unlikely) the app could have been uninstalled since
+ // the user clicked on it.
+ if (!extension)
+ return;
+ // If the app was terminated, reload it first. (This reallocates the
+ // Extension object.)
+ service->ReloadExtension(extension_id_);
+ extension = service->GetExtensionById(extension_id_, true);
+ }
+
+ extensions::ExtensionPrefs* extension_prefs = service->extension_prefs();
+ if (!extension_prefs->DidExtensionEscalatePermissions(extension_id_)) {
+ // Enable the extension immediately if its privileges weren't escalated.
+ // This is a no-op if the extension was previously terminated.
+ service->EnableExtension(extension_id_);
+
+ delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us.
+ return;
+ }
+
+ if (!prompt_)
+ prompt_.reset(delegate_->CreateExtensionInstallPrompt());
+ prompt_->ConfirmReEnable(this, extension);
+}
+
+void ExtensionEnableFlow::InstallUIProceed() {
+ ExtensionService* service =
+ extensions::ExtensionSystem::Get(profile_)->extension_service();
+
+ // The extension can be uninstalled in another window while the UI was
+ // showing. Do nothing in that case.
+ const Extension* extension = service->GetExtensionById(extension_id_, true);
+ if (!extension)
+ return;
+
+ service->GrantPermissionsAndEnableExtension(extension,
+ prompt_->record_oauth2_grant());
+ delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us.
+}
+
+void ExtensionEnableFlow::InstallUIAbort(bool user_initiated) {
+ delegate_->ExtensionEnableFlowAborted(user_initiated);
+ // |delegate_| may delete us.
+}
« no previous file with comments | « chrome/browser/ui/extensions/extension_enable_flow.h ('k') | chrome/browser/ui/extensions/extension_enable_flow_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698