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

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

Issue 2885143003: [Extensions] Remove external errors on profile shutdown (Closed)
Patch Set: . Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 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 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/external_install_manager.h" 5 #include "chrome/browser/extensions/external_install_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 ExternalInstallManager::ExternalInstallManager( 61 ExternalInstallManager::ExternalInstallManager(
62 content::BrowserContext* browser_context, 62 content::BrowserContext* browser_context,
63 bool is_first_run) 63 bool is_first_run)
64 : browser_context_(browser_context), 64 : browser_context_(browser_context),
65 is_first_run_(is_first_run), 65 is_first_run_(is_first_run),
66 extension_prefs_(ExtensionPrefs::Get(browser_context_)), 66 extension_prefs_(ExtensionPrefs::Get(browser_context_)),
67 currently_visible_install_alert_(nullptr), 67 currently_visible_install_alert_(nullptr),
68 extension_registry_observer_(this) { 68 extension_registry_observer_(this) {
69 DCHECK(browser_context_); 69 DCHECK(browser_context_);
70 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); 70 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
71 registrar_.Add( 71 Profile* profile = Profile::FromBrowserContext(browser_context_);
72 this, 72 registrar_.Add(this, extensions::NOTIFICATION_EXTENSION_REMOVED,
73 extensions::NOTIFICATION_EXTENSION_REMOVED, 73 content::Source<Profile>(profile));
74 content::Source<Profile>(Profile::FromBrowserContext(browser_context_))); 74 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
75 content::Source<Profile>(profile));
75 // Populate the set of unacknowledged external extensions now. We can't just 76 // Populate the set of unacknowledged external extensions now. We can't just
76 // rely on IsUnacknowledgedExternalExtension() for cases like 77 // rely on IsUnacknowledgedExternalExtension() for cases like
77 // OnExtensionLoaded(), since we need to examine the disable reasons, which 78 // OnExtensionLoaded(), since we need to examine the disable reasons, which
78 // can be removed throughout the session. 79 // can be removed throughout the session.
79 for (const auto& extension : 80 for (const auto& extension :
80 ExtensionRegistry::Get(browser_context)->disabled_extensions()) { 81 ExtensionRegistry::Get(browser_context)->disabled_extensions()) {
81 if (IsUnacknowledgedExternalExtension(*extension)) 82 if (IsUnacknowledgedExternalExtension(*extension))
82 unacknowledged_ids_.insert(extension->id()); 83 unacknowledged_ids_.insert(extension->id());
83 } 84 }
84 } 85 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 (disable_reasons & Extension::DISABLE_EXTERNAL_EXTENSION) != 0; 240 (disable_reasons & Extension::DISABLE_EXTERNAL_EXTENSION) != 0;
240 return is_disabled_external && !is_from_sideload_wipeout && 241 return is_disabled_external && !is_from_sideload_wipeout &&
241 Manifest::IsExternalLocation(extension.location()) && 242 Manifest::IsExternalLocation(extension.location()) &&
242 !extension_prefs_->IsExternalExtensionAcknowledged(extension.id()); 243 !extension_prefs_->IsExternalExtensionAcknowledged(extension.id());
243 } 244 }
244 245
245 void ExternalInstallManager::Observe( 246 void ExternalInstallManager::Observe(
246 int type, 247 int type,
247 const content::NotificationSource& source, 248 const content::NotificationSource& source,
248 const content::NotificationDetails& details) { 249 const content::NotificationDetails& details) {
249 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_REMOVED, type); 250 switch (type) {
250 // The error is invalidated if the extension has been loaded or removed. 251 case extensions::NOTIFICATION_EXTENSION_REMOVED: {
251 // It's a shame we have to use the notification system (instead of the 252 // The error is invalidated if the extension has been loaded or removed.
252 // registry observer) for this, but the ExtensionUnloaded notification is 253 // It's a shame we have to use the notification system (instead of the
253 // not sent out if the extension is disabled (which it is here). 254 // registry observer) for this, but the ExtensionUnloaded notification is
254 const std::string& extension_id = 255 // not sent out if the extension is disabled (which it is here).
255 content::Details<const Extension>(details).ptr()->id(); 256 const std::string& extension_id =
256 if (base::ContainsKey(errors_, extension_id)) 257 content::Details<const Extension>(details).ptr()->id();
257 RemoveExternalInstallError(extension_id); 258 if (base::ContainsKey(errors_, extension_id))
259 RemoveExternalInstallError(extension_id);
260 break;
261 }
262 case chrome::NOTIFICATION_PROFILE_DESTROYED:
263 DCHECK_EQ(Profile::FromBrowserContext(browser_context_),
264 content::Source<const Profile>(source).ptr());
265 // Delete all errors when the profile is shutting down, before associated
266 // services are deleted.
267 errors_.clear();
268 break;
269 default:
270 NOTREACHED();
271 }
258 } 272 }
259 273
260 } // namespace extensions 274 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698