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

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

Issue 309643007: Resubmit: Refactor external_install_ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Created 6 years, 6 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 2014 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/extensions/external_install_manager.h"
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/external_install_error.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/extensions/manifest_url_handler.h"
15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_source.h"
17 #include "extensions/browser/extension_registry.h"
18 #include "extensions/browser/extension_system.h"
19 #include "extensions/common/extension.h"
20
21 namespace extensions {
22
23 ExternalInstallManager::ExternalInstallManager(
24 content::BrowserContext* browser_context)
25 : browser_context_(browser_context),
26 extension_registry_observer_(this) {
27 DCHECK(browser_context_);
28 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
29 registrar_.Add(this,
30 chrome::NOTIFICATION_EXTENSION_REMOVED,
31 content::Source<Profile>(
32 Profile::FromBrowserContext(browser_context_)));
33 }
34
35 ExternalInstallManager::~ExternalInstallManager() {
36 }
37
38 void ExternalInstallManager::AddExternalInstallError(const Extension* extension,
39 bool is_new_profile) {
40 if (HasExternalInstallError())
41 return; // Only have one external install error at a time.
42
43 if (ManifestURL::UpdatesFromGallery(extension) && !is_new_profile) {
44 error_.reset(new ExternalInstallError(browser_context_,
45 extension->id(),
46 ExternalInstallError::BUBBLE_ALERT,
47 this));
48 } else {
49 error_.reset(new ExternalInstallError(browser_context_,
50 extension->id(),
51 ExternalInstallError::MENU_ALERT,
52 this));
53 }
54 }
55
56 void ExternalInstallManager::RemoveExternalInstallError() {
57 if (error_.get()) {
58 error_.reset();
59 ExtensionSystem::Get(browser_context_)
60 ->extension_service()
61 ->UpdateExternalExtensionAlert();
62 }
63 }
64
65 bool ExternalInstallManager::HasExternalInstallError() const {
66 return error_.get() != NULL;
67 }
68
69 bool ExternalInstallManager::HasExternalInstallBubble() const {
70 return error_.get() &&
71 error_->alert_type() == ExternalInstallError::BUBBLE_ALERT;
72 }
73
74 void ExternalInstallManager::OnExtensionLoaded(
75 content::BrowserContext* browser_context,
76 const Extension* extension) {
77 // The error is invalidated if the extension has been loaded or removed.
78 if (error_.get() && extension->id() == error_->extension_id()) {
79 // We treat loading as acknowledgement (since the user consciously chose to
80 // re-enable the extension).
81 error_->AcknowledgeExtension();
82 RemoveExternalInstallError();
83 }
84 }
85
86 void ExternalInstallManager::Observe(
87 int type,
88 const content::NotificationSource& source,
89 const content::NotificationDetails& details) {
90 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_REMOVED, type);
91 // The error is invalidated if the extension has been loaded or removed.
92 // It's a shame we have to use the notification system (instead of the
93 // registry observer) for this, but the ExtensionUnloaded notification is
94 // not sent out if the extension is disabled (which it is here).
95 if (error_.get() &&
96 content::Details<const Extension>(details).ptr()->id() ==
97 error_->extension_id()) {
98 RemoveExternalInstallError();
99 }
100 }
101
102 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/external_install_manager.h ('k') | chrome/browser/extensions/external_install_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698