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_DOWNLOADER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <map> | 10 #include <map> |
11 #include <set> | |
12 #include <string> | 11 #include <string> |
13 #include <vector> | 12 #include <vector> |
14 | 13 |
15 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
16 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
17 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
19 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" | 18 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" |
20 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" | 19 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" |
21 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
(...skipping 26 matching lines...) Expand all Loading... |
48 virtual ~ExtensionDownloader(); | 47 virtual ~ExtensionDownloader(); |
49 | 48 |
50 // Adds |extension| to the list of extensions to check for updates. | 49 // Adds |extension| to the list of extensions to check for updates. |
51 // Returns false if the |extension| can't be updated due to invalid details. | 50 // Returns false if the |extension| can't be updated due to invalid details. |
52 // In that case, no callbacks will be performed on the |delegate_|. | 51 // In that case, no callbacks will be performed on the |delegate_|. |
53 bool AddExtension(const Extension& extension); | 52 bool AddExtension(const Extension& extension); |
54 | 53 |
55 // Adds extension |id| to the list of extensions to check for updates. | 54 // Adds extension |id| to the list of extensions to check for updates. |
56 // Returns false if the |id| can't be updated due to invalid details. | 55 // Returns false if the |id| can't be updated due to invalid details. |
57 // In that case, no callbacks will be performed on the |delegate_|. | 56 // In that case, no callbacks will be performed on the |delegate_|. |
58 bool AddPendingExtension(const std::string& id, const GURL& update_url); | 57 bool AddPendingExtension(const std::string& id, const GURL& update_url, |
| 58 bool is_sync); |
59 | 59 |
60 // Schedules a fetch of the manifest of all the extensions added with | 60 // Schedules a fetch of the manifest of all the extensions added with |
61 // AddExtension() and AddPendingExtension(). | 61 // AddExtension() and AddPendingExtension(). |
62 void StartAllPending(); | 62 void StartAllPending(); |
63 | 63 |
64 // Schedules an update check of the blacklist. | 64 // Schedules an update check of the blacklist. |
65 void StartBlacklistUpdate(const std::string& version, | 65 void StartBlacklistUpdate(const std::string& version, |
66 const ManifestFetchData::PingData& ping_data); | 66 const ManifestFetchData::PingData& ping_data); |
67 | 67 |
68 // These are needed for unit testing, to help identify the correct mock | 68 // These are needed for unit testing, to help identify the correct mock |
(...skipping 21 matching lines...) Expand all Loading... |
90 | 90 |
91 int no_url_count, google_url_count, other_url_count; | 91 int no_url_count, google_url_count, other_url_count; |
92 int extension_count, theme_count, app_count, pending_count; | 92 int extension_count, theme_count, app_count, pending_count; |
93 }; | 93 }; |
94 | 94 |
95 // We need to keep track of some information associated with a url | 95 // We need to keep track of some information associated with a url |
96 // when doing a fetch. | 96 // when doing a fetch. |
97 struct ExtensionFetch { | 97 struct ExtensionFetch { |
98 ExtensionFetch(); | 98 ExtensionFetch(); |
99 ExtensionFetch(const std::string& id, const GURL& url, | 99 ExtensionFetch(const std::string& id, const GURL& url, |
100 const std::string& package_hash, const std::string& version); | 100 const std::string& package_hash, const std::string& version, |
| 101 const bool is_sync); |
101 ~ExtensionFetch(); | 102 ~ExtensionFetch(); |
102 | 103 |
103 std::string id; | 104 std::string id; |
104 GURL url; | 105 GURL url; |
105 std::string package_hash; | 106 std::string package_hash; |
106 std::string version; | 107 std::string version; |
| 108 bool is_sync; |
107 }; | 109 }; |
108 | 110 |
109 // Helper for AddExtension() and AddPendingExtension(). | 111 // Helper for AddExtension() and AddPendingExtension(). |
110 bool AddExtensionData(const std::string& id, | 112 bool AddExtensionData(const std::string& id, |
111 const Version& version, | 113 const Version& version, |
112 Extension::Type extension_type, | 114 Extension::Type extension_type, |
113 GURL update_url, | 115 GURL update_url, |
114 const std::string& update_url_data); | 116 const std::string& update_url_data, |
| 117 bool is_sync); |
115 | 118 |
116 // Adds all recorded stats taken so far to histogram counts. | 119 // Adds all recorded stats taken so far to histogram counts. |
117 void ReportStats() const; | 120 void ReportStats() const; |
118 | 121 |
119 // Begins an update check. Takes ownership of |fetch_data|. | 122 // Begins an update check. Takes ownership of |fetch_data|. |
120 void StartUpdateCheck(ManifestFetchData* fetch_data); | 123 void StartUpdateCheck(ManifestFetchData* fetch_data); |
121 | 124 |
122 // net::URLFetcherDelegate implementation. | 125 // net::URLFetcherDelegate implementation. |
123 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 126 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
124 | 127 |
(...skipping 11 matching lines...) Expand all Loading... |
136 // Given a list of potential updates, returns the indices of the ones that are | 139 // Given a list of potential updates, returns the indices of the ones that are |
137 // applicable (are actually a new version, etc.) in |result|. | 140 // applicable (are actually a new version, etc.) in |result|. |
138 void DetermineUpdates(const ManifestFetchData& fetch_data, | 141 void DetermineUpdates(const ManifestFetchData& fetch_data, |
139 const UpdateManifest::Results& possible_updates, | 142 const UpdateManifest::Results& possible_updates, |
140 std::vector<int>* result); | 143 std::vector<int>* result); |
141 | 144 |
142 // Begins (or queues up) download of an updated extension. | 145 // Begins (or queues up) download of an updated extension. |
143 void FetchUpdatedExtension(const std::string& id, | 146 void FetchUpdatedExtension(const std::string& id, |
144 const GURL& url, | 147 const GURL& url, |
145 const std::string& hash, | 148 const std::string& hash, |
146 const std::string& version); | 149 const std::string& version, |
| 150 const bool is_sync); |
147 | 151 |
148 // Handles the result of a crx fetch. | 152 // Handles the result of a crx fetch. |
149 void OnCRXFetchComplete(const net::URLFetcher* source, | 153 void OnCRXFetchComplete(const net::URLFetcher* source, |
150 const GURL& url, | 154 const GURL& url, |
151 const net::URLRequestStatus& status, | 155 const net::URLRequestStatus& status, |
152 int response_code); | 156 int response_code); |
153 | 157 |
154 // Invokes OnExtensionDownloadFailed() on the |delegate_| for each extension | 158 // Invokes OnExtensionDownloadFailed() on the |delegate_| for each extension |
155 // in the set, with |error| as the reason for failure. | 159 // in the mamapwith |error| as the reason for failure. |
156 void NotifyExtensionsDownloadFailed(const std::set<std::string>& id_set, | 160 void NotifyExtensionsDownloadFailed( |
157 ExtensionDownloaderDelegate::Error error); | 161 const ManifestFetchData::ExtensionInfoMap& id_map, |
| 162 ExtensionDownloaderDelegate::Error error); |
158 | 163 |
159 // Send a notification that an update was found for |id| that we'll | 164 // Send a notification that an update was found for |id| that we'll |
160 // attempt to download. | 165 // attempt to download. |
161 void NotifyUpdateFound(const std::string& id); | 166 void NotifyUpdateFound(const std::string& id); |
162 | 167 |
163 // The delegate that receives the crx files downloaded by the | 168 // The delegate that receives the crx files downloaded by the |
164 // ExtensionDownloader, and that fills in optional ping and update url data. | 169 // ExtensionDownloader, and that fills in optional ping and update url data. |
165 ExtensionDownloaderDelegate* delegate_; | 170 ExtensionDownloaderDelegate* delegate_; |
166 | 171 |
167 // The request context to use for the URLFetchers. | 172 // The request context to use for the URLFetchers. |
(...skipping 29 matching lines...) Expand all Loading... |
197 | 202 |
198 // Maps an extension-id to its PingResult data. | 203 // Maps an extension-id to its PingResult data. |
199 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; | 204 std::map<std::string, ExtensionDownloaderDelegate::PingResult> ping_results_; |
200 | 205 |
201 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); | 206 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloader); |
202 }; | 207 }; |
203 | 208 |
204 } // namespace extensions | 209 } // namespace extensions |
205 | 210 |
206 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ | 211 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_H_ |
OLD | NEW |