Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/extensions/updater/local_extension_cache.cc

Issue 2259383002: Consistently use namespaced base::Version in extensions code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extensions/updater/local_extension_cache.h" 5 #include "chrome/browser/extensions/updater/local_extension_cache.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_enumerator.h" 8 #include "base/files/file_enumerator.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 return false; 125 return false;
126 126
127 return (!expected_hash.empty() && it->second.expected_hash.empty()); 127 return (!expected_hash.empty() && it->second.expected_hash.empty());
128 } 128 }
129 129
130 // static 130 // static
131 bool LocalExtensionCache::NewerOrSame(const CacheMap::iterator& entry, 131 bool LocalExtensionCache::NewerOrSame(const CacheMap::iterator& entry,
132 const std::string& version, 132 const std::string& version,
133 const std::string& expected_hash, 133 const std::string& expected_hash,
134 int* compare) { 134 int* compare) {
135 Version new_version(version); 135 base::Version new_version(version);
136 Version prev_version(entry->second.version); 136 base::Version prev_version(entry->second.version);
137 int cmp = new_version.CompareTo(prev_version); 137 int cmp = new_version.CompareTo(prev_version);
138 138
139 if (compare) 139 if (compare)
140 *compare = cmp; 140 *compare = cmp;
141 141
142 // Cache entry is newer if its version is greater or same, and in the latter 142 // Cache entry is newer if its version is greater or same, and in the latter
143 // case we will prefer the existing one if we are trying to add an 143 // case we will prefer the existing one if we are trying to add an
144 // unhashed file, or we already have a hashed file in cache. 144 // unhashed file, or we already have a hashed file in cache.
145 return (cmp < 0 || (cmp == 0 && (expected_hash.empty() || 145 return (cmp < 0 || (cmp == 0 && (expected_hash.empty() ||
146 !entry->second.expected_hash.empty()))); 146 !entry->second.expected_hash.empty())));
147 } 147 }
148 148
149 void LocalExtensionCache::PutExtension(const std::string& id, 149 void LocalExtensionCache::PutExtension(const std::string& id,
150 const std::string& expected_hash, 150 const std::string& expected_hash,
151 const base::FilePath& file_path, 151 const base::FilePath& file_path,
152 const std::string& version, 152 const std::string& version,
153 const PutExtensionCallback& callback) { 153 const PutExtensionCallback& callback) {
154 if (state_ != kReady) { 154 if (state_ != kReady) {
155 callback.Run(file_path, true); 155 callback.Run(file_path, true);
156 return; 156 return;
157 } 157 }
158 158
159 Version version_validator(version); 159 base::Version version_validator(version);
160 if (!version_validator.IsValid()) { 160 if (!version_validator.IsValid()) {
161 LOG(ERROR) << "Extension " << id << " has bad version " << version; 161 LOG(ERROR) << "Extension " << id << " has bad version " << version;
162 callback.Run(file_path, true); 162 callback.Run(file_path, true);
163 return; 163 return;
164 } 164 }
165 165
166 CacheMap::iterator it = FindExtension(cached_extensions_, id, expected_hash); 166 CacheMap::iterator it = FindExtension(cached_extensions_, id, expected_hash);
167 if (it != cached_extensions_.end() && 167 if (it != cached_extensions_.end() &&
168 NewerOrSame(it, version, expected_hash, NULL)) { 168 NewerOrSame(it, version, expected_hash, NULL)) {
169 LOG(WARNING) << "Cache contains newer or the same version " 169 LOG(WARNING) << "Cache contains newer or the same version "
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } 435 }
436 } 436 }
437 437
438 // Enforce a lower-case id. 438 // Enforce a lower-case id.
439 id = base::ToLowerASCII(id); 439 id = base::ToLowerASCII(id);
440 if (!crx_file::id_util::IdIsValid(id)) { 440 if (!crx_file::id_util::IdIsValid(id)) {
441 LOG(ERROR) << "Bad extension id in cache: " << id; 441 LOG(ERROR) << "Bad extension id in cache: " << id;
442 id.clear(); 442 id.clear();
443 } 443 }
444 444
445 if (!Version(version).IsValid()) { 445 if (!base::Version(version).IsValid()) {
446 LOG(ERROR) << "Bad extension version in cache: " << version; 446 LOG(ERROR) << "Bad extension version in cache: " << version;
447 version.clear(); 447 version.clear();
448 } 448 }
449 449
450 if (id.empty() || version.empty()) { 450 if (id.empty() || version.empty()) {
451 LOG(ERROR) << "Invalid file in cache, erasing: " << basename; 451 LOG(ERROR) << "Invalid file in cache, erasing: " << basename;
452 base::DeleteFile(path, true /* recursive */); 452 base::DeleteFile(path, true /* recursive */);
453 continue; 453 continue;
454 } 454 }
455 455
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 size(size), 616 size(size),
617 file_path(file_path) {} 617 file_path(file_path) {}
618 618
619 LocalExtensionCache::CacheItemInfo::CacheItemInfo(const CacheItemInfo& other) = 619 LocalExtensionCache::CacheItemInfo::CacheItemInfo(const CacheItemInfo& other) =
620 default; 620 default;
621 621
622 LocalExtensionCache::CacheItemInfo::~CacheItemInfo() { 622 LocalExtensionCache::CacheItemInfo::~CacheItemInfo() {
623 } 623 }
624 624
625 } // namespace extensions 625 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater_unittest.cc ('k') | chrome/browser/extensions/webstore_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698