OLD | NEW |
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const base::FilePath& trash_dir) { | 74 const base::FilePath& trash_dir) { |
75 // Delete the trash directory. | 75 // Delete the trash directory. |
76 task_runner->PostDelayedTask( | 76 task_runner->PostDelayedTask( |
77 FROM_HERE, | 77 FROM_HERE, |
78 base::Bind(base::IgnoreResult(&base::DeleteFile), trash_dir, true), | 78 base::Bind(base::IgnoreResult(&base::DeleteFile), trash_dir, true), |
79 base::TimeDelta::FromSeconds(kTrashDelayInSeconds)); | 79 base::TimeDelta::FromSeconds(kTrashDelayInSeconds)); |
80 } | 80 } |
81 | 81 |
82 Array<uint8_t> PathToArray(const base::FilePath& path) { | 82 Array<uint8_t> PathToArray(const base::FilePath& path) { |
83 if (path.empty()) | 83 if (path.empty()) |
84 return Array<uint8_t>(); | 84 return nullptr; |
85 const std::string& string = path.value(); | 85 const std::string& string = path.value(); |
86 auto result = Array<uint8_t>::New(string.size()); | 86 auto result = Array<uint8_t>::New(string.size()); |
87 memcpy(&result.front(), string.data(), string.size()); | 87 memcpy(&result.front(), string.data(), string.size()); |
88 return result; | 88 return result; |
89 } | 89 } |
90 | 90 |
91 // This method remove the query string of an url if one is present. It does | 91 // This method remove the query string of an url if one is present. It does |
92 // match the behavior of the application manager, which connects to the same app | 92 // match the behavior of the application manager, which connects to the same app |
93 // if requested twice with different query parameters. | 93 // if requested twice with different query parameters. |
94 std::string CanonicalizeURL(const std::string& url) { | 94 std::string CanonicalizeURL(const std::string& url) { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 task_runner_, canonilized_url, staged_response_body_path, | 380 task_runner_, canonilized_url, staged_response_body_path, |
381 base::Bind( | 381 base::Bind( |
382 RunCallbackWithSuccess, | 382 RunCallbackWithSuccess, |
383 base::Bind(&RunMojoCallbackWithResponse, callback, canonilized_url), | 383 base::Bind(&RunMojoCallbackWithResponse, callback, canonilized_url), |
384 identifier, request_origin_, canonilized_url, | 384 identifier, request_origin_, canonilized_url, |
385 base::Passed(GetMinimalResponse(canonilized_url)), db_, | 385 base::Passed(GetMinimalResponse(canonilized_url)), db_, |
386 task_runner_)); | 386 task_runner_)); |
387 return; | 387 return; |
388 } | 388 } |
389 if (IsInvalidated(entry) || !IsCacheEntryValid(entry)) { | 389 if (IsInvalidated(entry) || !IsCacheEntryValid(entry)) { |
390 callback.Run(URLResponsePtr(), Array<uint8_t>(), Array<uint8_t>()); | 390 callback.Run(URLResponsePtr(), nullptr, nullptr); |
391 return; | 391 return; |
392 } | 392 } |
393 callback.Run(entry->response.Pass(), | 393 callback.Run(entry->response.Pass(), |
394 PathToArray(base::FilePath(entry->response_body_path)), | 394 PathToArray(base::FilePath(entry->response_body_path)), |
395 PathToArray(GetConsumerCacheDirectory( | 395 PathToArray(GetConsumerCacheDirectory( |
396 base::FilePath(entry->entry_directory)))); | 396 base::FilePath(entry->entry_directory)))); |
397 UpdateLastInvalidation(db_, key.Pass(), base::Time::Now()); | 397 UpdateLastInvalidation(db_, key.Pass(), base::Time::Now()); |
398 } | 398 } |
399 | 399 |
400 void URLResponseDiskCacheImpl::Validate(const String& url) { | 400 void URLResponseDiskCacheImpl::Validate(const String& url) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 return; | 515 return; |
516 } | 516 } |
517 } | 517 } |
518 // We can ignore write error, as it will just force to clear the cache on the | 518 // We can ignore write error, as it will just force to clear the cache on the |
519 // next request. | 519 // next request. |
520 WriteFile(GetExtractionSentinel(entry_directory), nullptr, 0); | 520 WriteFile(GetExtractionSentinel(entry_directory), nullptr, 0); |
521 callback.Run(extraction_directory, consumer_cache_directory); | 521 callback.Run(extraction_directory, consumer_cache_directory); |
522 } | 522 } |
523 | 523 |
524 } // namespace mojo | 524 } // namespace mojo |
OLD | NEW |