| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/autocomplete/shortcuts_extensions_manager.h" | 5 #include "chrome/browser/autocomplete/shortcuts_extensions_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" | 7 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 10 #include "components/omnibox/browser/shortcuts_backend.h" | 9 #include "components/omnibox/browser/shortcuts_backend.h" |
| 11 #include "content/public/browser/notification_details.h" | 10 #include "extensions/browser/extension_registry.h" |
| 12 #include "content/public/browser/notification_source.h" | |
| 13 #include "extensions/features/features.h" | |
| 14 | |
| 15 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 16 #include "extensions/browser/notification_types.h" | |
| 17 #include "extensions/common/extension.h" | 11 #include "extensions/common/extension.h" |
| 18 #endif | |
| 19 | 12 |
| 20 ShortcutsExtensionsManager::ShortcutsExtensionsManager(Profile* profile) | 13 ShortcutsExtensionsManager::ShortcutsExtensionsManager(Profile* profile) |
| 21 : profile_(profile) { | 14 : registry_observer_(this), profile_(profile) { |
| 22 DCHECK(profile_); | 15 DCHECK(profile_); |
| 23 #if BUILDFLAG(ENABLE_EXTENSIONS) | 16 registry_observer_.Add(extensions::ExtensionRegistry::Get(profile_)); |
| 24 notification_registrar_.Add( | |
| 25 this, extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
| 26 content::Source<Profile>(profile_)); | |
| 27 #endif | |
| 28 } | 17 } |
| 29 | 18 |
| 30 ShortcutsExtensionsManager::~ShortcutsExtensionsManager() {} | 19 ShortcutsExtensionsManager::~ShortcutsExtensionsManager() {} |
| 31 | 20 |
| 32 void ShortcutsExtensionsManager::Observe( | 21 void ShortcutsExtensionsManager::OnExtensionUnloaded( |
| 33 int type, | 22 content::BrowserContext* browser_context, |
| 34 const content::NotificationSource& source, | 23 const extensions::Extension* extension, |
| 35 const content::NotificationDetails& details) { | 24 extensions::UnloadedExtensionInfo::Reason reason) { |
| 36 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 37 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, type); | |
| 38 scoped_refptr<ShortcutsBackend> shortcuts_backend = | 25 scoped_refptr<ShortcutsBackend> shortcuts_backend = |
| 39 ShortcutsBackendFactory::GetForProfileIfExists(profile_); | 26 ShortcutsBackendFactory::GetForProfileIfExists(profile_); |
| 40 if (!shortcuts_backend) | 27 if (!shortcuts_backend) |
| 41 return; | 28 return; |
| 42 | 29 |
| 43 // When an extension is unloaded, we want to remove any Shortcuts associated | 30 // When an extension is unloaded, we want to remove any Shortcuts associated |
| 44 // with it. | 31 // with it. |
| 45 shortcuts_backend->DeleteShortcutsBeginningWithURL( | 32 shortcuts_backend->DeleteShortcutsBeginningWithURL(extension->url()); |
| 46 content::Details<extensions::UnloadedExtensionInfo>(details) | |
| 47 ->extension->url()); | |
| 48 #endif | |
| 49 } | 33 } |
| 34 |
| 35 void ShortcutsExtensionsManager::OnShutdown( |
| 36 extensions::ExtensionRegistry* registry) { |
| 37 registry_observer_.RemoveAll(); |
| 38 } |
| OLD | NEW |