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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 base::DictionaryValue* entry = NULL; | 334 base::DictionaryValue* entry = NULL; |
335 if (!extensions::Extension::IdIsValid(id)) { | 335 if (!extensions::Extension::IdIsValid(id)) { |
336 LOG(ERROR) << "Bad extension id in ExternalCache: " << id; | 336 LOG(ERROR) << "Bad extension id in ExternalCache: " << id; |
337 id.clear(); | 337 id.clear(); |
338 } else if (!prefs->GetDictionary(id, &entry)) { | 338 } else if (!prefs->GetDictionary(id, &entry)) { |
339 LOG(WARNING) << basename << " is in the cache but is not configured by " | 339 LOG(WARNING) << basename << " is in the cache but is not configured by " |
340 << "the ExternalCache source, and will be erased."; | 340 << "the ExternalCache source, and will be erased."; |
341 id.clear(); | 341 id.clear(); |
342 } | 342 } |
343 | 343 |
344 if (!base::Version(version).IsValid()) { | 344 if (!Version(version).IsValid()) { |
345 LOG(ERROR) << "Bad extension version in ExternalCache: " << version; | 345 LOG(ERROR) << "Bad extension version in ExternalCache: " << version; |
346 version.clear(); | 346 version.clear(); |
347 } | 347 } |
348 | 348 |
349 if (id.empty() || version.empty()) { | 349 if (id.empty() || version.empty()) { |
350 LOG(ERROR) << "Invalid file in ExternalCache, erasing: " << basename; | 350 LOG(ERROR) << "Invalid file in ExternalCache, erasing: " << basename; |
351 base::DeleteFile(path, true /* recursive */); | 351 base::DeleteFile(path, true /* recursive */); |
352 continue; | 352 continue; |
353 } | 353 } |
354 | 354 |
(...skipping 14 matching lines...) Expand all Loading... |
369 path.value()); | 369 path.value()); |
370 if (extension_urls::IsWebstoreUpdateUrl(GURL(update_url))) { | 370 if (extension_urls::IsWebstoreUpdateUrl(GURL(update_url))) { |
371 entry->SetBoolean(extensions::ExternalProviderImpl::kIsFromWebstore, | 371 entry->SetBoolean(extensions::ExternalProviderImpl::kIsFromWebstore, |
372 true); | 372 true); |
373 } | 373 } |
374 } else if ( | 374 } else if ( |
375 entry->GetString(extensions::ExternalProviderImpl::kExternalVersion, | 375 entry->GetString(extensions::ExternalProviderImpl::kExternalVersion, |
376 &prev_version_string) && | 376 &prev_version_string) && |
377 entry->GetString(extensions::ExternalProviderImpl::kExternalCrx, | 377 entry->GetString(extensions::ExternalProviderImpl::kExternalCrx, |
378 &prev_crx)) { | 378 &prev_crx)) { |
379 base::Version prev_version(prev_version_string); | 379 Version prev_version(prev_version_string); |
380 base::Version curr_version(version); | 380 Version curr_version(version); |
381 DCHECK(prev_version.IsValid()); | 381 DCHECK(prev_version.IsValid()); |
382 DCHECK(curr_version.IsValid()); | 382 DCHECK(curr_version.IsValid()); |
383 if (prev_version.CompareTo(curr_version) <= 0) { | 383 if (prev_version.CompareTo(curr_version) <= 0) { |
384 VLOG(1) << "ExternalCache found old cached version " | 384 VLOG(1) << "ExternalCache found old cached version " |
385 << prev_version_string << " path: " << prev_crx; | 385 << prev_version_string << " path: " << prev_crx; |
386 base::FilePath prev_crx_file(prev_crx); | 386 base::FilePath prev_crx_file(prev_crx); |
387 if (cache_dir.IsParent(prev_crx_file)) { | 387 if (cache_dir.IsParent(prev_crx_file)) { |
388 // Only delete old cached files under cache_dir_ folder. | 388 // Only delete old cached files under cache_dir_ folder. |
389 base::DeleteFile(base::FilePath(prev_crx), true /* recursive */); | 389 base::DeleteFile(base::FilePath(prev_crx), true /* recursive */); |
390 } | 390 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 UpdateExtensionLoader(); | 465 UpdateExtensionLoader(); |
466 } | 466 } |
467 | 467 |
468 // static | 468 // static |
469 void ExternalCache::BackendInstallCacheEntry( | 469 void ExternalCache::BackendInstallCacheEntry( |
470 base::WeakPtr<ExternalCache> external_cache, | 470 base::WeakPtr<ExternalCache> external_cache, |
471 const base::FilePath& cache_dir, | 471 const base::FilePath& cache_dir, |
472 const std::string& id, | 472 const std::string& id, |
473 const base::FilePath& path, | 473 const base::FilePath& path, |
474 const std::string& version) { | 474 const std::string& version) { |
475 base::Version version_validator(version); | 475 Version version_validator(version); |
476 if (!version_validator.IsValid()) { | 476 if (!version_validator.IsValid()) { |
477 LOG(ERROR) << "ExternalCache downloaded extension " << id << " but got bad " | 477 LOG(ERROR) << "ExternalCache downloaded extension " << id << " but got bad " |
478 << "version: " << version; | 478 << "version: " << version; |
479 base::DeleteFile(path, true /* recursive */); | 479 base::DeleteFile(path, true /* recursive */); |
480 return; | 480 return; |
481 } | 481 } |
482 | 482 |
483 std::string basename = id + "-" + version + kCRXFileExtension; | 483 std::string basename = id + "-" + version + kCRXFileExtension; |
484 base::FilePath cached_crx_path = cache_dir.Append(basename); | 484 base::FilePath cached_crx_path = cache_dir.Append(basename); |
485 | 485 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 FROM_HERE, | 554 FROM_HERE, |
555 callback); | 555 callback); |
556 } | 556 } |
557 | 557 |
558 std::string ExternalCache::Delegate::GetInstalledExtensionVersion( | 558 std::string ExternalCache::Delegate::GetInstalledExtensionVersion( |
559 const std::string& id) { | 559 const std::string& id) { |
560 return std::string(); | 560 return std::string(); |
561 } | 561 } |
562 | 562 |
563 } // namespace chromeos | 563 } // namespace chromeos |
OLD | NEW |