Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_assets_manager_chromeos.h
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   // Return true if |extension| was installed to shared location.
56   static bool IsSharedInstall(const Extension* extension);
57
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);
64
65   static void SetSharedInstallDirForTesting(const base::FilePath& install_dir);
66
67  private:
68   friend struct DefaultSingletonTraits<ExtensionAssetsManagerChromeOS>;
69
70   ExtensionAssetsManagerChromeOS();
71   virtual ~ExtensionAssetsManagerChromeOS();
72
73   // Should be called on UI thread to get associated file task runner for
74   // the profile.
75   static base::SequencedTaskRunner* GetFileTaskRunner(Profile* profile);
76
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);
81
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);
91
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);
97
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);
103
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);
112
113   // Called on UI thread to mark that shared version is not used.
114   static void MarkSharedExtensionUnused(const std::string& id,
115                                         Profile* profile);
116
117   // Called on task runner thread to remove shared version.
118   static void DeleteSharedVersion(const base::FilePath& shared_version_dir);
119
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);
125
126   DISALLOW_COPY_AND_ASSIGN(ExtensionAssetsManagerChromeOS);
127 };
128
129 }  // namespace extensions
130
131 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_ASSETS_MANAGER_CHROMEOS_H_