OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const GURL& download_url, | 96 const GURL& download_url, |
97 const std::string& version, | 97 const std::string& version, |
98 const PingResult& ping_result, | 98 const PingResult& ping_result, |
99 const std::set<int>& request_ids) OVERRIDE; | 99 const std::set<int>& request_ids) OVERRIDE; |
100 | 100 |
101 virtual bool IsExtensionPending(const std::string& id) OVERRIDE; | 101 virtual bool IsExtensionPending(const std::string& id) OVERRIDE; |
102 | 102 |
103 virtual bool GetExtensionExistingVersion(const std::string& id, | 103 virtual bool GetExtensionExistingVersion(const std::string& id, |
104 std::string* version) OVERRIDE; | 104 std::string* version) OVERRIDE; |
105 | 105 |
| 106 // Returns true if the extension with |id| is pending for update check. |
| 107 bool IsExtensionPendingForUpdateCheck(const std::string& id); |
| 108 |
| 109 // Returns true if the extension with |id| failed for download. |
| 110 bool IsExtensionDownloadFailed(const std::string& id); |
| 111 |
106 // Shut down the cache. The |callback| will be invoked when the cache has shut | 112 // Shut down the cache. The |callback| will be invoked when the cache has shut |
107 // down completely and there are no more pending file I/O operations. | 113 // down completely and there are no more pending file I/O operations. |
108 void Shutdown(const base::Closure& callback); | 114 void Shutdown(const base::Closure& callback); |
109 | 115 |
110 // Replace the list of extensions to cache with |prefs| and perform update | 116 // Replace the list of extensions to cache with |prefs| and perform update |
111 // checks for these. | 117 // checks for these. |
112 void UpdateExtensionsList(scoped_ptr<base::DictionaryValue> prefs); | 118 void UpdateExtensionsList(scoped_ptr<base::DictionaryValue> prefs); |
113 | 119 |
114 // If a user of one of the ExternalCache's extensions detects that | 120 // If a user of one of the ExternalCache's extensions detects that |
115 // the extension is damaged then this method can be used to remove it from | 121 // the extension is damaged then this method can be used to remove it from |
116 // the cache and retry to download it after a restart. | 122 // the cache and retry to download it after a restart. |
117 void OnDamagedFileDetected(const base::FilePath& path); | 123 void OnDamagedFileDetected(const base::FilePath& path); |
118 | 124 |
119 // Removes extensions listed in |ids| from external cache, corresponding crx | 125 // Removes extensions listed in |ids| from external cache, corresponding crx |
120 // files will be removed from disk too. | 126 // files will be removed from disk too. |
121 void RemoveExtensions(const std::vector<std::string>& ids); | 127 void RemoveExtensions(const std::vector<std::string>& ids); |
122 | 128 |
123 // If extension with |id| exists in the cache, returns |true|, |file_path| and | 129 // If extension with |id| exists in the cache, returns |true|, |file_path| and |
124 // |version| for the extension. Extension will be marked as used with current | 130 // |version| for the extension. Extension will be marked as used with current |
125 // timestamp. | 131 // timestamp. |
126 bool GetExtension(const std::string& id, | 132 bool GetExtension(const std::string& id, |
127 base::FilePath* file_path, | 133 base::FilePath* file_path, |
128 std::string* version); | 134 std::string* version); |
129 | 135 |
130 private: | 136 private: |
| 137 enum ExtensionStatus { |
| 138 DOWNLOAD_PENDING, |
| 139 DOWNLOAD_SUCCEEDED, |
| 140 DOWNLOAD_FAILED, |
| 141 }; |
| 142 |
131 // Notifies the that the cache has been updated, providing | 143 // Notifies the that the cache has been updated, providing |
132 // extensions loader with an updated list of extensions. | 144 // extensions loader with an updated list of extensions. |
133 void UpdateExtensionLoader(); | 145 void UpdateExtensionLoader(); |
134 | 146 |
135 // Checks the cache contents and initiate download if needed. | 147 // Checks the cache contents and initiate download if needed. |
136 void CheckCache(); | 148 void CheckCache(); |
137 | 149 |
138 // Invoked on the UI thread when a new entry has been installed in the cache. | 150 // Invoked on the UI thread when a new entry has been installed in the cache. |
139 void OnPutExtension(const std::string& id, | 151 void OnPutExtension(const std::string& id, |
140 const base::FilePath& file_path, | 152 const base::FilePath& file_path, |
(...skipping 16 matching lines...) Expand all Loading... |
157 // Set to true if cache should wait for initialization flag file. | 169 // Set to true if cache should wait for initialization flag file. |
158 bool wait_for_cache_initialization_; | 170 bool wait_for_cache_initialization_; |
159 | 171 |
160 // This is the list of extensions currently configured. | 172 // This is the list of extensions currently configured. |
161 scoped_ptr<base::DictionaryValue> extensions_; | 173 scoped_ptr<base::DictionaryValue> extensions_; |
162 | 174 |
163 // This contains extensions that are both currently configured | 175 // This contains extensions that are both currently configured |
164 // and that have a valid crx in the cache. | 176 // and that have a valid crx in the cache. |
165 scoped_ptr<base::DictionaryValue> cached_extensions_; | 177 scoped_ptr<base::DictionaryValue> cached_extensions_; |
166 | 178 |
| 179 // <extension_id : status>: used for tracking extension download status. |
| 180 std::map<std::string, ExtensionStatus> extensions_status_; |
| 181 |
167 // Used to download the extensions and to check for updates. | 182 // Used to download the extensions and to check for updates. |
168 scoped_ptr<extensions::ExtensionDownloader> downloader_; | 183 scoped_ptr<extensions::ExtensionDownloader> downloader_; |
169 | 184 |
170 // Observes failures to install CRX files. | 185 // Observes failures to install CRX files. |
171 content::NotificationRegistrar notification_registrar_; | 186 content::NotificationRegistrar notification_registrar_; |
172 | 187 |
173 // Weak factory for callbacks. | 188 // Weak factory for callbacks. |
174 base::WeakPtrFactory<ExternalCache> weak_ptr_factory_; | 189 base::WeakPtrFactory<ExternalCache> weak_ptr_factory_; |
175 | 190 |
176 DISALLOW_COPY_AND_ASSIGN(ExternalCache); | 191 DISALLOW_COPY_AND_ASSIGN(ExternalCache); |
177 }; | 192 }; |
178 | 193 |
179 } // namespace chromeos | 194 } // namespace chromeos |
180 | 195 |
181 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ | 196 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ |
OLD | NEW |