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"
13 template <typename T
> struct DefaultSingletonTraits
;
16 class PrefRegistrySimple
;
19 class DictionaryValue
;
20 class SequencedTaskRunner
;
23 namespace extensions
{
25 // Chrome OS specific implementation of assets manager that shares default apps
26 // between all users on the machine.
27 class ExtensionAssetsManagerChromeOS
: public ExtensionAssetsManager
{
29 static ExtensionAssetsManagerChromeOS
* GetInstance();
31 // A dictionary that maps shared extension IDs to version/paths/users.
32 static const char kSharedExtensions
[];
34 // Name of path attribute in shared extensions map.
35 static const char kSharedExtensionPath
[];
37 // Name of users attribute (list of user emails) in shared extensions map.
38 static const char kSharedExtensionUsers
[];
40 // Register shared assets related preferences.
41 static void RegisterPrefs(PrefRegistrySimple
* registry
);
43 // Override from ExtensionAssetsManager.
44 void InstallExtension(const Extension
* extension
,
45 const base::FilePath
& unpacked_extension_root
,
46 const base::FilePath
& local_install_dir
,
48 InstallExtensionCallback callback
) override
;
49 void UninstallExtension(const std::string
& id
,
51 const base::FilePath
& local_install_dir
,
52 const base::FilePath
& extension_root
) override
;
54 // Return shared install dir.
55 static base::FilePath
GetSharedInstallDir();
57 // Return true if |extension| was installed to shared location.
58 static bool IsSharedInstall(const Extension
* extension
);
60 // Cleans up shared extensions list in preferences and returns list of
61 // extension IDs and version paths that are in use in |live_extension_paths|.
62 // Files on disk are not removed. Must be called on UI thread.
63 // Returns |false| in case of errors.
64 static bool CleanUpSharedExtensions(
65 std::multimap
<std::string
, base::FilePath
>* live_extension_paths
);
67 static void SetSharedInstallDirForTesting(const base::FilePath
& install_dir
);
70 friend struct base::DefaultSingletonTraits
<ExtensionAssetsManagerChromeOS
>;
72 ExtensionAssetsManagerChromeOS();
73 ~ExtensionAssetsManagerChromeOS() override
;
75 // Should be called on UI thread to get associated file task runner for
77 static base::SequencedTaskRunner
* GetFileTaskRunner(Profile
* profile
);
79 // Return |true| if |extension| can be installed in a shared place for all
80 // users on the device.
81 static bool CanShareAssets(const Extension
* extension
,
82 const base::FilePath
& unpacked_extension_root
);
84 // Called on the UI thread to check if a given version of the |extension|
85 // already exists at the shared location.
86 static void CheckSharedExtension(
87 const std::string
& id
,
88 const std::string
& version
,
89 const base::FilePath
& unpacked_extension_root
,
90 const base::FilePath
& local_install_dir
,
92 InstallExtensionCallback callback
);
94 // Called on task runner thread to install extension to shared location.
95 static void InstallSharedExtension(
96 const std::string
& id
,
97 const std::string
& version
,
98 const base::FilePath
& unpacked_extension_root
);
100 // Called on UI thread to process shared install result.
101 static void InstallSharedExtensionDone(
102 const std::string
& id
,
103 const std::string
& version
,
104 const base::FilePath
& shared_version_dir
);
106 // Called on task runner thread to install the extension to local dir call
107 // callback with the result.
108 static void InstallLocalExtension(
109 const std::string
& id
,
110 const std::string
& version
,
111 const base::FilePath
& unpacked_extension_root
,
112 const base::FilePath
& local_install_dir
,
113 InstallExtensionCallback callback
);
115 // Called on UI thread to mark that shared version is not used.
116 static void MarkSharedExtensionUnused(const std::string
& id
,
119 // Called on task runner thread to remove shared version.
120 static void DeleteSharedVersion(const base::FilePath
& shared_version_dir
);
122 // Clean shared extension with given |id|.
123 static bool CleanUpExtension(
124 const std::string
& id
,
125 base::DictionaryValue
* extension_info
,
126 std::multimap
<std::string
, base::FilePath
>* live_extension_paths
);
128 DISALLOW_COPY_AND_ASSIGN(ExtensionAssetsManagerChromeOS
);
131 } // namespace extensions
133 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_