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 #include "chrome/browser/chromeos/extensions/external_cache.h" | 5 #include "chrome/browser/chromeos/extensions/external_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 ExternalCache::~ExternalCache() { | 51 ExternalCache::~ExternalCache() { |
52 } | 52 } |
53 | 53 |
54 void ExternalCache::Shutdown(const base::Closure& callback) { | 54 void ExternalCache::Shutdown(const base::Closure& callback) { |
55 local_cache_.Shutdown(callback); | 55 local_cache_.Shutdown(callback); |
56 } | 56 } |
57 | 57 |
58 void ExternalCache::UpdateExtensionsList( | 58 void ExternalCache::UpdateExtensionsList( |
59 scoped_ptr<base::DictionaryValue> prefs) { | 59 scoped_ptr<base::DictionaryValue> prefs) { |
60 extensions_ = prefs.Pass(); | 60 extensions_ = prefs.Pass(); |
61 extensions_status_.clear(); | |
61 | 62 |
62 if (extensions_->empty()) { | 63 if (extensions_->empty()) { |
63 // If list of know extensions is empty, don't init cache on disk. It is | 64 // If list of know extensions is empty, don't init cache on disk. It is |
64 // important shortcut for test to don't wait forever for cache dir | 65 // important shortcut for test to don't wait forever for cache dir |
65 // initialization that should happen outside of Chrome on real device. | 66 // initialization that should happen outside of Chrome on real device. |
66 cached_extensions_->Clear(); | 67 cached_extensions_->Clear(); |
67 UpdateExtensionLoader(); | 68 UpdateExtensionLoader(); |
68 return; | 69 return; |
69 } | 70 } |
70 | 71 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 145 |
145 void ExternalCache::OnExtensionDownloadFailed( | 146 void ExternalCache::OnExtensionDownloadFailed( |
146 const std::string& id, | 147 const std::string& id, |
147 extensions::ExtensionDownloaderDelegate::Error error, | 148 extensions::ExtensionDownloaderDelegate::Error error, |
148 const extensions::ExtensionDownloaderDelegate::PingResult& ping_result, | 149 const extensions::ExtensionDownloaderDelegate::PingResult& ping_result, |
149 const std::set<int>& request_ids) { | 150 const std::set<int>& request_ids) { |
150 if (error == NO_UPDATE_AVAILABLE) { | 151 if (error == NO_UPDATE_AVAILABLE) { |
151 if (!cached_extensions_->HasKey(id)) { | 152 if (!cached_extensions_->HasKey(id)) { |
152 LOG(ERROR) << "ExternalCache extension " << id | 153 LOG(ERROR) << "ExternalCache extension " << id |
153 << " not found on update server"; | 154 << " not found on update server"; |
155 extensions_status_[id] = DOWNLOAD_FAILED; | |
154 delegate_->OnExtensionDownloadFailed(id, error); | 156 delegate_->OnExtensionDownloadFailed(id, error); |
155 } else { | 157 } else { |
158 // No version update for an already cached extension. | |
159 extensions_status_[id] = DOWNLOAD_SUCCEEDED; | |
156 delegate_->OnExtensionLoadedInCache(id); | 160 delegate_->OnExtensionLoadedInCache(id); |
157 } | 161 } |
158 } else { | 162 } else { |
159 LOG(ERROR) << "ExternalCache failed to download extension " << id | 163 LOG(ERROR) << "ExternalCache failed to download extension " << id |
160 << ", error " << error; | 164 << ", error " << error; |
165 extensions_status_[id] = DOWNLOAD_FAILED; | |
161 delegate_->OnExtensionDownloadFailed(id, error); | 166 delegate_->OnExtensionDownloadFailed(id, error); |
162 } | 167 } |
163 } | 168 } |
164 | 169 |
165 void ExternalCache::OnExtensionDownloadFinished( | 170 void ExternalCache::OnExtensionDownloadFinished( |
166 const std::string& id, | 171 const std::string& id, |
167 const base::FilePath& path, | 172 const base::FilePath& path, |
168 bool file_ownership_passed, | 173 bool file_ownership_passed, |
169 const GURL& download_url, | 174 const GURL& download_url, |
170 const std::string& version, | 175 const std::string& version, |
171 const extensions::ExtensionDownloaderDelegate::PingResult& ping_result, | 176 const extensions::ExtensionDownloaderDelegate::PingResult& ping_result, |
172 const std::set<int>& request_ids) { | 177 const std::set<int>& request_ids) { |
173 DCHECK(file_ownership_passed); | 178 DCHECK(file_ownership_passed); |
174 local_cache_.PutExtension(id, path, version, | 179 local_cache_.PutExtension(id, path, version, |
175 base::Bind(&ExternalCache::OnPutExtension, | 180 base::Bind(&ExternalCache::OnPutExtension, |
176 weak_ptr_factory_.GetWeakPtr(), | 181 weak_ptr_factory_.GetWeakPtr(), |
177 id)); | 182 id)); |
178 } | 183 } |
179 | 184 |
180 bool ExternalCache::IsExtensionPending(const std::string& id) { | 185 bool ExternalCache::IsExtensionPending(const std::string& id) { |
181 // Pending means that there is no installed version yet. | 186 // Pending means that there is no installed version yet. |
182 return extensions_->HasKey(id) && !cached_extensions_->HasKey(id); | 187 return extensions_->HasKey(id) && !cached_extensions_->HasKey(id) && |
188 extensions_status_.find(id) != extensions_status_.end() && | |
189 extensions_status_[id] != DOWNLOAD_FAILED; | |
xiyuan
2014/05/29 19:49:01
Not sure if we should change this. Other call site
jennyz
2014/07/07 21:11:12
removed the change from this function.
| |
190 } | |
191 | |
192 bool ExternalCache::IsExtensionPendingForUpdateCheck(const std::string& id) { | |
193 return extensions_->HasKey(id) && cached_extensions_->HasKey(id) && | |
194 extensions_status_.find(id) != extensions_status_.end() && | |
195 extensions_status_[id] == DOWNLOAD_PENDING; | |
183 } | 196 } |
184 | 197 |
185 bool ExternalCache::GetExtensionExistingVersion(const std::string& id, | 198 bool ExternalCache::GetExtensionExistingVersion(const std::string& id, |
186 std::string* version) { | 199 std::string* version) { |
187 base::DictionaryValue* extension_dictionary = NULL; | 200 base::DictionaryValue* extension_dictionary = NULL; |
188 if (cached_extensions_->GetDictionary(id, &extension_dictionary)) { | 201 if (cached_extensions_->GetDictionary(id, &extension_dictionary)) { |
189 if (extension_dictionary->GetString( | 202 if (extension_dictionary->GetString( |
190 extensions::ExternalProviderImpl::kExternalVersion, version)) { | 203 extensions::ExternalProviderImpl::kExternalVersion, version)) { |
191 return true; | 204 return true; |
192 } | 205 } |
(...skipping 13 matching lines...) Expand all Loading... | |
206 if (local_cache_.is_shutdown()) | 219 if (local_cache_.is_shutdown()) |
207 return; | 220 return; |
208 | 221 |
209 // If request_context_ is missing we can't download anything. | 222 // If request_context_ is missing we can't download anything. |
210 if (!downloader_ && request_context_) { | 223 if (!downloader_ && request_context_) { |
211 downloader_.reset( | 224 downloader_.reset( |
212 new extensions::ExtensionDownloader(this, request_context_)); | 225 new extensions::ExtensionDownloader(this, request_context_)); |
213 } | 226 } |
214 | 227 |
215 cached_extensions_->Clear(); | 228 cached_extensions_->Clear(); |
229 extensions_status_.clear(); | |
216 for (base::DictionaryValue::Iterator it(*extensions_.get()); | 230 for (base::DictionaryValue::Iterator it(*extensions_.get()); |
217 !it.IsAtEnd(); it.Advance()) { | 231 !it.IsAtEnd(); it.Advance()) { |
218 const base::DictionaryValue* entry = NULL; | 232 const base::DictionaryValue* entry = NULL; |
219 if (!it.value().GetAsDictionary(&entry)) { | 233 if (!it.value().GetAsDictionary(&entry)) { |
220 LOG(ERROR) << "ExternalCache found bad entry with type " | 234 LOG(ERROR) << "ExternalCache found bad entry with type " |
221 << it.value().GetType(); | 235 << it.value().GetType(); |
222 continue; | 236 continue; |
223 } | 237 } |
224 | 238 |
225 bool keep_if_present = | 239 bool keep_if_present = |
226 entry->HasKey(extensions::ExternalProviderImpl::kKeepIfPresent); | 240 entry->HasKey(extensions::ExternalProviderImpl::kKeepIfPresent); |
227 std::string external_update_url; | 241 std::string external_update_url; |
228 entry->GetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, | 242 entry->GetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, |
229 &external_update_url); | 243 &external_update_url); |
230 if (downloader_ && !keep_if_present) { | 244 if (downloader_ && !keep_if_present) { |
231 GURL update_url; | 245 GURL update_url; |
232 if (!external_update_url.empty()) | 246 if (!external_update_url.empty()) |
233 update_url = GURL(external_update_url); | 247 update_url = GURL(external_update_url); |
234 else if (always_check_updates_) | 248 else if (always_check_updates_) |
235 update_url = extension_urls::GetWebstoreUpdateUrl(); | 249 update_url = extension_urls::GetWebstoreUpdateUrl(); |
236 | 250 |
237 if (update_url.is_valid()) | 251 if (update_url.is_valid()) { |
238 downloader_->AddPendingExtension(it.key(), update_url, 0); | 252 downloader_->AddPendingExtension(it.key(), update_url, 0); |
253 extensions_status_[it.key()] = DOWNLOAD_PENDING; | |
254 } | |
239 } | 255 } |
240 | 256 |
241 base::FilePath file_path; | 257 base::FilePath file_path; |
242 std::string version; | 258 std::string version; |
243 if (local_cache_.GetExtension(it.key(), &file_path, &version)) { | 259 if (local_cache_.GetExtension(it.key(), &file_path, &version)) { |
244 // Copy entry to don't modify it inside extensions_. | 260 // Copy entry to don't modify it inside extensions_. |
245 base::DictionaryValue* entry_copy = entry->DeepCopy(); | 261 base::DictionaryValue* entry_copy = entry->DeepCopy(); |
246 | 262 |
247 if (extension_urls::IsWebstoreUpdateUrl(GURL(external_update_url))) { | 263 if (extension_urls::IsWebstoreUpdateUrl(GURL(external_update_url))) { |
248 entry_copy->SetBoolean( | 264 entry_copy->SetBoolean( |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 &update_url) && | 324 &update_url) && |
309 extension_urls::IsWebstoreUpdateUrl(GURL(update_url))) { | 325 extension_urls::IsWebstoreUpdateUrl(GURL(update_url))) { |
310 entry->SetBoolean(extensions::ExternalProviderImpl::kIsFromWebstore, true); | 326 entry->SetBoolean(extensions::ExternalProviderImpl::kIsFromWebstore, true); |
311 } | 327 } |
312 entry->Remove(extensions::ExternalProviderImpl::kExternalUpdateUrl, NULL); | 328 entry->Remove(extensions::ExternalProviderImpl::kExternalUpdateUrl, NULL); |
313 entry->SetString(extensions::ExternalProviderImpl::kExternalVersion, version); | 329 entry->SetString(extensions::ExternalProviderImpl::kExternalVersion, version); |
314 entry->SetString(extensions::ExternalProviderImpl::kExternalCrx, | 330 entry->SetString(extensions::ExternalProviderImpl::kExternalCrx, |
315 file_path.value()); | 331 file_path.value()); |
316 | 332 |
317 cached_extensions_->Set(id, entry); | 333 cached_extensions_->Set(id, entry); |
334 extensions_status_[id] = DOWNLOAD_SUCCEEDED; | |
318 if (delegate_) | 335 if (delegate_) |
319 delegate_->OnExtensionLoadedInCache(id); | 336 delegate_->OnExtensionLoadedInCache(id); |
320 UpdateExtensionLoader(); | 337 UpdateExtensionLoader(); |
321 } | 338 } |
322 | 339 |
323 std::string ExternalCache::Delegate::GetInstalledExtensionVersion( | 340 std::string ExternalCache::Delegate::GetInstalledExtensionVersion( |
324 const std::string& id) { | 341 const std::string& id) { |
325 return std::string(); | 342 return std::string(); |
326 } | 343 } |
327 | 344 |
328 } // namespace chromeos | 345 } // namespace chromeos |
OLD | NEW |