OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EXTENSION_UPDATER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_UPDATER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UPDATER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UPDATER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <stack> | 12 #include <stack> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
21 #include "base/scoped_temp_dir.h" | 21 #include "base/scoped_temp_dir.h" |
22 #include "base/time.h" | 22 #include "base/time.h" |
23 #include "base/timer.h" | 23 #include "base/timer.h" |
24 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
25 #include "chrome/common/extensions/update_manifest.h" | 25 #include "chrome/common/extensions/update_manifest.h" |
26 #include "content/common/net/url_fetcher.h" | 26 #include "content/public/common/url_fetcher_delegate.h" |
27 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
28 | 28 |
29 class Extension; | 29 class Extension; |
30 class ExtensionPrefs; | 30 class ExtensionPrefs; |
31 class ExtensionUpdaterTest; | 31 class ExtensionUpdaterTest; |
32 class PrefService; | 32 class PrefService; |
33 class Profile; | 33 class Profile; |
34 class SafeManifestParser; | 34 class SafeManifestParser; |
35 | 35 |
| 36 namespace net { |
| 37 class URLRequestStatus; |
| 38 } |
| 39 |
36 // To save on server resources we can request updates for multiple extensions | 40 // To save on server resources we can request updates for multiple extensions |
37 // in one manifest check. This class helps us keep track of the id's for a | 41 // in one manifest check. This class helps us keep track of the id's for a |
38 // given fetch, building up the actual URL, and what if anything to include | 42 // given fetch, building up the actual URL, and what if anything to include |
39 // in the ping parameter. | 43 // in the ping parameter. |
40 class ManifestFetchData { | 44 class ManifestFetchData { |
41 public: | 45 public: |
42 static const int kNeverPinged = -1; | 46 static const int kNeverPinged = -1; |
43 | 47 |
44 // Each ping type is sent at most once per day. | 48 // Each ping type is sent at most once per day. |
45 enum PingType { | 49 enum PingType { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 }; | 162 }; |
159 | 163 |
160 // A class for doing auto-updates of installed Extensions. Used like this: | 164 // A class for doing auto-updates of installed Extensions. Used like this: |
161 // | 165 // |
162 // ExtensionUpdater* updater = new ExtensionUpdater(my_extensions_service, | 166 // ExtensionUpdater* updater = new ExtensionUpdater(my_extensions_service, |
163 // pref_service, | 167 // pref_service, |
164 // update_frequency_secs); | 168 // update_frequency_secs); |
165 // updater->Start(); | 169 // updater->Start(); |
166 // .... | 170 // .... |
167 // updater->Stop(); | 171 // updater->Stop(); |
168 class ExtensionUpdater : public URLFetcher::Delegate, | 172 class ExtensionUpdater : public content::URLFetcherDelegate, |
169 public content::NotificationObserver { | 173 public content::NotificationObserver { |
170 public: | 174 public: |
171 // Holds a pointer to the passed |service|, using it for querying installed | 175 // Holds a pointer to the passed |service|, using it for querying installed |
172 // extensions and installing updated ones. The |frequency_seconds| parameter | 176 // extensions and installing updated ones. The |frequency_seconds| parameter |
173 // controls how often update checks are scheduled. | 177 // controls how often update checks are scheduled. |
174 ExtensionUpdater(ExtensionServiceInterface* service, | 178 ExtensionUpdater(ExtensionServiceInterface* service, |
175 ExtensionPrefs* extension_prefs, | 179 ExtensionPrefs* extension_prefs, |
176 PrefService* prefs, | 180 PrefService* prefs, |
177 Profile* profile, | 181 Profile* profile, |
178 int frequency_seconds); | 182 int frequency_seconds); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 static const int kExtensionFetcherId = 2; | 247 static const int kExtensionFetcherId = 2; |
244 | 248 |
245 static const char* kBlacklistAppID; | 249 static const char* kBlacklistAppID; |
246 | 250 |
247 // Does common work from constructors. | 251 // Does common work from constructors. |
248 void Init(); | 252 void Init(); |
249 | 253 |
250 // Computes when to schedule the first update check. | 254 // Computes when to schedule the first update check. |
251 base::TimeDelta DetermineFirstCheckDelay(); | 255 base::TimeDelta DetermineFirstCheckDelay(); |
252 | 256 |
253 // URLFetcher::Delegate interface. | 257 // content::URLFetcherDelegate interface. |
254 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 258 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
255 | 259 |
256 // These do the actual work when a URL fetch completes. | 260 // These do the actual work when a URL fetch completes. |
257 virtual void OnManifestFetchComplete(const GURL& url, | 261 virtual void OnManifestFetchComplete(const GURL& url, |
258 const net::URLRequestStatus& status, | 262 const net::URLRequestStatus& status, |
259 int response_code, | 263 int response_code, |
260 const std::string& data); | 264 const std::string& data); |
261 | 265 |
262 virtual void OnCRXFetchComplete(const URLFetcher* source, | 266 virtual void OnCRXFetchComplete(const URLFetcher* source, |
263 const GURL& url, | 267 const GURL& url, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 // Fetched CRX files waiting to be installed. | 386 // Fetched CRX files waiting to be installed. |
383 std::stack<FetchedCRXFile> fetched_crx_files_; | 387 std::stack<FetchedCRXFile> fetched_crx_files_; |
384 | 388 |
385 FRIEND_TEST(ExtensionUpdaterTest, TestStartUpdateCheckMemory); | 389 FRIEND_TEST(ExtensionUpdaterTest, TestStartUpdateCheckMemory); |
386 FRIEND_TEST(ExtensionUpdaterTest, TestAfterStopBehavior); | 390 FRIEND_TEST(ExtensionUpdaterTest, TestAfterStopBehavior); |
387 | 391 |
388 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater); | 392 DISALLOW_COPY_AND_ASSIGN(ExtensionUpdater); |
389 }; | 393 }; |
390 | 394 |
391 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UPDATER_H_ | 395 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UPDATER_H_ |
OLD | NEW |