1// Copyright 2013 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#ifndef CHROME_BROWSER_APPS_SHORTCUT_MANAGER_H_
6#define CHROME_BROWSER_APPS_SHORTCUT_MANAGER_H_
7
8#include "base/memory/weak_ptr.h"
9#include "base/scoped_observer.h"
10#include "chrome/browser/profiles/profile_info_cache_observer.h"
11#include "components/keyed_service/core/keyed_service.h"
12#include "extensions/browser/extension_registry_observer.h"
13#include "extensions/common/extension.h"
14
15class PrefService;
16class Profile;
17
18namespace extensions {
19class ExtensionRegistry;
20}
21
22namespace user_prefs {
23class PrefRegistrySyncable;
24}
25
26// This class manages the installation of shortcuts for platform apps.
27class AppShortcutManager : public KeyedService,
28                           public extensions::ExtensionRegistryObserver,
29                           public ProfileInfoCacheObserver {
30 public:
31  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
32
33  explicit AppShortcutManager(Profile* profile);
34
35  virtual ~AppShortcutManager();
36
37  // Updates all shortcuts if kAppShortcutsVersion in prefs is less than
38  // kCurrentAppShortcutsVersion.
39  void UpdateShortcutsForAllAppsIfNeeded();
40
41  // extensions::ExtensionRegistryObserver.
42  virtual void OnExtensionWillBeInstalled(
43      content::BrowserContext* browser_context,
44      const extensions::Extension* extension,
45      bool is_update,
46      bool from_ephemeral,
47      const std::string& old_name) OVERRIDE;
48  virtual void OnExtensionUninstalled(
49      content::BrowserContext* browser_context,
50      const extensions::Extension* extension,
51      extensions::UninstallReason reason) OVERRIDE;
52
53  // ProfileInfoCacheObserver.
54  virtual void OnProfileWillBeRemoved(
55      const base::FilePath& profile_path) OVERRIDE;
56
57 private:
58  void DeleteApplicationShortcuts(const extensions::Extension* extension);
59
60  Profile* profile_;
61  bool is_profile_info_cache_observer_;
62  PrefService* prefs_;
63
64  ScopedObserver<extensions::ExtensionRegistry,
65                 extensions::ExtensionRegistryObserver>
66      extension_registry_observer_;
67
68  base::WeakPtrFactory<AppShortcutManager> weak_ptr_factory_;
69
70  DISALLOW_COPY_AND_ASSIGN(AppShortcutManager);
71};
72
73#endif  // CHROME_BROWSER_APPS_SHORTCUT_MANAGER_H_
74