Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_assets_manager_chromeos.h
blobbfb37ad3aab074d5e37a1d29e3408d5ec0b2ea2c
1 // Copyright (c) 2014 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_
8 #include <map>
10 #include "chrome/browser/extensions/extension_assets_manager.h"
12 template <typename T> struct DefaultSingletonTraits;
13 class PrefRegistrySimple;
15 namespace base {
16 class DictionaryValue;
17 class SequencedTaskRunner;
20 namespace extensions {
22 // Chrome OS specific implementation of assets manager that shares default apps
23 // between all users on the machine.
24 class ExtensionAssetsManagerChromeOS : public ExtensionAssetsManager {
25 public:
26 static ExtensionAssetsManagerChromeOS* GetInstance();
28 // A dictionary that maps shared extension IDs to version/paths/users.
29 static const char kSharedExtensions[];
31 // Name of path attribute in shared extensions map.
32 static const char kSharedExtensionPath[];
34 // Name of users attribute (list of user emails) in shared extensions map.
35 static const char kSharedExtensionUsers[];
37 // Register shared assets related preferences.
38 static void RegisterPrefs(PrefRegistrySimple* registry);
40 // Override from ExtensionAssetsManager.
41 void InstallExtension(const Extension* extension,
42 const base::FilePath& unpacked_extension_root,
43 const base::FilePath& local_install_dir,
44 Profile* profile,
45 InstallExtensionCallback callback) override;
46 void UninstallExtension(const std::string& id,
47 Profile* profile,
48 const base::FilePath& local_install_dir,
49 const base::FilePath& extension_root) override;
51 // Return shared install dir.
52 static base::FilePath GetSharedInstallDir();
54 // Return true if |extension| was installed to shared location.
55 static bool IsSharedInstall(const Extension* extension);
57 // Cleans up shared extensions list in preferences and returns list of
58 // extension IDs and version paths that are in use in |live_extension_paths|.
59 // Files on disk are not removed. Must be called on UI thread.
60 // Returns |false| in case of errors.
61 static bool CleanUpSharedExtensions(
62 std::multimap<std::string, base::FilePath>* live_extension_paths);
64 static void SetSharedInstallDirForTesting(const base::FilePath& install_dir);
66 private:
67 friend struct DefaultSingletonTraits<ExtensionAssetsManagerChromeOS>;
69 ExtensionAssetsManagerChromeOS();
70 ~ExtensionAssetsManagerChromeOS() override;
72 // Should be called on UI thread to get associated file task runner for
73 // the profile.
74 static base::SequencedTaskRunner* GetFileTaskRunner(Profile* profile);
76 // Return |true| if |extension| can be installed in a shared place for all
77 // users on the device.
78 static bool CanShareAssets(const Extension* extension,
79 const base::FilePath& unpacked_extension_root);
81 // Called on the UI thread to check if a given version of the |extension|
82 // already exists at the shared location.
83 static void CheckSharedExtension(
84 const std::string& id,
85 const std::string& version,
86 const base::FilePath& unpacked_extension_root,
87 const base::FilePath& local_install_dir,
88 Profile* profile,
89 InstallExtensionCallback callback);
91 // Called on task runner thread to install extension to shared location.
92 static void InstallSharedExtension(
93 const std::string& id,
94 const std::string& version,
95 const base::FilePath& unpacked_extension_root);
97 // Called on UI thread to process shared install result.
98 static void InstallSharedExtensionDone(
99 const std::string& id,
100 const std::string& version,
101 const base::FilePath& shared_version_dir);
103 // Called on task runner thread to install the extension to local dir call
104 // callback with the result.
105 static void InstallLocalExtension(
106 const std::string& id,
107 const std::string& version,
108 const base::FilePath& unpacked_extension_root,
109 const base::FilePath& local_install_dir,
110 InstallExtensionCallback callback);
112 // Called on UI thread to mark that shared version is not used.
113 static void MarkSharedExtensionUnused(const std::string& id,
114 Profile* profile);
116 // Called on task runner thread to remove shared version.
117 static void DeleteSharedVersion(const base::FilePath& shared_version_dir);
119 // Clean shared extension with given |id|.
120 static bool CleanUpExtension(
121 const std::string& id,
122 base::DictionaryValue* extension_info,
123 std::multimap<std::string, base::FilePath>* live_extension_paths);
125 DISALLOW_COPY_AND_ASSIGN(ExtensionAssetsManagerChromeOS);
128 } // namespace extensions
130 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_