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 20 matching lines...) Expand all Loading... |
31 namespace net { | 31 namespace net { |
32 class URLRequestContextGetter; | 32 class URLRequestContextGetter; |
33 } | 33 } |
34 | 34 |
35 namespace chromeos { | 35 namespace chromeos { |
36 | 36 |
37 // The ExternalCache manages a cache for external extensions. | 37 // The ExternalCache manages a cache for external extensions. |
38 class ExternalCache : public content::NotificationObserver, | 38 class ExternalCache : public content::NotificationObserver, |
39 public extensions::ExtensionDownloaderDelegate { | 39 public extensions::ExtensionDownloaderDelegate { |
40 public: | 40 public: |
| 41 typedef base::Callback<void(const std::string& id, bool success)> |
| 42 PutExternalExtensionCallback; |
| 43 |
41 class Delegate { | 44 class Delegate { |
42 public: | 45 public: |
43 virtual ~Delegate() {} | 46 virtual ~Delegate() {} |
44 // Caller owns |prefs|. | 47 // Caller owns |prefs|. |
45 virtual void OnExtensionListsUpdated( | 48 virtual void OnExtensionListsUpdated( |
46 const base::DictionaryValue* prefs) = 0; | 49 const base::DictionaryValue* prefs) = 0; |
47 // Called after extension with |id| is loaded in cache. | 50 // Called after extension with |id| is loaded in cache. |
48 virtual void OnExtensionLoadedInCache(const std::string& id) {} | 51 virtual void OnExtensionLoadedInCache(const std::string& id) {} |
49 // Called when extension with |id| is failed with downloading for |error|. | 52 // Called when extension with |id| is failed with downloading for |error|. |
50 virtual void OnExtensionDownloadFailed( | 53 virtual void OnExtensionDownloadFailed( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // files will be removed from disk too. | 123 // files will be removed from disk too. |
121 void RemoveExtensions(const std::vector<std::string>& ids); | 124 void RemoveExtensions(const std::vector<std::string>& ids); |
122 | 125 |
123 // If extension with |id| exists in the cache, returns |true|, |file_path| and | 126 // 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 | 127 // |version| for the extension. Extension will be marked as used with current |
125 // timestamp. | 128 // timestamp. |
126 bool GetExtension(const std::string& id, | 129 bool GetExtension(const std::string& id, |
127 base::FilePath* file_path, | 130 base::FilePath* file_path, |
128 std::string* version); | 131 std::string* version); |
129 | 132 |
| 133 // Puts the external |crx_file_path| into |local_cache_| for extension with |
| 134 // |id|. |
| 135 void PutExternalExtension(const std::string& id, |
| 136 const base::FilePath& crx_file_path, |
| 137 const std::string& version, |
| 138 const PutExternalExtensionCallback& callback); |
| 139 |
130 private: | 140 private: |
131 // Notifies the that the cache has been updated, providing | 141 // Notifies the that the cache has been updated, providing |
132 // extensions loader with an updated list of extensions. | 142 // extensions loader with an updated list of extensions. |
133 void UpdateExtensionLoader(); | 143 void UpdateExtensionLoader(); |
134 | 144 |
135 // Checks the cache contents and initiate download if needed. | 145 // Checks the cache contents and initiate download if needed. |
136 void CheckCache(); | 146 void CheckCache(); |
137 | 147 |
138 // Invoked on the UI thread when a new entry has been installed in the cache. | 148 // Invoked on the UI thread when a new entry has been installed in the cache. |
139 void OnPutExtension(const std::string& id, | 149 void OnPutExtension(const std::string& id, |
140 const base::FilePath& file_path, | 150 const base::FilePath& file_path, |
141 bool file_ownership_passed); | 151 bool file_ownership_passed); |
142 | 152 |
| 153 // Invoked on the UI thread when the external extension has been installed |
| 154 // in the local cache by calling PutExternalExtension. |
| 155 void OnPutExternalExtension(const std::string& id, |
| 156 const PutExternalExtensionCallback& callback, |
| 157 const base::FilePath& file_path, |
| 158 bool file_ownership_passed); |
| 159 |
143 extensions::LocalExtensionCache local_cache_; | 160 extensions::LocalExtensionCache local_cache_; |
144 | 161 |
145 // Request context used by the |downloader_|. | 162 // Request context used by the |downloader_|. |
146 scoped_refptr<net::URLRequestContextGetter> request_context_; | 163 scoped_refptr<net::URLRequestContextGetter> request_context_; |
147 | 164 |
148 // Task runner for executing file I/O tasks. | 165 // Task runner for executing file I/O tasks. |
149 const scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; | 166 const scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; |
150 | 167 |
151 // Delegate that would like to get notifications about cache updates. | 168 // Delegate that would like to get notifications about cache updates. |
152 Delegate* delegate_; | 169 Delegate* delegate_; |
(...skipping 19 matching lines...) Expand all Loading... |
172 | 189 |
173 // Weak factory for callbacks. | 190 // Weak factory for callbacks. |
174 base::WeakPtrFactory<ExternalCache> weak_ptr_factory_; | 191 base::WeakPtrFactory<ExternalCache> weak_ptr_factory_; |
175 | 192 |
176 DISALLOW_COPY_AND_ASSIGN(ExternalCache); | 193 DISALLOW_COPY_AND_ASSIGN(ExternalCache); |
177 }; | 194 }; |
178 | 195 |
179 } // namespace chromeos | 196 } // namespace chromeos |
180 | 197 |
181 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ | 198 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ |
OLD | NEW |