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

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

Issue 1281313003: base: Remove using:: declaration from version.h header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more fixes Created 5 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return false; 126 return false;
127 127
128 return (!expected_hash.empty() && it->second.expected_hash.empty()); 128 return (!expected_hash.empty() && it->second.expected_hash.empty());
129 } 129 }
130 130
131 // static 131 // static
132 bool LocalExtensionCache::NewerOrSame(const CacheMap::iterator& entry, 132 bool LocalExtensionCache::NewerOrSame(const CacheMap::iterator& entry,
133 const std::string& version, 133 const std::string& version,
134 const std::string& expected_hash, 134 const std::string& expected_hash,
135 int* compare) { 135 int* compare) {
136 Version new_version(version); 136 base::Version new_version(version);
137 Version prev_version(entry->second.version); 137 base::Version prev_version(entry->second.version);
138 int cmp = new_version.CompareTo(prev_version); 138 int cmp = new_version.CompareTo(prev_version);
139 139
140 if (compare) 140 if (compare)
141 *compare = cmp; 141 *compare = cmp;
142 142
143 // Cache entry is newer if its version is greater or same, and in the latter 143 // Cache entry is newer if its version is greater or same, and in the latter
144 // case we will prefer the existing one if we are trying to add an 144 // case we will prefer the existing one if we are trying to add an
145 // unhashed file, or we already have a hashed file in cache. 145 // unhashed file, or we already have a hashed file in cache.
146 return (cmp < 0 || (cmp == 0 && (expected_hash.empty() || 146 return (cmp < 0 || (cmp == 0 && (expected_hash.empty() ||
147 !entry->second.expected_hash.empty()))); 147 !entry->second.expected_hash.empty())));
148 } 148 }
149 149
150 void LocalExtensionCache::PutExtension(const std::string& id, 150 void LocalExtensionCache::PutExtension(const std::string& id,
151 const std::string& expected_hash, 151 const std::string& expected_hash,
152 const base::FilePath& file_path, 152 const base::FilePath& file_path,
153 const std::string& version, 153 const std::string& version,
154 const PutExtensionCallback& callback) { 154 const PutExtensionCallback& callback) {
155 if (state_ != kReady) { 155 if (state_ != kReady) {
156 callback.Run(file_path, true); 156 callback.Run(file_path, true);
157 return; 157 return;
158 } 158 }
159 159
160 Version version_validator(version); 160 base::Version version_validator(version);
161 if (!version_validator.IsValid()) { 161 if (!version_validator.IsValid()) {
162 LOG(ERROR) << "Extension " << id << " has bad version " << version; 162 LOG(ERROR) << "Extension " << id << " has bad version " << version;
163 callback.Run(file_path, true); 163 callback.Run(file_path, true);
164 return; 164 return;
165 } 165 }
166 166
167 CacheMap::iterator it = FindExtension(cached_extensions_, id, expected_hash); 167 CacheMap::iterator it = FindExtension(cached_extensions_, id, expected_hash);
168 if (it != cached_extensions_.end() && 168 if (it != cached_extensions_.end() &&
169 NewerOrSame(it, version, expected_hash, NULL)) { 169 NewerOrSame(it, version, expected_hash, NULL)) {
170 LOG(WARNING) << "Cache contains newer or the same version " 170 LOG(WARNING) << "Cache contains newer or the same version "
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 436 }
437 } 437 }
438 438
439 // Enforce a lower-case id. 439 // Enforce a lower-case id.
440 id = base::ToLowerASCII(id); 440 id = base::ToLowerASCII(id);
441 if (!crx_file::id_util::IdIsValid(id)) { 441 if (!crx_file::id_util::IdIsValid(id)) {
442 LOG(ERROR) << "Bad extension id in cache: " << id; 442 LOG(ERROR) << "Bad extension id in cache: " << id;
443 id.clear(); 443 id.clear();
444 } 444 }
445 445
446 if (!Version(version).IsValid()) { 446 if (!base::Version(version).IsValid()) {
447 LOG(ERROR) << "Bad extension version in cache: " << version; 447 LOG(ERROR) << "Bad extension version in cache: " << version;
448 version.clear(); 448 version.clear();
449 } 449 }
450 450
451 if (id.empty() || version.empty()) { 451 if (id.empty() || version.empty()) {
452 LOG(ERROR) << "Invalid file in cache, erasing: " << basename; 452 LOG(ERROR) << "Invalid file in cache, erasing: " << basename;
453 base::DeleteFile(path, true /* recursive */); 453 base::DeleteFile(path, true /* recursive */);
454 continue; 454 continue;
455 } 455 }
456 456
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 expected_hash(base::ToLowerASCII(expected_hash)), 615 expected_hash(base::ToLowerASCII(expected_hash)),
616 last_used(last_used), 616 last_used(last_used),
617 size(size), 617 size(size),
618 file_path(file_path) { 618 file_path(file_path) {
619 } 619 }
620 620
621 LocalExtensionCache::CacheItemInfo::~CacheItemInfo() { 621 LocalExtensionCache::CacheItemInfo::~CacheItemInfo() {
622 } 622 }
623 623
624 } // namespace extensions 624 } // 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