summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam <jam@chromium.org>2016-02-10 14:54:58 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-10 22:55:53 +0000
commit31963689d7f4b2242d4630b34b93852ed03e1dc3 (patch)
tree1539d93d80f6a610504a91b14c9873b729bc19c2
parentd00f5b6987750d39a5cc4859ee19c9ca89ed0cd9 (diff)
downloadchromium_src-31963689d7f4b2242d4630b34b93852ed03e1dc3.zip
chromium_src-31963689d7f4b2242d4630b34b93852ed03e1dc3.tar.gz
chromium_src-31963689d7f4b2242d4630b34b93852ed03e1dc3.tar.bz2
Use uint64_t instead of size_t inside the web cache manager code.
size_t is not sufficient when the browser is 32 bit and the renderers are 64 bits. BUG=581409,585382 Review URL: https://codereview.chromium.org/1685883004 Cr-Commit-Position: refs/heads/master@{#374760}
-rw-r--r--chrome/browser/renderer_host/chrome_render_message_filter.cc10
-rw-r--r--chrome/browser/renderer_host/chrome_render_message_filter.h7
-rw-r--r--chrome/common/render_messages.cc36
-rw-r--r--chrome/common/render_messages.h21
-rw-r--r--chrome/renderer/chrome_render_process_observer.cc7
-rw-r--r--components/web_cache/browser/web_cache_manager.cc138
-rw-r--r--components/web_cache/browser/web_cache_manager.h50
-rw-r--r--components/web_cache/browser/web_cache_manager_unittest.cc134
-rw-r--r--components/web_cache/common/web_cache_messages.h6
-rw-r--r--components/web_cache/renderer/web_cache_render_process_observer.cc16
-rw-r--r--components/web_cache/renderer/web_cache_render_process_observer.h6
11 files changed, 223 insertions, 208 deletions
diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc
index 056d6a8..1a48364 100644
--- a/chrome/browser/renderer_host/chrome_render_message_filter.cc
+++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc
@@ -39,7 +39,6 @@
#endif
using content::BrowserThread;
-using blink::WebCache;
namespace {
@@ -130,9 +129,14 @@ void ChromeRenderMessageFilter::OnPreconnect(const GURL& url,
}
void ChromeRenderMessageFilter::OnUpdatedCacheStats(
- const WebCache::UsageStats& stats) {
+ uint64_t min_dead_capacity,
+ uint64_t max_dead_capacity,
+ uint64_t capacity,
+ uint64_t live_size,
+ uint64_t dead_size) {
web_cache::WebCacheManager::GetInstance()->ObserveStats(
- render_process_id_, stats);
+ render_process_id_, min_dead_capacity, max_dead_capacity, capacity,
+ live_size, dead_size);
}
void ChromeRenderMessageFilter::OnAllowDatabase(
diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.h b/chrome/browser/renderer_host/chrome_render_message_filter.h
index 64b46bd..97bf627 100644
--- a/chrome/browser/renderer_host/chrome_render_message_filter.h
+++ b/chrome/browser/renderer_host/chrome_render_message_filter.h
@@ -12,7 +12,6 @@
#include "base/macros.h"
#include "base/sequenced_task_runner_helpers.h"
#include "content/public/browser/browser_message_filter.h"
-#include "third_party/WebKit/public/web/WebCache.h"
class GURL;
class Profile;
@@ -52,7 +51,11 @@ class ChromeRenderMessageFilter : public content::BrowserMessageFilter {
void OnDnsPrefetch(const network_hints::LookupRequest& request);
void OnPreconnect(const GURL& url, bool allow_credentials, int count);
- void OnUpdatedCacheStats(const blink::WebCache::UsageStats& stats);
+ void OnUpdatedCacheStats(uint64_t min_capacity,
+ uint64_t max_capacity,
+ uint64_t capacity,
+ uint64_t live_size,
+ uint64_t dead_size);
void OnAllowDatabase(int render_frame_id,
const GURL& origin_url,
diff --git a/chrome/common/render_messages.cc b/chrome/common/render_messages.cc
index 7e30f25..d108f42 100644
--- a/chrome/common/render_messages.cc
+++ b/chrome/common/render_messages.cc
@@ -28,40 +28,4 @@ void ParamTraits<ContentSettingsPattern>::Log(
l->append(">");
}
-void ParamTraits<blink::WebCache::UsageStats>::Write(
- base::Pickle* m, const blink::WebCache::UsageStats& u) {
- m->WriteUInt64(static_cast<uint64_t>(u.minDeadCapacity));
- m->WriteUInt64(static_cast<uint64_t>(u.maxDeadCapacity));
- m->WriteUInt64(static_cast<uint64_t>(u.capacity));
- m->WriteUInt64(static_cast<uint64_t>(u.liveSize));
- m->WriteUInt64(static_cast<uint64_t>(u.deadSize));
-}
-
-bool ParamTraits<blink::WebCache::UsageStats>::Read(
- const base::Pickle* m,
- base::PickleIterator* iter,
- blink::WebCache::UsageStats* u) {
- uint64_t min_capacity, max_capacity, capacity, live_size, dead_size;
- if (!iter->ReadUInt64(&min_capacity) ||
- !iter->ReadUInt64(&max_capacity) ||
- !iter->ReadUInt64(&capacity) ||
- !iter->ReadUInt64(&live_size) ||
- !iter->ReadUInt64(&dead_size)) {
- return false;
- }
-
- u->minDeadCapacity = base::checked_cast<size_t>(min_capacity);
- u->maxDeadCapacity = base::checked_cast<size_t>(max_capacity);
- u->capacity = base::checked_cast<size_t>(capacity);
- u->liveSize = base::checked_cast<size_t>(live_size);
- u->deadSize = base::checked_cast<size_t>(dead_size);
-
- return true;
-}
-
-void ParamTraits<blink::WebCache::UsageStats>::Log(
- const blink::WebCache::UsageStats& p, std::string* l) {
- l->append("<blink::WebCache::UsageStats>");
-}
-
} // namespace IPC
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 61526f0..72ceba5 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -24,7 +24,6 @@
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_platform_file.h"
#include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerPromptReply.h"
-#include "third_party/WebKit/public/web/WebCache.h"
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
// Singly-included section for enums and custom IPC traits.
@@ -56,18 +55,6 @@ struct ParamTraits<ContentSettingsPattern> {
static void Log(const param_type& p, std::string* l);
};
-// Manual traits since this struct uses size_t and it's in Blink, so avoid
-// changing Blink due to IPC differences.
-template <>
-struct ParamTraits<blink::WebCache::UsageStats> {
- typedef blink::WebCache::UsageStats param_type;
- static void Write(base::Pickle* m, const param_type& u);
- static bool Read(const base::Pickle* m,
- base::PickleIterator* iter,
- param_type* u);
- static void Log(const param_type& p, std::string* l);
-};
-
} // namespace IPC
#endif // CHROME_COMMON_RENDER_MESSAGES_H_
@@ -365,8 +352,12 @@ IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_LoadOfflineCopy, GURL /* url */)
// Misc messages
// These are messages sent from the renderer to the browser process.
-IPC_MESSAGE_CONTROL1(ChromeViewHostMsg_UpdatedCacheStats,
- blink::WebCache::UsageStats /* stats */)
+IPC_MESSAGE_CONTROL5(ChromeViewHostMsg_UpdatedCacheStats,
+ uint64_t /* min_dead_capacity */,
+ uint64_t /* max_dead_capacity */,
+ uint64_t /* capacity */,
+ uint64_t /* live_size */,
+ uint64_t /* dead_size */)
// Sent by the renderer process to check whether access to FileSystem is
// granted by content settings.
diff --git a/chrome/renderer/chrome_render_process_observer.cc b/chrome/renderer/chrome_render_process_observer.cc
index 0ed2604..6b2c147 100644
--- a/chrome/renderer/chrome_render_process_observer.cc
+++ b/chrome/renderer/chrome_render_process_observer.cc
@@ -116,7 +116,12 @@ class RendererResourceDelegate : public content::ResourceDispatcherDelegate {
void InformHostOfCacheStats() {
WebCache::UsageStats stats;
WebCache::getUsageStats(&stats);
- RenderThread::Get()->Send(new ChromeViewHostMsg_UpdatedCacheStats(stats));
+ RenderThread::Get()->Send(new ChromeViewHostMsg_UpdatedCacheStats(
+ static_cast<uint64_t>(stats.minDeadCapacity),
+ static_cast<uint64_t>(stats.maxDeadCapacity),
+ static_cast<uint64_t>(stats.capacity),
+ static_cast<uint64_t>(stats.liveSize),
+ static_cast<uint64_t>(stats.deadSize)));
}
base::WeakPtrFactory<RendererResourceDelegate> weak_factory_;
diff --git a/components/web_cache/browser/web_cache_manager.cc b/components/web_cache/browser/web_cache_manager.cc
index c325a2f..66076e9 100644
--- a/components/web_cache/browser/web_cache_manager.cc
+++ b/components/web_cache/browser/web_cache_manager.cc
@@ -26,7 +26,6 @@
using base::Time;
using base::TimeDelta;
-using blink::WebCache;
namespace web_cache {
@@ -126,20 +125,24 @@ void WebCacheManager::ObserveActivity(int renderer_id) {
}
void WebCacheManager::ObserveStats(int renderer_id,
- const WebCache::UsageStats& stats) {
+ uint64_t min_dead_capacity,
+ uint64_t max_dead_capacity,
+ uint64_t capacity,
+ uint64_t live_size,
+ uint64_t dead_size) {
StatsMap::iterator entry = stats_.find(renderer_id);
if (entry == stats_.end())
return; // We might see stats for a renderer that has been destroyed.
// Record the updated stats.
- entry->second.capacity = stats.capacity;
- entry->second.deadSize = stats.deadSize;
- entry->second.liveSize = stats.liveSize;
- entry->second.maxDeadCapacity = stats.maxDeadCapacity;
- entry->second.minDeadCapacity = stats.minDeadCapacity;
+ entry->second.capacity = capacity;
+ entry->second.dead_size = dead_size;
+ entry->second.live_size = live_size;
+ entry->second.max_dead_capacity = max_dead_capacity;
+ entry->second.min_dead_capacity = min_dead_capacity;
}
-void WebCacheManager::SetGlobalSizeLimit(size_t bytes) {
+void WebCacheManager::SetGlobalSizeLimit(uint64_t bytes) {
global_size_limit_ = bytes;
ReviseAllocationStrategyLater();
}
@@ -180,49 +183,48 @@ void WebCacheManager::Observe(int type,
}
// static
-size_t WebCacheManager::GetDefaultGlobalSizeLimit() {
+uint64_t WebCacheManager::GetDefaultGlobalSizeLimit() {
return GetDefaultCacheSize();
}
void WebCacheManager::GatherStats(const std::set<int>& renderers,
- WebCache::UsageStats* stats) {
- DCHECK(stats);
-
- memset(stats, 0, sizeof(WebCache::UsageStats));
+ uint64_t* capacity,
+ uint64_t* live_size,
+ uint64_t* dead_size) {
+ *capacity = *live_size = *dead_size = 0;
std::set<int>::const_iterator iter = renderers.begin();
while (iter != renderers.end()) {
StatsMap::iterator elmt = stats_.find(*iter);
if (elmt != stats_.end()) {
- stats->minDeadCapacity += elmt->second.minDeadCapacity;
- stats->maxDeadCapacity += elmt->second.maxDeadCapacity;
- stats->capacity += elmt->second.capacity;
- stats->liveSize += elmt->second.liveSize;
- stats->deadSize += elmt->second.deadSize;
+ *capacity += elmt->second.capacity;
+ *live_size += elmt->second.live_size;
+ *dead_size += elmt->second.dead_size;
}
++iter;
}
}
// static
-size_t WebCacheManager::GetSize(AllocationTactic tactic,
- const WebCache::UsageStats& stats) {
+uint64_t WebCacheManager::GetSize(AllocationTactic tactic,
+ uint64_t live_size,
+ uint64_t dead_size) {
switch (tactic) {
case DIVIDE_EVENLY:
// We aren't going to reserve any space for existing objects.
return 0;
case KEEP_CURRENT_WITH_HEADROOM:
// We need enough space for our current objects, plus some headroom.
- return 3 * GetSize(KEEP_CURRENT, stats) / 2;
+ return 3 * GetSize(KEEP_CURRENT, live_size, dead_size) / 2;
case KEEP_CURRENT:
// We need enough space to keep our current objects.
- return stats.liveSize + stats.deadSize;
+ return live_size + dead_size;
case KEEP_LIVE_WITH_HEADROOM:
// We need enough space to keep out live resources, plus some headroom.
- return 3 * GetSize(KEEP_LIVE, stats) / 2;
+ return 3 * GetSize(KEEP_LIVE, live_size, dead_size) / 2;
case KEEP_LIVE:
// We need enough space to keep our live resources.
- return stats.liveSize;
+ return live_size;
default:
NOTREACHED() << "Unknown cache allocation tactic";
return 0;
@@ -231,36 +233,40 @@ size_t WebCacheManager::GetSize(AllocationTactic tactic,
bool WebCacheManager::AttemptTactic(
AllocationTactic active_tactic,
- const WebCache::UsageStats& active_stats,
+ uint64_t active_live_size,
+ uint64_t active_dead_size,
AllocationTactic inactive_tactic,
- const WebCache::UsageStats& inactive_stats,
+ uint64_t inactive_live_size,
+ uint64_t inactive_dead_size,
AllocationStrategy* strategy) {
DCHECK(strategy);
- size_t active_size = GetSize(active_tactic, active_stats);
- size_t inactive_size = GetSize(inactive_tactic, inactive_stats);
+ uint64_t active_size = GetSize(active_tactic, active_live_size,
+ active_dead_size);
+ uint64_t inactive_size = GetSize(inactive_tactic, inactive_live_size,
+ inactive_dead_size);
// Give up if we don't have enough space to use this tactic.
if (global_size_limit_ < active_size + inactive_size)
return false;
// Compute the unreserved space available.
- size_t total_extra = global_size_limit_ - (active_size + inactive_size);
+ uint64_t total_extra = global_size_limit_ - (active_size + inactive_size);
// The plan for the extra space is to divide it evenly amoung the active
// renderers.
- size_t shares = active_renderers_.size();
+ uint64_t shares = active_renderers_.size();
// The inactive renderers get one share of the extra memory to be divided
// among themselves.
- size_t inactive_extra = 0;
+ uint64_t inactive_extra = 0;
if (!inactive_renderers_.empty()) {
++shares;
inactive_extra = total_extra / shares;
}
// The remaining memory is allocated to the active renderers.
- size_t active_extra = total_extra - inactive_extra;
+ uint64_t active_extra = total_extra - inactive_extra;
// Actually compute the allocations for each renderer.
AddToStrategy(active_renderers_, active_tactic, active_extra, strategy);
@@ -272,7 +278,7 @@ bool WebCacheManager::AttemptTactic(
void WebCacheManager::AddToStrategy(const std::set<int>& renderers,
AllocationTactic tactic,
- size_t extra_bytes_to_allocate,
+ uint64_t extra_bytes_to_allocate,
AllocationStrategy* strategy) {
DCHECK(strategy);
@@ -282,16 +288,18 @@ void WebCacheManager::AddToStrategy(const std::set<int>& renderers,
return;
// Divide the extra memory evenly among the renderers.
- size_t extra_each = extra_bytes_to_allocate / renderers.size();
+ uint64_t extra_each = extra_bytes_to_allocate / renderers.size();
std::set<int>::const_iterator iter = renderers.begin();
while (iter != renderers.end()) {
- size_t cache_size = extra_each;
+ uint64_t cache_size = extra_each;
// Add in the space required to implement |tactic|.
StatsMap::iterator elmt = stats_.find(*iter);
- if (elmt != stats_.end())
- cache_size += GetSize(tactic, elmt->second);
+ if (elmt != stats_.end()) {
+ cache_size += GetSize(tactic, elmt->second.live_size,
+ elmt->second.dead_size);
+ }
// Record the allocation in our strategy.
strategy->push_back(Allocation(*iter, cache_size));
@@ -307,17 +315,19 @@ void WebCacheManager::EnactStrategy(const AllocationStrategy& strategy) {
content::RenderProcessHost::FromID(allocation->first);
if (host) {
// This is the capacity this renderer has been allocated.
- uint32_t capacity = allocation->second;
+ uint64_t capacity = allocation->second;
// We don't reserve any space for dead objects in the cache. Instead, we
// prefer to keep live objects around. There is probably some performance
// tuning to be done here.
- uint32_t min_dead_capacity = 0;
+ uint64_t min_dead_capacity = 0;
// We allow the dead objects to consume up to half of the cache capacity.
- uint32_t max_dead_capacity = capacity / 2;
- if (base::SysInfo::IsLowEndDevice())
- max_dead_capacity = std::min(512 * 1024u, max_dead_capacity);
+ uint64_t max_dead_capacity = capacity / 2;
+ if (base::SysInfo::IsLowEndDevice()) {
+ max_dead_capacity = std::min(static_cast<uint64_t>(512 * 1024u),
+ max_dead_capacity);
+ }
host->Send(new WebCacheMsg_SetCacheCapacities(min_dead_capacity,
max_dead_capacity,
@@ -353,25 +363,27 @@ void WebCacheManager::ReviseAllocationStrategy() {
FindInactiveRenderers();
// Gather statistics
- WebCache::UsageStats active;
- WebCache::UsageStats inactive;
- GatherStats(active_renderers_, &active);
- GatherStats(inactive_renderers_, &inactive);
+ uint64_t active_capacity, active_live_size, active_dead_size,
+ inactive_capacity, inactive_live_size, inactive_dead_size;
+ GatherStats(active_renderers_, &active_capacity, &active_live_size,
+ &active_dead_size);
+ GatherStats(inactive_renderers_, &inactive_capacity, &inactive_live_size,
+ &inactive_dead_size);
UMA_HISTOGRAM_COUNTS_100("Cache.ActiveTabs", active_renderers_.size());
UMA_HISTOGRAM_COUNTS_100("Cache.InactiveTabs", inactive_renderers_.size());
UMA_HISTOGRAM_MEMORY_MB("Cache.ActiveCapacityMB",
- active.capacity / 1024 / 1024);
+ active_capacity / 1024 / 1024);
UMA_HISTOGRAM_MEMORY_MB("Cache.ActiveDeadSizeMB",
- active.deadSize / 1024 / 1024);
+ active_dead_size / 1024 / 1024);
UMA_HISTOGRAM_MEMORY_MB("Cache.ActiveLiveSizeMB",
- active.liveSize / 1024 / 1024);
+ active_live_size / 1024 / 1024);
UMA_HISTOGRAM_MEMORY_MB("Cache.InactiveCapacityMB",
- inactive.capacity / 1024 / 1024);
+ inactive_capacity / 1024 / 1024);
UMA_HISTOGRAM_MEMORY_MB("Cache.InactiveDeadSizeMB",
- inactive.deadSize / 1024 / 1024);
+ inactive_dead_size / 1024 / 1024);
UMA_HISTOGRAM_MEMORY_MB("Cache.InactiveLiveSizeMB",
- inactive.liveSize / 1024 / 1024);
+ inactive_live_size / 1024 / 1024);
// Compute an allocation strategy.
//
@@ -389,23 +401,29 @@ void WebCacheManager::ReviseAllocationStrategy() {
AllocationStrategy strategy;
if ( // Ideally, we'd like to give the active renderers some headroom and
// keep all our current objects.
- AttemptTactic(KEEP_CURRENT_WITH_HEADROOM, active,
- KEEP_CURRENT, inactive, &strategy) ||
+ AttemptTactic(KEEP_CURRENT_WITH_HEADROOM, active_live_size,
+ active_dead_size, KEEP_CURRENT, inactive_live_size,
+ inactive_dead_size, &strategy) ||
// If we can't have that, then we first try to evict the dead objects in
// the caches of inactive renderers.
- AttemptTactic(KEEP_CURRENT_WITH_HEADROOM, active,
- KEEP_LIVE, inactive, &strategy) ||
+ AttemptTactic(KEEP_CURRENT_WITH_HEADROOM, active_live_size,
+ active_dead_size, KEEP_LIVE, inactive_live_size,
+ inactive_dead_size, &strategy) ||
// Next, we try to keep the live objects in the active renders (with some
// room for new objects) and give whatever is left to the inactive
// renderers.
- AttemptTactic(KEEP_LIVE_WITH_HEADROOM, active,
- DIVIDE_EVENLY, inactive, &strategy) ||
+ AttemptTactic(KEEP_LIVE_WITH_HEADROOM, active_live_size,
+ active_dead_size, DIVIDE_EVENLY, inactive_live_size,
+ inactive_dead_size, &strategy) ||
// If we've gotten this far, then we are very tight on memory. Let's try
// to at least keep around the live objects for the active renderers.
- AttemptTactic(KEEP_LIVE, active, DIVIDE_EVENLY, inactive, &strategy) ||
+ AttemptTactic(KEEP_LIVE, active_live_size, active_dead_size,
+ DIVIDE_EVENLY, inactive_live_size, inactive_dead_size,
+ &strategy) ||
// We're basically out of memory. The best we can do is just divide up
// what we have and soldier on.
- AttemptTactic(DIVIDE_EVENLY, active, DIVIDE_EVENLY, inactive,
+ AttemptTactic(DIVIDE_EVENLY, active_live_size, active_dead_size,
+ DIVIDE_EVENLY, inactive_live_size, inactive_dead_size,
&strategy)) {
// Having found a workable strategy, we enact it.
EnactStrategy(strategy);
diff --git a/components/web_cache/browser/web_cache_manager.h b/components/web_cache/browser/web_cache_manager.h
index 2d6d300..a0c1907 100644
--- a/components/web_cache/browser/web_cache_manager.h
+++ b/components/web_cache/browser/web_cache_manager.h
@@ -21,7 +21,6 @@
#include "base/time/time.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-#include "third_party/WebKit/public/web/WebCache.h"
namespace base {
template<typename Type>
@@ -32,10 +31,15 @@ class PrefRegistrySimple;
namespace web_cache {
+// Note: memory usage uses uint64_t because potentially the browser could be
+// 32 bit and the renderers 64 bits.
class WebCacheManager : public content::NotificationObserver {
friend class WebCacheManagerTest;
FRIEND_TEST_ALL_PREFIXES(
WebCacheManagerTest,
+ GatherStatsTest);
+ FRIEND_TEST_ALL_PREFIXES(
+ WebCacheManagerTest,
CallRemoveRendererAndObserveActivityInAnyOrderShouldNotCrashTest_1);
FRIEND_TEST_ALL_PREFIXES(
WebCacheManagerTest,
@@ -79,14 +83,18 @@ class WebCacheManager : public content::NotificationObserver {
// Periodically, renderers should inform the cache manager of their current
// statistics. The more up-to-date the cache manager's statistics, the
// better it can allocate cache resources.
- void ObserveStats(
- int renderer_id, const blink::WebCache::UsageStats& stats);
+ void ObserveStats(int renderer_id,
+ uint64_t min_dead_capacity,
+ uint64_t max_dead_capacity,
+ uint64_t capacity,
+ uint64_t live_size,
+ uint64_t dead_size);
// The global limit on the number of bytes in all the in-memory caches.
- size_t global_size_limit() const { return global_size_limit_; }
+ uint64_t global_size_limit() const { return global_size_limit_; }
// Sets the global size limit, forcing a recalculation of cache allocations.
- void SetGlobalSizeLimit(size_t bytes);
+ void SetGlobalSizeLimit(uint64_t bytes);
// Clears all in-memory caches.
void ClearCache();
@@ -105,23 +113,28 @@ class WebCacheManager : public content::NotificationObserver {
// Gets the default global size limit. This interrogates system metrics to
// tune the default size to the current system.
- static size_t GetDefaultGlobalSizeLimit();
+ static uint64_t GetDefaultGlobalSizeLimit();
protected:
// The amount of idle time before we consider a tab to be "inactive"
static const int kRendererInactiveThresholdMinutes = 5;
// Keep track of some renderer information.
- struct RendererInfo : blink::WebCache::UsageStats {
+ struct RendererInfo {
// The access time for this renderer.
base::Time access;
+ uint64_t min_dead_capacity;
+ uint64_t max_dead_capacity;
+ uint64_t capacity;
+ uint64_t live_size;
+ uint64_t dead_size;
};
typedef std::map<int, RendererInfo> StatsMap;
// An allocation is the number of bytes a specific renderer should use for
// its cache.
- typedef std::pair<int,size_t> Allocation;
+ typedef std::pair<int,uint64_t> Allocation;
// An allocation strategy is a list of allocations specifying the resources
// each renderer is permitted to consume for its cache.
@@ -172,15 +185,18 @@ class WebCacheManager : public content::NotificationObserver {
// Helper functions for devising an allocation strategy
// Add up all the stats from the given set of renderers and place the result
- // in |stats|.
+ // in the given parameters.
void GatherStats(const std::set<int>& renderers,
- blink::WebCache::UsageStats* stats);
+ uint64_t* capacity,
+ uint64_t* live_size,
+ uint64_t* dead_size);
// Get the amount of memory that would be required to implement |tactic|
// using the specified allocation tactic. This function defines the
// semantics for each of the tactics.
- static size_t GetSize(AllocationTactic tactic,
- const blink::WebCache::UsageStats& stats);
+ static uint64_t GetSize(AllocationTactic tactic,
+ uint64_t live_size,
+ uint64_t dead_size);
// Attempt to use the specified tactics to compute an allocation strategy
// and place the result in |strategy|. |active_stats| and |inactive_stats|
@@ -190,9 +206,11 @@ class WebCacheManager : public content::NotificationObserver {
// Returns |true| on success and |false| on failure. Does not modify
// |strategy| on failure.
bool AttemptTactic(AllocationTactic active_tactic,
- const blink::WebCache::UsageStats& active_stats,
+ uint64_t active_live_size,
+ uint64_t active_dead_size,
AllocationTactic inactive_tactic,
- const blink::WebCache::UsageStats& inactive_stats,
+ uint64_t inactive_live_size,
+ uint64_t inactive_dead_size,
AllocationStrategy* strategy);
// For each renderer in |renderers|, computes its allocation according to
@@ -200,7 +218,7 @@ class WebCacheManager : public content::NotificationObserver {
// is divided evenly among the renderers.
void AddToStrategy(const std::set<int>& renderers,
AllocationTactic tactic,
- size_t extra_bytes_to_allocate,
+ uint64_t extra_bytes_to_allocate,
AllocationStrategy* strategy);
// Enact an allocation strategy by informing the renderers of their
@@ -223,7 +241,7 @@ class WebCacheManager : public content::NotificationObserver {
void FindInactiveRenderers();
// The global size limit for all in-memory caches.
- size_t global_size_limit_;
+ uint64_t global_size_limit_;
// Maps every renderer_id our most recent copy of its statistics.
StatsMap stats_;
diff --git a/components/web_cache/browser/web_cache_manager_unittest.cc b/components/web_cache/browser/web_cache_manager_unittest.cc
index 826552e..2989021 100644
--- a/components/web_cache/browser/web_cache_manager_unittest.cc
+++ b/components/web_cache/browser/web_cache_manager_unittest.cc
@@ -14,7 +14,6 @@
using base::Time;
using base::TimeDelta;
using content::BrowserThread;
-using blink::WebCache;
namespace web_cache {
@@ -26,8 +25,8 @@ class WebCacheManagerTest : public testing::Test {
static const int kRendererID;
static const int kRendererID2;
- static const WebCache::UsageStats kStats;
- static const WebCache::UsageStats kStats2;
+ static const WebCacheManager::RendererInfo kStats;
+ static const WebCacheManager::RendererInfo kStats2;
WebCacheManagerTest()
: ui_thread_(BrowserThread::UI, &message_loop_) {
@@ -53,38 +52,46 @@ class WebCacheManagerTest : public testing::Test {
}
static void GatherStats(WebCacheManager* h,
std::set<int> renderers,
- WebCache::UsageStats* stats) {
- h->GatherStats(renderers, stats);
+ WebCacheManager::RendererInfo* stats) {
+ memset(stats, 0, sizeof(WebCacheManager::RendererInfo));
+ h->GatherStats(renderers, &stats->capacity, &stats->live_size,
+ &stats->dead_size);
}
- static size_t GetSize(int tactic,
- const WebCache::UsageStats& stats) {
+ static uint64_t GetSize(int tactic,
+ const WebCacheManager::RendererInfo& stats) {
return WebCacheManager::GetSize(
- static_cast<WebCacheManager::AllocationTactic>(tactic), stats);
+ static_cast<WebCacheManager::AllocationTactic>(tactic), stats.live_size,
+ stats.dead_size);
}
static bool AttemptTactic(WebCacheManager* h,
int active_tactic,
- const WebCache::UsageStats& active_stats,
+ const WebCacheManager::RendererInfo& active_stats,
int inactive_tactic,
- const WebCache::UsageStats& inactive_stats,
- std::list< std::pair<int,size_t> >* strategy) {
+ const WebCacheManager::RendererInfo& inactive_stats,
+ std::list<std::pair<int, uint64_t>>* strategy) {
return h->AttemptTactic(
static_cast<WebCacheManager::AllocationTactic>(active_tactic),
- active_stats,
+ active_stats.live_size, active_stats.dead_size,
static_cast<WebCacheManager::AllocationTactic>(inactive_tactic),
- inactive_stats,
- strategy);
+ inactive_stats.live_size, inactive_stats.dead_size, strategy);
}
static void AddToStrategy(WebCacheManager* h,
std::set<int> renderers,
int tactic,
- size_t extra_bytes_to_allocate,
- std::list< std::pair<int,size_t> >* strategy) {
+ uint64_t extra_bytes_to_allocate,
+ std::list<std::pair<int, uint64_t>>* strategy) {
h->AddToStrategy(renderers,
static_cast<WebCacheManager::AllocationTactic>(tactic),
extra_bytes_to_allocate,
strategy);
}
+ static bool RendererInfoEqual(const WebCacheManager::RendererInfo& lhs,
+ const WebCacheManager::RendererInfo& rhs) {
+ return lhs.capacity == rhs.capacity && lhs.live_size == rhs.live_size &&
+ lhs.dead_size == rhs.dead_size;
+ }
+
enum {
DIVIDE_EVENLY = WebCacheManager::DIVIDE_EVENLY,
KEEP_CURRENT_WITH_HEADROOM = WebCacheManager::KEEP_CURRENT_WITH_HEADROOM,
@@ -108,27 +115,14 @@ const int WebCacheManagerTest::kRendererID = 146;
const int WebCacheManagerTest::kRendererID2 = 245;
// static
-const WebCache::UsageStats WebCacheManagerTest::kStats = {
- 0,
- 1024 * 1024,
- 1024 * 1024,
- 256 * 1024,
- 512,
- };
+const WebCacheManager::RendererInfo WebCacheManagerTest::kStats = {
+ base::Time(), 0, 1024 * 1024, 1024 * 1024, 256 * 1024, 512,
+};
// static
-const WebCache::UsageStats WebCacheManagerTest::kStats2 = {
- 0,
- 2 * 1024 * 1024,
- 2 * 1024 * 1024,
- 2 * 256 * 1024,
- 2 * 512,
- };
-
-static bool operator==(const WebCache::UsageStats& lhs,
- const WebCache::UsageStats& rhs) {
- return !::memcmp(&lhs, &rhs, sizeof(WebCache::UsageStats));
-}
+const WebCacheManager::RendererInfo WebCacheManagerTest::kStats2 = {
+ base::Time(), 0, 2 * 1024 * 1024, 2 * 1024 * 1024, 2 * 256 * 1024, 2 * 512,
+};
TEST_F(WebCacheManagerTest, AddRemoveRendererTest) {
EXPECT_EQ(0U, active_renderers(manager()).size());
@@ -166,16 +160,18 @@ TEST_F(WebCacheManagerTest, ObserveStatsTest) {
EXPECT_EQ(1U, stats(manager()).size());
- manager()->ObserveStats(kRendererID, kStats);
+ manager()->ObserveStats(kRendererID, kStats.min_dead_capacity,
+ kStats.max_dead_capacity, kStats.capacity,
+ kStats.live_size, kStats.dead_size);
EXPECT_EQ(1U, stats(manager()).size());
- EXPECT_TRUE(kStats == stats(manager())[kRendererID]);
+ EXPECT_TRUE(RendererInfoEqual(kStats, stats(manager())[kRendererID]));
manager()->Remove(kRendererID);
}
TEST_F(WebCacheManagerTest, SetGlobalSizeLimitTest) {
- size_t limit = manager()->GetDefaultGlobalSizeLimit();
+ uint64_t limit = manager()->GetDefaultGlobalSizeLimit();
manager()->SetGlobalSizeLimit(limit);
EXPECT_EQ(limit, manager()->global_size_limit());
@@ -187,28 +183,32 @@ TEST_F(WebCacheManagerTest, GatherStatsTest) {
manager()->Add(kRendererID);
manager()->Add(kRendererID2);
- manager()->ObserveStats(kRendererID, kStats);
- manager()->ObserveStats(kRendererID2, kStats2);
+ manager()->ObserveStats(kRendererID, kStats.min_dead_capacity,
+ kStats.max_dead_capacity, kStats.capacity,
+ kStats.live_size, kStats.dead_size);
+ manager()->ObserveStats(kRendererID2, kStats2.min_dead_capacity,
+ kStats2.max_dead_capacity, kStats2.capacity,
+ kStats2.live_size, kStats2.dead_size);
std::set<int> renderer_set;
renderer_set.insert(kRendererID);
- WebCache::UsageStats stats;
+ WebCacheManager::RendererInfo stats;
GatherStats(manager(), renderer_set, &stats);
- EXPECT_TRUE(kStats == stats);
+ EXPECT_TRUE(RendererInfoEqual(kStats, stats));
renderer_set.insert(kRendererID2);
GatherStats(manager(), renderer_set, &stats);
- WebCache::UsageStats expected_stats = kStats;
- expected_stats.minDeadCapacity += kStats2.minDeadCapacity;
- expected_stats.maxDeadCapacity += kStats2.maxDeadCapacity;
+ WebCacheManager::RendererInfo expected_stats = kStats;
+ expected_stats.min_dead_capacity += kStats2.min_dead_capacity;
+ expected_stats.max_dead_capacity += kStats2.max_dead_capacity;
expected_stats.capacity += kStats2.capacity;
- expected_stats.liveSize += kStats2.liveSize;
- expected_stats.deadSize += kStats2.deadSize;
+ expected_stats.live_size += kStats2.live_size;
+ expected_stats.dead_size += kStats2.dead_size;
- EXPECT_TRUE(expected_stats == stats);
+ EXPECT_TRUE(RendererInfoEqual(expected_stats, stats));
manager()->Remove(kRendererID);
manager()->Remove(kRendererID2);
@@ -229,11 +229,15 @@ TEST_F(WebCacheManagerTest, AttemptTacticTest) {
manager()->ObserveActivity(kRendererID);
SimulateInactivity(manager(), kRendererID2);
- manager()->ObserveStats(kRendererID, kStats);
- manager()->ObserveStats(kRendererID2, kStats2);
+ manager()->ObserveStats(kRendererID, kStats.min_dead_capacity,
+ kStats.max_dead_capacity, kStats.capacity,
+ kStats.live_size, kStats.dead_size);
+ manager()->ObserveStats(kRendererID2, kStats2.min_dead_capacity,
+ kStats2.max_dead_capacity, kStats2.capacity,
+ kStats2.live_size, kStats2.dead_size);
- manager()->SetGlobalSizeLimit(kStats.liveSize + kStats.deadSize +
- kStats2.liveSize + kStats2.deadSize/2);
+ manager()->SetGlobalSizeLimit(kStats.live_size + kStats.dead_size +
+ kStats2.live_size + kStats2.dead_size / 2);
AllocationStrategy strategy;
@@ -256,9 +260,9 @@ TEST_F(WebCacheManagerTest, AttemptTacticTest) {
AllocationStrategy::iterator iter = strategy.begin();
while (iter != strategy.end()) {
if (iter->first == kRendererID)
- EXPECT_LE(kStats.liveSize + kStats.deadSize, iter->second);
+ EXPECT_LE(kStats.live_size + kStats.dead_size, iter->second);
else if (iter->first == kRendererID2)
- EXPECT_LE(kStats2.liveSize, iter->second);
+ EXPECT_LE(kStats2.live_size, iter->second);
else
ADD_FAILURE(); // Unexpected entry in strategy.
++iter;
@@ -276,10 +280,14 @@ TEST_F(WebCacheManagerTest, AddToStrategyTest) {
renderer_set.insert(kRendererID);
renderer_set.insert(kRendererID2);
- manager()->ObserveStats(kRendererID, kStats);
- manager()->ObserveStats(kRendererID2, kStats2);
+ manager()->ObserveStats(kRendererID, kStats.min_dead_capacity,
+ kStats.max_dead_capacity, kStats.capacity,
+ kStats.live_size, kStats.dead_size);
+ manager()->ObserveStats(kRendererID2, kStats2.min_dead_capacity,
+ kStats2.max_dead_capacity, kStats2.capacity,
+ kStats2.live_size, kStats2.dead_size);
- const size_t kExtraBytesToAllocate = 10 * 1024;
+ const uint64_t kExtraBytesToAllocate = 10 * 1024;
AllocationStrategy strategy;
AddToStrategy(manager(),
@@ -290,23 +298,23 @@ TEST_F(WebCacheManagerTest, AddToStrategyTest) {
EXPECT_EQ(2U, strategy.size());
- size_t total_bytes = 0;
+ uint64_t total_bytes = 0;
AllocationStrategy::iterator iter = strategy.begin();
while (iter != strategy.end()) {
total_bytes += iter->second;
if (iter->first == kRendererID)
- EXPECT_LE(kStats.liveSize + kStats.deadSize, iter->second);
+ EXPECT_LE(kStats.live_size + kStats.dead_size, iter->second);
else if (iter->first == kRendererID2)
- EXPECT_LE(kStats2.liveSize + kStats2.deadSize, iter->second);
+ EXPECT_LE(kStats2.live_size + kStats2.dead_size, iter->second);
else
ADD_FAILURE(); // Unexpected entry in strategy.
++iter;
}
- size_t expected_total_bytes = kExtraBytesToAllocate +
- kStats.liveSize + kStats.deadSize +
- kStats2.liveSize + kStats2.deadSize;
+ uint64_t expected_total_bytes = kExtraBytesToAllocate + kStats.live_size +
+ kStats.dead_size + kStats2.live_size +
+ kStats2.dead_size;
EXPECT_GE(expected_total_bytes, total_bytes);
diff --git a/components/web_cache/common/web_cache_messages.h b/components/web_cache/common/web_cache_messages.h
index 58f9c70..44f48b6 100644
--- a/components/web_cache/common/web_cache_messages.h
+++ b/components/web_cache/common/web_cache_messages.h
@@ -17,9 +17,9 @@
// Tells the renderer to set its maximum cache size to the supplied value.
IPC_MESSAGE_CONTROL3(WebCacheMsg_SetCacheCapacities,
- uint32_t /* min_dead_capacity */,
- uint32_t /* max_dead_capacity */,
- uint32_t /* capacity */)
+ uint64_t /* min_dead_capacity */,
+ uint64_t /* max_dead_capacity */,
+ uint64_t /* capacity */)
// Tells the renderer to clear the cache.
IPC_MESSAGE_CONTROL1(WebCacheMsg_ClearCache,
diff --git a/components/web_cache/renderer/web_cache_render_process_observer.cc b/components/web_cache/renderer/web_cache_render_process_observer.cc
index a944ba1..1d12253 100644
--- a/components/web_cache/renderer/web_cache_render_process_observer.cc
+++ b/components/web_cache/renderer/web_cache_render_process_observer.cc
@@ -6,6 +6,7 @@
#include <limits>
+#include "base/numerics/safe_conversions.h"
#include "components/web_cache/common/web_cache_messages.h"
#include "third_party/WebKit/public/web/WebCache.h"
@@ -60,18 +61,21 @@ void WebCacheRenderProcessObserver::OnRenderProcessShutdown() {
}
void WebCacheRenderProcessObserver::OnSetCacheCapacities(
- uint32_t min_dead_capacity,
- uint32_t max_dead_capacity,
- uint32_t capacity) {
+ uint64_t min_dead_capacity,
+ uint64_t max_dead_capacity,
+ uint64_t capacity64) {
+ size_t min_dead_capacity2 = base::checked_cast<size_t>(min_dead_capacity);
+ size_t max_dead_capacity2 = base::checked_cast<size_t>(max_dead_capacity);
+ size_t capacity = base::checked_cast<size_t>(capacity64);
if (!webkit_initialized_) {
- pending_cache_min_dead_capacity_ = min_dead_capacity;
- pending_cache_max_dead_capacity_ = max_dead_capacity;
+ pending_cache_min_dead_capacity_ = min_dead_capacity2;
+ pending_cache_max_dead_capacity_ = max_dead_capacity2;
pending_cache_capacity_ = capacity;
return;
}
WebCache::setCapacities(
- min_dead_capacity, max_dead_capacity, capacity);
+ min_dead_capacity2, max_dead_capacity2, capacity);
}
void WebCacheRenderProcessObserver::OnClearCache(bool on_navigation) {
diff --git a/components/web_cache/renderer/web_cache_render_process_observer.h b/components/web_cache/renderer/web_cache_render_process_observer.h
index b683fa7..714ef23 100644
--- a/components/web_cache/renderer/web_cache_render_process_observer.h
+++ b/components/web_cache/renderer/web_cache_render_process_observer.h
@@ -31,9 +31,9 @@ class WebCacheRenderProcessObserver : public content::RenderProcessObserver {
void OnRenderProcessShutdown() override;
// Message handlers.
- void OnSetCacheCapacities(uint32_t min_dead_capacity,
- uint32_t max_dead_capacity,
- uint32_t capacity);
+ void OnSetCacheCapacities(uint64_t min_dead_capacity,
+ uint64_t max_dead_capacity,
+ uint64_t capacity);
// If |on_navigation| is true, the clearing is delayed until the next
// navigation event.
void OnClearCache(bool on_navigation);