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. 4 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_ 7 8 #include <map> 9 10 #include "chrome/browser/extensions/extension_assets_manager.h" 11 12 template <typename T> struct DefaultSingletonTraits; 13 class PrefRegistrySimple; 14 15 namespace base { 16 class DictionaryValue; 17 class SequencedTaskRunner; 18 } 19 20 namespace extensions { 21 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(); 27 28 // A dictionary that maps shared extension IDs to version/paths/users. 29 static const char kSharedExtensions[]; 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 37 // Register shared assets related preferences. 38 static void RegisterPrefs(PrefRegistrySimple* registry); 39 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, 44 Profile* profile, 45 InstallExtensionCallback callback) OVERRIDE; 46 virtual void UninstallExtension( 47 const std::string& id, 48 Profile* profile, 49 const base::FilePath& local_install_dir, 50 const base::FilePath& extension_root) OVERRIDE; 51 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); 63 64 private: 65 friend struct DefaultSingletonTraits<ExtensionAssetsManagerChromeOS>; 66 67 ExtensionAssetsManagerChromeOS(); 68 virtual ~ExtensionAssetsManagerChromeOS(); 69 70 // Should be called on UI thread to get associated file task runner for 71 // the profile. 72 static base::SequencedTaskRunner* GetFileTaskRunner(Profile* profile); 73 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); 77 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, 85 Profile* profile, 86 InstallExtensionCallback callback); 87 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); 93 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); 99 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); 108 109 // Called on UI thread to mark that shared version is not used. 110 static void MarkSharedExtensionUnused(const std::string& id, 111 Profile* profile); 112 113 // Called on task runner thread to remove shared version. 114 static void DeleteSharedVersion(const base::FilePath& shared_version_dir); 115 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); 123 }; 124 125 } // namespace extensions 126 127 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_ 128