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

Side by Side Diff: services/url_response_disk_cache/url_response_disk_cache_impl.cc

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/url_response_disk_cache/url_response_disk_cache_impl.h" 5 #include "services/url_response_disk_cache/url_response_disk_cache_impl.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 for (size_t i = 0u; i < headers.size(); ++i) { 230 for (size_t i = 0u; i < headers.size(); ++i) {
231 const std::string& name = headers[i]->name.get(); 231 const std::string& name = headers[i]->name.get();
232 if (base::LowerCaseEqualsASCII(name, header_name.c_str())) 232 if (base::LowerCaseEqualsASCII(name, header_name.c_str()))
233 result.push_back(headers[i]->value); 233 result.push_back(headers[i]->value);
234 } 234 }
235 return result; 235 return result;
236 } 236 }
237 237
238 // Returns whether the given |entry| is valid. 238 // Returns whether the given |entry| is valid.
239 bool IsCacheEntryValid(const CacheEntryPtr& entry) { 239 bool IsCacheEntryValid(const CacheEntryPtr& entry) {
240 return entry && PathExists(base::FilePath(entry->response_body_path)); 240 return entry &&
241 PathExists(base::FilePath::FromUTF8Unsafe(entry->response_body_path));
241 } 242 }
242 243
243 // Returns whether the given directory |entry| is valid and its content can be 244 // Returns whether the given directory |entry| is valid and its content can be
244 // used for the given |response|. 245 // used for the given |response|.
245 bool IsCacheEntryFresh(const URLResponsePtr& response, 246 bool IsCacheEntryFresh(const URLResponsePtr& response,
246 const CacheEntryPtr& entry) { 247 const CacheEntryPtr& entry) {
247 DCHECK(response); 248 DCHECK(response);
248 if (!IsCacheEntryValid(entry)) 249 if (!IsCacheEntryValid(entry))
249 return false; 250 return false;
250 251
(...skipping 27 matching lines...) Expand all
278 279
279 void PruneCache(scoped_refptr<URLResponseDiskCacheDB> db, 280 void PruneCache(scoped_refptr<URLResponseDiskCacheDB> db,
280 const scoped_ptr<URLResponseDiskCacheDB::Iterator>& iterator) { 281 const scoped_ptr<URLResponseDiskCacheDB::Iterator>& iterator) {
281 CacheKeyPtr last_key; 282 CacheKeyPtr last_key;
282 CacheKeyPtr key; 283 CacheKeyPtr key;
283 CacheEntryPtr entry; 284 CacheEntryPtr entry;
284 while (iterator->HasNext()) { 285 while (iterator->HasNext()) {
285 iterator->GetNext(&key, &entry); 286 iterator->GetNext(&key, &entry);
286 if (last_key && last_key->request_origin == key->request_origin && 287 if (last_key && last_key->request_origin == key->request_origin &&
287 last_key->url == key->url) { 288 last_key->url == key->url) {
288 base::FilePath entry_directory = base::FilePath(entry->entry_directory); 289 base::FilePath entry_directory =
290 base::FilePath::FromUTF8Unsafe(entry->entry_directory);
289 if (base::DeleteFile(entry_directory, true)) 291 if (base::DeleteFile(entry_directory, true))
290 db->Delete(key.Clone()); 292 db->Delete(key.Clone());
291 } 293 }
292 last_key = key.Pass(); 294 last_key = key.Pass();
293 } 295 }
294 } 296 }
295 297
296 } // namespace 298 } // namespace
297 299
298 // static 300 // static
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 base::Bind(&RunMojoCallbackWithResponse, callback, canonilized_url), 385 base::Bind(&RunMojoCallbackWithResponse, callback, canonilized_url),
384 identifier, request_origin_, canonilized_url, 386 identifier, request_origin_, canonilized_url,
385 base::Passed(GetMinimalResponse(canonilized_url)), db_, 387 base::Passed(GetMinimalResponse(canonilized_url)), db_,
386 task_runner_)); 388 task_runner_));
387 return; 389 return;
388 } 390 }
389 if (IsInvalidated(entry) || !IsCacheEntryValid(entry)) { 391 if (IsInvalidated(entry) || !IsCacheEntryValid(entry)) {
390 callback.Run(URLResponsePtr(), nullptr, nullptr); 392 callback.Run(URLResponsePtr(), nullptr, nullptr);
391 return; 393 return;
392 } 394 }
393 callback.Run(entry->response.Pass(), 395 callback.Run(
394 PathToArray(base::FilePath(entry->response_body_path)), 396 entry->response.Pass(),
395 PathToArray(GetConsumerCacheDirectory( 397 PathToArray(base::FilePath::FromUTF8Unsafe(entry->response_body_path)),
396 base::FilePath(entry->entry_directory)))); 398 PathToArray(GetConsumerCacheDirectory(
399 base::FilePath::FromUTF8Unsafe(entry->entry_directory))));
397 UpdateLastInvalidation(db_, key.Pass(), base::Time::Now()); 400 UpdateLastInvalidation(db_, key.Pass(), base::Time::Now());
398 } 401 }
399 402
400 void URLResponseDiskCacheImpl::Validate(const String& url) { 403 void URLResponseDiskCacheImpl::Validate(const String& url) {
401 CacheKeyPtr key; 404 CacheKeyPtr key;
402 CacheEntryPtr entry = 405 CacheEntryPtr entry =
403 db_->GetNewest(request_origin_, CanonicalizeURL(url), &key); 406 db_->GetNewest(request_origin_, CanonicalizeURL(url), &key);
404 if (entry) 407 if (entry)
405 UpdateLastInvalidation(db_, key.Pass(), base::Time::Max()); 408 UpdateLastInvalidation(db_, key.Pass(), base::Time::Max());
406 } 409 }
(...skipping 27 matching lines...) Expand all
434 return; 437 return;
435 } 438 }
436 439
437 std::string url = CanonicalizeURL(response->url); 440 std::string url = CanonicalizeURL(response->url);
438 441
439 // Check if the response is cached and valid. If that's the case, returns 442 // Check if the response is cached and valid. If that's the case, returns
440 // the cached value. 443 // the cached value.
441 CacheKeyPtr key; 444 CacheKeyPtr key;
442 CacheEntryPtr entry = db_->GetNewest(request_origin_, url, &key); 445 CacheEntryPtr entry = db_->GetNewest(request_origin_, url, &key);
443 if (IsCacheEntryFresh(response, entry)) { 446 if (IsCacheEntryFresh(response, entry)) {
444 callback.Run( 447 callback.Run(base::FilePath::FromUTF8Unsafe(entry->response_body_path),
445 base::FilePath(entry->response_body_path), 448 GetConsumerCacheDirectory(
446 GetConsumerCacheDirectory(base::FilePath(entry->entry_directory))); 449 base::FilePath::FromUTF8Unsafe(entry->entry_directory)));
447 UpdateLastInvalidation(db_, key.Pass(), base::Time::Max()); 450 UpdateLastInvalidation(db_, key.Pass(), base::Time::Max());
448 return; 451 return;
449 } 452 }
450 453
451 if (!response->body.is_valid()) { 454 if (!response->body.is_valid()) {
452 callback.Run(base::FilePath(), base::FilePath()); 455 callback.Run(base::FilePath(), base::FilePath());
453 return; 456 return;
454 } 457 }
455 458
456 std::string identifier = GetNewIdentifier(); 459 std::string identifier = GetNewIdentifier();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 return; 518 return;
516 } 519 }
517 } 520 }
518 // We can ignore write error, as it will just force to clear the cache on the 521 // We can ignore write error, as it will just force to clear the cache on the
519 // next request. 522 // next request.
520 WriteFile(GetExtractionSentinel(entry_directory), nullptr, 0); 523 WriteFile(GetExtractionSentinel(entry_directory), nullptr, 0);
521 callback.Run(extraction_directory, consumer_cache_directory); 524 callback.Run(extraction_directory, consumer_cache_directory);
522 } 525 }
523 526
524 } // namespace mojo 527 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698