Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / extensions / extension_assets_manager_chromeos.h
blob01d98be83eabdf517802cf1e24bea142b9e2cab4
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 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;
52 // Return shared install dir.
53 static base::FilePath GetSharedInstallDir();
55 // Return true if |extension| was installed to shared location.
56 static bool IsSharedInstall(const Extension* extension);
58 // Cleans up shared extensions list in preferences and returns list of
59 // extension IDs and version paths that are in use in |live_extension_paths|.
60 // Files on disk are not removed. Must be called on UI thread.
61 // Returns |false| in case of errors.
62 static bool CleanUpSharedExtensions(
63 std::multimap<std::string, base::FilePath>* live_extension_paths);
65 static void SetSharedInstallDirForTesting(const base::FilePath& install_dir);
67 private:
68 friend struct DefaultSingletonTraits<ExtensionAssetsManagerChromeOS>;
70 ExtensionAssetsManagerChromeOS();
71 virtual ~ExtensionAssetsManagerChromeOS();
73 // Should be called on UI thread to get associated file task runner for
74 // the profile.
75 static base::SequencedTaskRunner* GetFileTaskRunner(Profile* profile);
77 // Return |true| if |extension| can be installed in a shared place for all
78 // users on the device.
79 static bool CanShareAssets(const Extension* extension,
80 const base::FilePath& unpacked_extension_root);
82 // Called on the UI thread to check if a given version of the |extension|
83 // already exists at the shared location.
84 static void CheckSharedExtension(
85 const std::string& id,
86 const std::string& version,
87 const base::FilePath& unpacked_extension_root,
88 const base::FilePath& local_install_dir,
89 Profile* profile,
90 InstallExtensionCallback callback);
92 // Called on task runner thread to install extension to shared location.
93 static void InstallSharedExtension(
94 const std::string& id,
95 const std::string& version,
96 const base::FilePath& unpacked_extension_root);
98 // Called on UI thread to process shared install result.
99 static void InstallSharedExtensionDone(
100 const std::string& id,
101 const std::string& version,
102 const base::FilePath& shared_version_dir);
104 // Called on task runner thread to install the extension to local dir call
105 // callback with the result.
106 static void InstallLocalExtension(
107 const std::string& id,
108 const std::string& version,
109 const base::FilePath& unpacked_extension_root,
110 const base::FilePath& local_install_dir,
111 InstallExtensionCallback callback);
113 // Called on UI thread to mark that shared version is not used.
114 static void MarkSharedExtensionUnused(const std::string& id,
115 Profile* profile);
117 // Called on task runner thread to remove shared version.
118 static void DeleteSharedVersion(const base::FilePath& shared_version_dir);
120 // Clean shared extension with given |id|.
121 static bool CleanUpExtension(
122 const std::string& id,
123 base::DictionaryValue* extension_info,
124 std::multimap<std::string, base::FilePath>* live_extension_paths);
126 DISALLOW_COPY_AND_ASSIGN(ExtensionAssetsManagerChromeOS);
129 } // namespace extensions
131 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_