Support multiple voices for all available modules (text-to-speech engines) on Linux.
[chromium-blink-merge.git] / apps / shortcut_manager.cc
blobdf31a797a3013550d08559297ffc787e51feb241
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"
7 #include "base/bind.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;
18 namespace {
20 // Creates a shortcut for an application in the applications menu.
21 void CreateShortcutsInApplicationsMenu(
22 const ShellIntegration::ShortcutInfo& shortcut_info) {
23 ShellIntegration::ShortcutLocations creation_locations;
24 creation_locations.in_applications_menu = true;
25 // Create the shortcut in the Chrome Apps subdir.
26 creation_locations.applications_menu_subdir =
27 web_app::GetAppShortcutsSubdirName();
28 web_app::CreateShortcuts(shortcut_info, creation_locations);
31 } // namespace
33 namespace apps {
35 ShortcutManager::ShortcutManager(Profile* profile)
36 : profile_(profile),
37 weak_factory_(this) {
38 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
39 content::Source<Profile>(profile_));
40 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
41 content::Source<Profile>(profile_));
44 ShortcutManager::~ShortcutManager() {}
46 void ShortcutManager::Observe(int type,
47 const content::NotificationSource& source,
48 const content::NotificationDetails& details) {
49 switch (type) {
50 case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
51 #if !defined(OS_MACOSX)
52 const extensions::InstalledExtensionInfo* installed_info =
53 content::Details<const extensions::InstalledExtensionInfo>(details)
54 .ptr();
55 const Extension* extension = installed_info->extension;
56 if (extension->is_platform_app() &&
57 extension->location() != extensions::Manifest::COMPONENT) {
58 // If the app is being updated, update any existing shortcuts but do not
59 // create new ones. If it is being installed, automatically create a
60 // shortcut in the applications menu (e.g., Start Menu).
61 base::Callback<void(const ShellIntegration::ShortcutInfo&)>
62 create_or_update;
63 if (installed_info->is_update) {
64 create_or_update = base::Bind(&web_app::UpdateAllShortcuts);
65 } else {
66 create_or_update = base::Bind(&CreateShortcutsInApplicationsMenu);
69 web_app::UpdateShortcutInfoAndIconForApp(*extension, profile_,
70 create_or_update);
72 #endif // !defined(OS_MACOSX)
73 break;
75 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
76 const Extension* extension = content::Details<const Extension>(
77 details).ptr();
78 DeleteApplicationShortcuts(extension);
79 break;
81 default:
82 NOTREACHED();
86 void ShortcutManager::DeleteApplicationShortcuts(
87 const Extension* extension) {
88 ShellIntegration::ShortcutInfo delete_info =
89 web_app::ShortcutInfoForExtensionAndProfile(extension, profile_);
90 web_app::DeleteAllShortcuts(delete_info);
93 } // namespace apps