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.
5 #include "apps/shortcut_manager.h"
8 #include "base/compiler_specific.h"
9 #include "chrome/browser/shell_integration.h"
10 #include "chrome/browser/ui/web_applications/web_app_ui.h"
11 #include "chrome/browser/web_applications/web_app.h"
12 #include "chrome/common/chrome_notification_types.h"
13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_source.h"
16 using extensions::Extension
;
20 ShortcutManager::ShortcutManager(Profile
* profile
)
22 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
23 registrar_
.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED
,
24 content::Source
<Profile
>(profile_
));
25 registrar_
.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED
,
26 content::Source
<Profile
>(profile_
));
29 ShortcutManager::~ShortcutManager() {}
31 void ShortcutManager::Observe(int type
,
32 const content::NotificationSource
& source
,
33 const content::NotificationDetails
& details
) {
35 case chrome::NOTIFICATION_EXTENSION_INSTALLED
: {
36 #if !defined(OS_MACOSX)
37 const Extension
* extension
= content::Details
<const Extension
>(
39 if (extension
->is_platform_app() &&
40 extension
->location() != extensions::Manifest::COMPONENT
) {
41 web_app::UpdateShortcutInfoAndIconForApp(*extension
, profile_
,
42 base::Bind(&web_app::UpdateAllShortcuts
));
44 #endif // !defined(OS_MACOSX)
47 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED
: {
48 const Extension
* extension
= content::Details
<const Extension
>(
50 DeleteApplicationShortcuts(extension
);
58 void ShortcutManager::DeleteApplicationShortcuts(
59 const Extension
* extension
) {
60 ShellIntegration::ShortcutInfo delete_info
=
61 web_app::ShortcutInfoForExtensionAndProfile(extension
, profile_
);
62 web_app::DeleteAllShortcuts(delete_info
);