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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/extensions/extension_enable_flow.h"
6
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
10
11 using extensions::Extension;
12
13 ExtensionEnableFlow::ExtensionEnableFlow(Profile* profile,
14 const std::string& extension_id,
15 ExtensionEnableFlowDelegate* delegate)
16 : profile_(profile),
17 extension_id_(extension_id),
18 delegate_(delegate) {
19 }
20
21 ExtensionEnableFlow::~ExtensionEnableFlow() {
22 }
23
24 void ExtensionEnableFlow::Start() {
25 ExtensionService* service =
26 extensions::ExtensionSystem::Get(profile_)->extension_service();
27 const Extension* extension = service->GetExtensionById(extension_id_, true);
28 if (!extension) {
29 extension = service->GetTerminatedExtension(extension_id_);
30 // It's possible (though unlikely) the app could have been uninstalled since
31 // the user clicked on it.
32 if (!extension)
33 return;
34 // If the app was terminated, reload it first. (This reallocates the
35 // Extension object.)
36 service->ReloadExtension(extension_id_);
37 extension = service->GetExtensionById(extension_id_, true);
38 }
39
40 extensions::ExtensionPrefs* extension_prefs = service->extension_prefs();
41 if (!extension_prefs->DidExtensionEscalatePermissions(extension_id_)) {
42 // Enable the extension immediately if its privileges weren't escalated.
43 // This is a no-op if the extension was previously terminated.
44 service->EnableExtension(extension_id_);
45
46 delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us.
47 return;
48 }
49
50 if (!prompt_)
51 prompt_.reset(delegate_->CreateExtensionInstallPrompt());
52 prompt_->ConfirmReEnable(this, extension);
53 }
54
55 void ExtensionEnableFlow::InstallUIProceed() {
56 ExtensionService* service =
57 extensions::ExtensionSystem::Get(profile_)->extension_service();
58
59 // The extension can be uninstalled in another window while the UI was
60 // showing. Do nothing in that case.
61 const Extension* extension = service->GetExtensionById(extension_id_, true);
62 if (!extension)
63 return;
64
65 service->GrantPermissionsAndEnableExtension(extension,
66 prompt_->record_oauth2_grant());
67 delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us.
68 }
69
70 void ExtensionEnableFlow::InstallUIAbort(bool user_initiated) {
71 delegate_->ExtensionEnableFlowAborted(user_initiated);
72 // |delegate_| may delete us.
73 }
OLDNEW
« 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