| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 class ExtensionServiceInterface; | 28 class ExtensionServiceInterface; |
| 29 class ExtensionSet; | 29 class ExtensionSet; |
| 30 class PrefService; | 30 class PrefService; |
| 31 class Profile; | 31 class Profile; |
| 32 | 32 |
| 33 namespace extensions { | 33 namespace extensions { |
| 34 | 34 |
| 35 class Blacklist; | |
| 36 class ExtensionDownloader; | 35 class ExtensionDownloader; |
| 37 class ExtensionPrefs; | 36 class ExtensionPrefs; |
| 38 class ExtensionUpdaterTest; | 37 class ExtensionUpdaterTest; |
| 39 | 38 |
| 40 // A class for doing auto-updates of installed Extensions. Used like this: | 39 // A class for doing auto-updates of installed Extensions. Used like this: |
| 41 // | 40 // |
| 42 // ExtensionUpdater* updater = new ExtensionUpdater(my_extensions_service, | 41 // ExtensionUpdater* updater = new ExtensionUpdater(my_extensions_service, |
| 43 // extension_prefs, | 42 // extension_prefs, |
| 44 // pref_service, | 43 // pref_service, |
| 45 // profile, | 44 // profile, |
| 46 // update_frequency_secs); | 45 // update_frequency_secs); |
| 47 // updater->Start(); | 46 // updater->Start(); |
| 48 // .... | 47 // .... |
| 49 // updater->Stop(); | 48 // updater->Stop(); |
| 50 class ExtensionUpdater : public ExtensionDownloaderDelegate, | 49 class ExtensionUpdater : public ExtensionDownloaderDelegate, |
| 51 public content::NotificationObserver { | 50 public content::NotificationObserver { |
| 52 public: | 51 public: |
| 53 typedef base::Closure FinishedCallback; | 52 typedef base::Closure FinishedCallback; |
| 54 | 53 |
| 55 struct CheckParams { | 54 struct CheckParams { |
| 56 // Creates a default CheckParams instance that checks for all extensions and | 55 // Creates a default CheckParams instance that checks for all extensions. |
| 57 // the extension blacklist. | |
| 58 CheckParams(); | 56 CheckParams(); |
| 59 ~CheckParams(); | 57 ~CheckParams(); |
| 60 | 58 |
| 61 // The set of extensions that should be checked for updates. If empty | 59 // The set of extensions that should be checked for updates. If empty |
| 62 // all extensions will be included in the update check. | 60 // all extensions will be included in the update check. |
| 63 std::list<std::string> ids; | 61 std::list<std::string> ids; |
| 64 | 62 |
| 65 // If true, the extension blacklist will also be updated. | |
| 66 bool check_blacklist; | |
| 67 | |
| 68 // Normally extension updates get installed only when the extension is idle. | 63 // Normally extension updates get installed only when the extension is idle. |
| 69 // Setting this to true causes any updates that are found to be installed | 64 // Setting this to true causes any updates that are found to be installed |
| 70 // right away. | 65 // right away. |
| 71 bool install_immediately; | 66 bool install_immediately; |
| 72 | 67 |
| 73 // Callback to call when the update check is complete. Can be null, if | 68 // Callback to call when the update check is complete. Can be null, if |
| 74 // you're not interested in when this happens. | 69 // you're not interested in when this happens. |
| 75 FinishedCallback callback; | 70 FinishedCallback callback; |
| 76 }; | 71 }; |
| 77 | 72 |
| 78 // Holds a pointer to the passed |service|, using it for querying installed | 73 // Holds a pointer to the passed |service|, using it for querying installed |
| 79 // extensions and installing updated ones. The |frequency_seconds| parameter | 74 // extensions and installing updated ones. The |frequency_seconds| parameter |
| 80 // controls how often update checks are scheduled. | 75 // controls how often update checks are scheduled. |
| 81 ExtensionUpdater(ExtensionServiceInterface* service, | 76 ExtensionUpdater(ExtensionServiceInterface* service, |
| 82 ExtensionPrefs* extension_prefs, | 77 ExtensionPrefs* extension_prefs, |
| 83 PrefService* prefs, | 78 PrefService* prefs, |
| 84 Profile* profile, | 79 Profile* profile, |
| 85 Blacklist* blacklist, | |
| 86 int frequency_seconds); | 80 int frequency_seconds); |
| 87 | 81 |
| 88 virtual ~ExtensionUpdater(); | 82 virtual ~ExtensionUpdater(); |
| 89 | 83 |
| 90 // Starts the updater running. Should be called at most once. | 84 // Starts the updater running. Should be called at most once. |
| 91 void Start(); | 85 void Start(); |
| 92 | 86 |
| 93 // Stops the updater running, cancelling any outstanding update manifest and | 87 // Stops the updater running, cancelling any outstanding update manifest and |
| 94 // crx downloads. Does not cancel any in-progress installs. | 88 // crx downloads. Does not cancel any in-progress installs. |
| 95 void Stop(); | 89 void Stop(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 const std::set<int>& request_ids) OVERRIDE; | 174 const std::set<int>& request_ids) OVERRIDE; |
| 181 | 175 |
| 182 virtual void OnExtensionDownloadFinished( | 176 virtual void OnExtensionDownloadFinished( |
| 183 const std::string& id, | 177 const std::string& id, |
| 184 const base::FilePath& path, | 178 const base::FilePath& path, |
| 185 const GURL& download_url, | 179 const GURL& download_url, |
| 186 const std::string& version, | 180 const std::string& version, |
| 187 const PingResult& ping, | 181 const PingResult& ping, |
| 188 const std::set<int>& request_id) OVERRIDE; | 182 const std::set<int>& request_id) OVERRIDE; |
| 189 | 183 |
| 190 virtual void OnBlacklistDownloadFinished( | |
| 191 const std::string& data, | |
| 192 const std::string& package_hash, | |
| 193 const std::string& version, | |
| 194 const PingResult& ping, | |
| 195 const std::set<int>& request_id) OVERRIDE; | |
| 196 | |
| 197 virtual bool GetPingDataForExtension( | 184 virtual bool GetPingDataForExtension( |
| 198 const std::string& id, | 185 const std::string& id, |
| 199 ManifestFetchData::PingData* ping_data) OVERRIDE; | 186 ManifestFetchData::PingData* ping_data) OVERRIDE; |
| 200 | 187 |
| 201 virtual std::string GetUpdateUrlData(const std::string& id) OVERRIDE; | 188 virtual std::string GetUpdateUrlData(const std::string& id) OVERRIDE; |
| 202 | 189 |
| 203 virtual bool IsExtensionPending(const std::string& id) OVERRIDE; | 190 virtual bool IsExtensionPending(const std::string& id) OVERRIDE; |
| 204 | 191 |
| 205 virtual bool GetExtensionExistingVersion(const std::string& id, | 192 virtual bool GetExtensionExistingVersion(const std::string& id, |
| 206 std::string* version) OVERRIDE; | 193 std::string* version) OVERRIDE; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 235 // Fetches the crx files for the extensions that have an available update. | 222 // Fetches the crx files for the extensions that have an available update. |
| 236 scoped_ptr<ExtensionDownloader> downloader_; | 223 scoped_ptr<ExtensionDownloader> downloader_; |
| 237 | 224 |
| 238 base::OneShotTimer<ExtensionUpdater> timer_; | 225 base::OneShotTimer<ExtensionUpdater> timer_; |
| 239 int frequency_seconds_; | 226 int frequency_seconds_; |
| 240 bool will_check_soon_; | 227 bool will_check_soon_; |
| 241 | 228 |
| 242 ExtensionPrefs* extension_prefs_; | 229 ExtensionPrefs* extension_prefs_; |
| 243 PrefService* prefs_; | 230 PrefService* prefs_; |
| 244 Profile* profile_; | 231 Profile* profile_; |
| 245 Blacklist* blacklist_; | |
| 246 | 232 |
| 247 std::map<int, InProgressCheck> requests_in_progress_; | 233 std::map<int, InProgressCheck> requests_in_progress_; |
| 248 int next_request_id_; | 234 int next_request_id_; |
| 249 | 235 |
| 250 // Observes CRX installs we initiate. | 236 // Observes CRX installs we initiate. |
| 251 content::NotificationRegistrar registrar_; | 237 content::NotificationRegistrar registrar_; |
| 252 | 238 |
| 253 // True when a CrxInstaller is doing an install. Used in MaybeUpdateCrxFile() | 239 // True when a CrxInstaller is doing an install. Used in MaybeUpdateCrxFile() |
| 254 // to keep more than one install from running at once. | 240 // to keep more than one install from running at once. |
| 255 bool crx_install_is_running_; | 241 bool crx_install_is_running_; |
| 256 | 242 |
| 257 // Fetched CRX files waiting to be installed. | 243 // Fetched CRX files waiting to be installed. |
| 258 std::stack<FetchedCRXFile> fetched_crx_files_; | 244 std::stack<FetchedCRXFile> fetched_crx_files_; |
| 259 FetchedCRXFile current_crx_file_; | 245 FetchedCRXFile current_crx_file_; |
| 260 | 246 |
| 261 CheckParams default_params_; | 247 CheckParams default_params_; |
| 262 | 248 |
| 263 // Keeps track of when an extension tried to update itself, so we can throttle | 249 // Keeps track of when an extension tried to update itself, so we can throttle |
| 264 // checks to prevent too many requests from being made. | 250 // checks to prevent too many requests from being made. |
| 265 std::map<std::string, ThrottleInfo> throttle_info_; | 251 std::map<std::string, ThrottleInfo> throttle_info_; |
| 266 | 252 |
| 267 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater); | 253 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater); |
| 268 }; | 254 }; |
| 269 | 255 |
| 270 } // namespace extensions | 256 } // namespace extensions |
| 271 | 257 |
| 272 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ | 258 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_UPDATER_H_ |
| OLD | NEW |