summaryrefslogtreecommitdiff
path: root/chromium/net/disk_cache/simple
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-04-05 14:08:31 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-04-11 07:46:53 +0000
commit6a4cabb866f66d4128a97cdc6d9d08ce074f1247 (patch)
treeab00f70a5e89278d6a0d16ff0c42578dc4d84a2d /chromium/net/disk_cache/simple
parente733310db58160074f574c429d48f8308c0afe17 (diff)
downloadqtwebengine-chromium-6a4cabb866f66d4128a97cdc6d9d08ce074f1247.tar.gz
BASELINE: Update Chromium to 57.0.2987.144
Change-Id: I29db402ff696c71a04c4dbaec822c2e53efe0267 Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'chromium/net/disk_cache/simple')
-rw-r--r--chromium/net/disk_cache/simple/simple_backend_impl.cc21
-rw-r--r--chromium/net/disk_cache/simple/simple_backend_impl.h11
-rw-r--r--chromium/net/disk_cache/simple/simple_entry_format.h4
-rw-r--r--chromium/net/disk_cache/simple/simple_entry_impl.cc2
-rw-r--r--chromium/net/disk_cache/simple/simple_experiment_unittest.cc1
-rw-r--r--chromium/net/disk_cache/simple/simple_index.cc36
-rw-r--r--chromium/net/disk_cache/simple/simple_index.h6
-rw-r--r--chromium/net/disk_cache/simple/simple_index_file_unittest.cc1
-rw-r--r--chromium/net/disk_cache/simple/simple_net_log_parameters.h6
-rw-r--r--chromium/net/disk_cache/simple/simple_synchronous_entry.cc1
-rw-r--r--chromium/net/disk_cache/simple/simple_test_util.cc12
11 files changed, 80 insertions, 21 deletions
diff --git a/chromium/net/disk_cache/simple/simple_backend_impl.cc b/chromium/net/disk_cache/simple/simple_backend_impl.cc
index 30fade471fd..e5645e357eb 100644
--- a/chromium/net/disk_cache/simple/simple_backend_impl.cc
+++ b/chromium/net/disk_cache/simple/simple_backend_impl.cc
@@ -458,6 +458,15 @@ int SimpleBackendImpl::CalculateSizeOfAllEntries(
&SimpleBackendImpl::IndexReadyForSizeCalculation, AsWeakPtr(), callback));
}
+int SimpleBackendImpl::CalculateSizeOfEntriesBetween(
+ base::Time initial_time,
+ base::Time end_time,
+ const CompletionCallback& callback) {
+ return index_->ExecuteWhenReady(
+ base::Bind(&SimpleBackendImpl::IndexReadyForSizeBetweenCalculation,
+ AsWeakPtr(), initial_time, end_time, callback));
+}
+
class SimpleBackendImpl::SimpleIterator final : public Iterator {
public:
explicit SimpleIterator(base::WeakPtr<SimpleBackendImpl> backend)
@@ -573,6 +582,18 @@ void SimpleBackendImpl::IndexReadyForSizeCalculation(
callback.Run(result);
}
+void SimpleBackendImpl::IndexReadyForSizeBetweenCalculation(
+ base::Time initial_time,
+ base::Time end_time,
+ const CompletionCallback& callback,
+ int result) {
+ if (result == net::OK) {
+ result =
+ static_cast<int>(index_->GetCacheSizeBetween(initial_time, end_time));
+ }
+ callback.Run(result);
+}
+
// static
SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk(
const base::FilePath& path,
diff --git a/chromium/net/disk_cache/simple/simple_backend_impl.h b/chromium/net/disk_cache/simple/simple_backend_impl.h
index 3516847e1f7..a0b4b9c4282 100644
--- a/chromium/net/disk_cache/simple/simple_backend_impl.h
+++ b/chromium/net/disk_cache/simple/simple_backend_impl.h
@@ -110,6 +110,10 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend,
int DoomEntriesSince(base::Time initial_time,
const CompletionCallback& callback) override;
int CalculateSizeOfAllEntries(const CompletionCallback& callback) override;
+ int CalculateSizeOfEntriesBetween(
+ base::Time initial_time,
+ base::Time end_time,
+ const CompletionCallback& callback) override;
std::unique_ptr<Iterator> CreateIterator() override;
void GetStats(base::StringPairs* stats) override;
void OnExternalCacheHit(const std::string& key) override;
@@ -148,6 +152,13 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend,
void IndexReadyForSizeCalculation(const CompletionCallback& callback,
int result);
+ // Calculates the size all cache entries between |initial_time| and
+ // |end_time|. Invoked when the index is ready.
+ void IndexReadyForSizeBetweenCalculation(base::Time initial_time,
+ base::Time end_time,
+ const CompletionCallback& callback,
+ int result);
+
// Try to create the directory if it doesn't exist. This must run on the IO
// thread.
static DiskStatResult InitCacheStructureOnDisk(
diff --git a/chromium/net/disk_cache/simple/simple_entry_format.h b/chromium/net/disk_cache/simple/simple_entry_format.h
index 30a369358fb..eec9d68c7f4 100644
--- a/chromium/net/disk_cache/simple/simple_entry_format.h
+++ b/chromium/net/disk_cache/simple/simple_entry_format.h
@@ -9,10 +9,6 @@
#include "net/base/net_export.h"
-namespace base {
-class Time;
-}
-
namespace disk_cache {
const uint64_t kSimpleInitialMagicNumber = UINT64_C(0xfcfb6d1ba7725c30);
diff --git a/chromium/net/disk_cache/simple/simple_entry_impl.cc b/chromium/net/disk_cache/simple/simple_entry_impl.cc
index 8bc20fcbbde..23136ba60e5 100644
--- a/chromium/net/disk_cache/simple/simple_entry_impl.cc
+++ b/chromium/net/disk_cache/simple/simple_entry_impl.cc
@@ -205,7 +205,7 @@ SimpleEntryImpl::SimpleEntryImpl(net::CacheType cache_type,
void SimpleEntryImpl::SetActiveEntryProxy(
std::unique_ptr<ActiveEntryProxy> active_entry_proxy) {
DCHECK(!active_entry_proxy_);
- active_entry_proxy_.reset(active_entry_proxy.release());
+ active_entry_proxy_ = std::move(active_entry_proxy);
}
int SimpleEntryImpl::OpenEntry(Entry** out_entry,
diff --git a/chromium/net/disk_cache/simple/simple_experiment_unittest.cc b/chromium/net/disk_cache/simple/simple_experiment_unittest.cc
index ca187e413bf..66d04000ed9 100644
--- a/chromium/net/disk_cache/simple/simple_experiment_unittest.cc
+++ b/chromium/net/disk_cache/simple/simple_experiment_unittest.cc
@@ -10,6 +10,7 @@
#include <utility>
#include "base/feature_list.h"
+#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_param_associator.h"
#include "base/optional.h"
diff --git a/chromium/net/disk_cache/simple/simple_index.cc b/chromium/net/disk_cache/simple/simple_index.cc
index e68e7468f20..a654faf3718 100644
--- a/chromium/net/disk_cache/simple/simple_index.cc
+++ b/chromium/net/disk_cache/simple/simple_index.cc
@@ -220,16 +220,14 @@ std::unique_ptr<SimpleIndex::HashList> SimpleIndex::GetEntriesBetween(
end_time = base::Time::Max();
else
end_time += EntryMetadata::GetUpperEpsilonForTimeComparisons();
- const base::Time extended_end_time =
- end_time.is_null() ? base::Time::Max() : end_time;
- DCHECK(extended_end_time >= initial_time);
+ DCHECK(end_time >= initial_time);
+
std::unique_ptr<HashList> ret_hashes(new HashList());
- for (EntrySet::iterator it = entries_set_.begin(), end = entries_set_.end();
- it != end; ++it) {
- EntryMetadata& metadata = it->second;
+ for (const auto& entry : entries_set_) {
+ const EntryMetadata& metadata = entry.second;
base::Time entry_time = metadata.GetLastUsedTime();
- if (initial_time <= entry_time && entry_time < extended_end_time)
- ret_hashes->push_back(it->first);
+ if (initial_time <= entry_time && entry_time < end_time)
+ ret_hashes->push_back(entry.first);
}
return ret_hashes;
}
@@ -248,6 +246,28 @@ uint64_t SimpleIndex::GetCacheSize() const {
return cache_size_;
}
+uint64_t SimpleIndex::GetCacheSizeBetween(base::Time initial_time,
+ base::Time end_time) const {
+ DCHECK_EQ(true, initialized_);
+
+ if (!initial_time.is_null())
+ initial_time -= EntryMetadata::GetLowerEpsilonForTimeComparisons();
+ if (end_time.is_null())
+ end_time = base::Time::Max();
+ else
+ end_time += EntryMetadata::GetUpperEpsilonForTimeComparisons();
+
+ DCHECK(end_time >= initial_time);
+ uint64_t size = 0;
+ for (const auto& entry : entries_set_) {
+ const EntryMetadata& metadata = entry.second;
+ base::Time entry_time = metadata.GetLastUsedTime();
+ if (initial_time <= entry_time && entry_time < end_time)
+ size += metadata.GetEntrySize();
+ }
+ return size;
+}
+
void SimpleIndex::Insert(uint64_t entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread());
// Upon insert we don't know yet the size of the entry.
diff --git a/chromium/net/disk_cache/simple/simple_index.h b/chromium/net/disk_cache/simple/simple_index.h
index fee2a1e93e0..1adb0ecc48a 100644
--- a/chromium/net/disk_cache/simple/simple_index.h
+++ b/chromium/net/disk_cache/simple/simple_index.h
@@ -155,6 +155,12 @@ class NET_EXPORT_PRIVATE SimpleIndex
// index has been initialized.
uint64_t GetCacheSize() const;
+ // Returns the size of the cache entries accessed between |initial_time| and
+ // |end_time| in bytes. Can only be called after the index has been
+ // initialized.
+ uint64_t GetCacheSizeBetween(const base::Time initial_time,
+ const base::Time end_time) const;
+
// Returns whether the index has been initialized yet.
bool initialized() const { return initialized_; }
diff --git a/chromium/net/disk_cache/simple/simple_index_file_unittest.cc b/chromium/net/disk_cache/simple/simple_index_file_unittest.cc
index 5d49fb254e3..54ce8955a08 100644
--- a/chromium/net/disk_cache/simple/simple_index_file_unittest.cc
+++ b/chromium/net/disk_cache/simple/simple_index_file_unittest.cc
@@ -15,7 +15,6 @@
#include "base/pickle.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
-#include "base/strings/stringprintf.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
diff --git a/chromium/net/disk_cache/simple/simple_net_log_parameters.h b/chromium/net/disk_cache/simple/simple_net_log_parameters.h
index ac9d003650a..39b105a4408 100644
--- a/chromium/net/disk_cache/simple/simple_net_log_parameters.h
+++ b/chromium/net/disk_cache/simple/simple_net_log_parameters.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef NET_DISK_CACHE_SIMPLE_NET_LOG_PARAMETERS_H_
-#define NET_DISK_CACHE_SIMPLE_NET_LOG_PARAMETERS_H_
+#ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_NET_LOG_PARAMETERS_H_
+#define NET_DISK_CACHE_SIMPLE_SIMPLE_NET_LOG_PARAMETERS_H_
#include "net/log/net_log_parameters_callback.h"
@@ -29,4 +29,4 @@ net::NetLogParametersCallback CreateNetLogSimpleEntryCreationCallback(
} // namespace disk_cache
-#endif // NET_DISK_CACHE_SIMPLE_NET_LOG_PARAMETERS_H_
+#endif // NET_DISK_CACHE_SIMPLE_SIMPLE_NET_LOG_PARAMETERS_H_
diff --git a/chromium/net/disk_cache/simple/simple_synchronous_entry.cc b/chromium/net/disk_cache/simple/simple_synchronous_entry.cc
index aac3d1143a3..2512656873d 100644
--- a/chromium/net/disk_cache/simple/simple_synchronous_entry.cc
+++ b/chromium/net/disk_cache/simple/simple_synchronous_entry.cc
@@ -16,7 +16,6 @@
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/sha1.h"
-#include "base/strings/stringprintf.h"
#include "base/timer/elapsed_timer.h"
#include "crypto/secure_hash.h"
#include "net/base/hash_value.h"
diff --git a/chromium/net/disk_cache/simple/simple_test_util.cc b/chromium/net/disk_cache/simple/simple_test_util.cc
index 9463b63eab4..0251f3ad914 100644
--- a/chromium/net/disk_cache/simple/simple_test_util.cc
+++ b/chromium/net/disk_cache/simple/simple_test_util.cc
@@ -37,8 +37,10 @@ bool RemoveKeySHA256FromEntry(const std::string& key,
File entry_file(entry_file_path, flags);
if (!entry_file.IsValid())
return false;
- int file_length = entry_file.GetLength();
+ int64_t file_length = entry_file.GetLength();
SimpleFileEOF eof_record;
+ if (file_length < static_cast<int64_t>(sizeof(eof_record)))
+ return false;
if (entry_file.Read(file_length - sizeof(eof_record),
reinterpret_cast<char*>(&eof_record),
sizeof(eof_record)) != sizeof(eof_record)) {
@@ -73,8 +75,10 @@ bool CorruptKeySHA256FromEntry(const std::string& key,
File entry_file(entry_file_path, flags);
if (!entry_file.IsValid())
return false;
- int file_length = entry_file.GetLength();
+ int64_t file_length = entry_file.GetLength();
SimpleFileEOF eof_record;
+ if (file_length < static_cast<int64_t>(sizeof(eof_record)))
+ return false;
if (entry_file.Read(file_length - sizeof(eof_record),
reinterpret_cast<char*>(&eof_record),
sizeof(eof_record)) != sizeof(eof_record)) {
@@ -105,8 +109,10 @@ bool CorruptStream0LengthFromEntry(const std::string& key,
File entry_file(entry_file_path, flags);
if (!entry_file.IsValid())
return false;
- int file_length = entry_file.GetLength();
+ int64_t file_length = entry_file.GetLength();
SimpleFileEOF eof_record;
+ if (file_length < static_cast<int64_t>(sizeof(eof_record)))
+ return false;
if (entry_file.Read(file_length - sizeof(eof_record),
reinterpret_cast<char*>(&eof_record),
sizeof(eof_record)) != sizeof(eof_record)) {