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_
10 #include "chrome/browser/extensions/extension_assets_manager.h"
12 template <typename T> struct DefaultSingletonTraits;
13 class PrefRegistrySimple;
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 {
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 virtual void InstallExtension(const Extension* extension,
42 const base::FilePath& unpacked_extension_root,
43 const base::FilePath& local_install_dir,
45 InstallExtensionCallback callback) OVERRIDE;
46 virtual void UninstallExtension(
47 const std::string& id,
49 const base::FilePath& local_install_dir,
50 const base::FilePath& extension_root) OVERRIDE;
52 // Return shared install dir.
53 static base::FilePath GetSharedInstallDir();
55 // Cleans up shared extensions list in preferences and returns list of
56 // extension IDs and version paths that are in use in |live_extension_paths|.
57 // Files on disk are not removed. Must be called on UI thread.
58 // Returns |false| in case of errors.
59 static bool CleanUpSharedExtensions(
60 std::multimap<std::string, base::FilePath>* live_extension_paths);
62 static void SetSharedInstallDirForTesting(const base::FilePath& install_dir);
65 friend struct DefaultSingletonTraits<ExtensionAssetsManagerChromeOS>;
67 ExtensionAssetsManagerChromeOS();
68 virtual ~ExtensionAssetsManagerChromeOS();
70 // Should be called on UI thread to get associated file task runner for
72 static base::SequencedTaskRunner* GetFileTaskRunner(Profile* profile);
74 // Return |true| if |extension| can be installed in a shared place for all
75 // users on the device.
76 static bool CanShareAssets(const Extension* extension);
78 // Called on the UI thread to check if a given version of the |extension|
79 // already exists at the shared location.
80 static void CheckSharedExtension(
81 const std::string& id,
82 const std::string& version,
83 const base::FilePath& unpacked_extension_root,
84 const base::FilePath& local_install_dir,
86 InstallExtensionCallback callback);
88 // Called on task runner thread to install extension to shared location.
89 static void InstallSharedExtension(
90 const std::string& id,
91 const std::string& version,
92 const base::FilePath& unpacked_extension_root);
94 // Called on UI thread to process shared install result.
95 static void InstallSharedExtensionDone(
96 const std::string& id,
97 const std::string& version,
98 const base::FilePath& shared_version_dir);
100 // Called on task runner thread to install the extension to local dir call
101 // callback with the result.
102 static void InstallLocalExtension(
103 const std::string& id,
104 const std::string& version,
105 const base::FilePath& unpacked_extension_root,
106 const base::FilePath& local_install_dir,
107 InstallExtensionCallback callback);
109 // Called on UI thread to mark that shared version is not used.
110 static void MarkSharedExtensionUnused(const std::string& id,
113 // Called on task runner thread to remove shared version.
114 static void DeleteSharedVersion(const base::FilePath& shared_version_dir);
116 // Clean shared extension with given |id|.
117 static bool CleanUpExtension(
118 const std::string& id,
119 base::DictionaryValue* extension_info,
120 std::multimap<std::string, base::FilePath>* live_extension_paths);
122 DISALLOW_COPY_AND_ASSIGN(ExtensionAssetsManagerChromeOS);
125 } // namespace extensions
127 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_