OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_ |
7 | 7 |
8 #include <map> | |
9 | |
10 #include "chrome/browser/extensions/extension_assets_manager.h" | 8 #include "chrome/browser/extensions/extension_assets_manager.h" |
11 | 9 |
12 template <typename T> struct DefaultSingletonTraits; | 10 template <typename T> struct DefaultSingletonTraits; |
13 class PrefRegistrySimple; | 11 class PrefRegistrySimple; |
14 | 12 |
15 namespace base { | 13 namespace base { |
16 class DictionaryValue; | |
17 class SequencedTaskRunner; | 14 class SequencedTaskRunner; |
18 } | 15 } |
19 | 16 |
20 namespace extensions { | 17 namespace extensions { |
21 | 18 |
22 // Chrome OS specific implementation of assets manager that shares default apps | 19 // Chrome OS specific implementation of assets manager that shares default apps |
23 // between all users on the machine. | 20 // between all users on the machine. |
24 class ExtensionAssetsManagerChromeOS : public ExtensionAssetsManager { | 21 class ExtensionAssetsManagerChromeOS : public ExtensionAssetsManager { |
25 public: | 22 public: |
26 static ExtensionAssetsManagerChromeOS* GetInstance(); | 23 static ExtensionAssetsManagerChromeOS* GetInstance(); |
27 | 24 |
28 // A dictionary that maps shared extension IDs to version/paths/users. | 25 // Path to shared extensions install dir. |
29 static const char kSharedExtensions[]; | 26 static const char kSharedExtensionsDir[]; |
30 | |
31 // Name of path attribute in shared extensions map. | |
32 static const char kSharedExtensionPath[]; | |
33 | |
34 // Name of users attribute (list of user emails) in shared extensions map. | |
35 static const char kSharedExtensionUsers[]; | |
36 | 27 |
37 // Register shared assets related preferences. | 28 // Register shared assets related preferences. |
38 static void RegisterPrefs(PrefRegistrySimple* registry); | 29 static void RegisterPrefs(PrefRegistrySimple* registry); |
39 | 30 |
40 // Override from ExtensionAssetsManager. | 31 // Override from ExtensionAssetsManager. |
41 virtual void InstallExtension(const Extension* extension, | 32 virtual void InstallExtension(const Extension* extension, |
42 const base::FilePath& unpacked_extension_root, | 33 const base::FilePath& unpacked_extension_root, |
43 const base::FilePath& local_install_dir, | 34 const base::FilePath& local_install_dir, |
44 Profile* profile, | 35 Profile* profile, |
45 InstallExtensionCallback callback) OVERRIDE; | 36 InstallExtensionCallback callback) OVERRIDE; |
46 virtual void UninstallExtension( | 37 virtual void UninstallExtension( |
47 const std::string& id, | 38 const std::string& id, |
48 Profile* profile, | 39 Profile* profile, |
49 const base::FilePath& local_install_dir, | 40 const base::FilePath& local_install_dir, |
50 const base::FilePath& extension_root) OVERRIDE; | 41 const base::FilePath& extension_root) OVERRIDE; |
51 | 42 |
52 // Return shared install dir. | |
53 static base::FilePath GetSharedInstallDir(); | |
54 | |
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); | |
61 | |
62 static void SetSharedInstallDirForTesting(const base::FilePath& install_dir); | 43 static void SetSharedInstallDirForTesting(const base::FilePath& install_dir); |
63 | 44 |
64 private: | 45 private: |
65 friend struct DefaultSingletonTraits<ExtensionAssetsManagerChromeOS>; | 46 friend struct DefaultSingletonTraits<ExtensionAssetsManagerChromeOS>; |
66 | 47 |
67 ExtensionAssetsManagerChromeOS(); | 48 ExtensionAssetsManagerChromeOS(); |
68 virtual ~ExtensionAssetsManagerChromeOS(); | 49 virtual ~ExtensionAssetsManagerChromeOS(); |
69 | 50 |
70 // Should be called on UI thread to get associated file task runner for | 51 // Should be called on UI thread to get associated file task runner for |
71 // the profile. | 52 // the profile. |
72 static base::SequencedTaskRunner* GetFileTaskRunner(Profile* profile); | 53 static base::SequencedTaskRunner* GetFileTaskRunner(Profile* profile); |
73 | 54 |
| 55 // Return shared install dir. |
| 56 static base::FilePath GetSharedInstallDir(); |
| 57 |
74 // Return |true| if |extension| can be installed in a shared place for all | 58 // Return |true| if |extension| can be installed in a shared place for all |
75 // users on the device. | 59 // users on the device. |
76 static bool CanShareAssets(const Extension* extension); | 60 static bool CanShareAssets(const Extension* extension); |
77 | 61 |
78 // Called on the UI thread to check if a given version of the |extension| | 62 // Called on the UI thread to check if a given version of the |extension| |
79 // already exists at the shared location. | 63 // already exists at the shared location. |
80 static void CheckSharedExtension( | 64 static void CheckSharedExtension( |
81 const std::string& id, | 65 const std::string& id, |
82 const std::string& version, | 66 const std::string& version, |
83 const base::FilePath& unpacked_extension_root, | 67 const base::FilePath& unpacked_extension_root, |
(...skipping 22 matching lines...) Expand all Loading... |
106 const base::FilePath& local_install_dir, | 90 const base::FilePath& local_install_dir, |
107 InstallExtensionCallback callback); | 91 InstallExtensionCallback callback); |
108 | 92 |
109 // Called on UI thread to mark that shared version is not used. | 93 // Called on UI thread to mark that shared version is not used. |
110 static void MarkSharedExtensionUnused(const std::string& id, | 94 static void MarkSharedExtensionUnused(const std::string& id, |
111 Profile* profile); | 95 Profile* profile); |
112 | 96 |
113 // Called on task runner thread to remove shared version. | 97 // Called on task runner thread to remove shared version. |
114 static void DeleteSharedVersion(const base::FilePath& shared_version_dir); | 98 static void DeleteSharedVersion(const base::FilePath& shared_version_dir); |
115 | 99 |
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); | |
121 | |
122 DISALLOW_COPY_AND_ASSIGN(ExtensionAssetsManagerChromeOS); | 100 DISALLOW_COPY_AND_ASSIGN(ExtensionAssetsManagerChromeOS); |
123 }; | 101 }; |
124 | 102 |
125 } // namespace extensions | 103 } // namespace extensions |
126 | 104 |
127 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_ | 105 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_ |
OLD | NEW |