Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This is the browser side of the cache manager, it tracks the activity of the | 5 // This is the browser side of the cache manager, it tracks the activity of the |
| 6 // render processes and allocates available memory cache resources. | 6 // render processes and allocates available memory cache resources. |
| 7 | 7 |
| 8 #ifndef COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ | 8 #ifndef COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ |
| 9 #define COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ | 9 #define COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ |
| 10 | 10 |
| 11 #include <list> | 11 #include <list> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <set> | 13 #include <set> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "base/trace_event/memory_dump_provider.h" | |
| 20 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 22 #include "third_party/WebKit/public/web/WebCache.h" | 23 #include "third_party/WebKit/public/web/WebCache.h" |
| 23 | 24 |
| 24 template<typename Type> | 25 template<typename Type> |
| 25 struct DefaultSingletonTraits; | 26 struct DefaultSingletonTraits; |
| 26 class PrefRegistrySimple; | 27 class PrefRegistrySimple; |
| 27 | 28 |
| 28 namespace web_cache { | 29 namespace web_cache { |
| 29 | 30 |
| 30 class WebCacheManager : public content::NotificationObserver { | 31 class WebCacheManager : public content::NotificationObserver, |
| 32 public base::trace_event::MemoryDumpProvider { | |
| 31 friend class WebCacheManagerTest; | 33 friend class WebCacheManagerTest; |
| 32 FRIEND_TEST_ALL_PREFIXES( | 34 FRIEND_TEST_ALL_PREFIXES( |
| 33 WebCacheManagerTest, | 35 WebCacheManagerTest, |
| 34 CallRemoveRendererAndObserveActivityInAnyOrderShouldNotCrashTest_1); | 36 CallRemoveRendererAndObserveActivityInAnyOrderShouldNotCrashTest_1); |
| 35 FRIEND_TEST_ALL_PREFIXES( | 37 FRIEND_TEST_ALL_PREFIXES( |
| 36 WebCacheManagerTest, | 38 WebCacheManagerTest, |
| 37 CallRemoveRendererAndObserveActivityInAnyOrderShouldNotCrashTest_2); | 39 CallRemoveRendererAndObserveActivityInAnyOrderShouldNotCrashTest_2); |
| 38 FRIEND_TEST_ALL_PREFIXES( | 40 FRIEND_TEST_ALL_PREFIXES( |
| 39 WebCacheManagerTest, | 41 WebCacheManagerTest, |
| 40 CallRemoveRendererAndObserveActivityInAnyOrderShouldNotCrashTest_3); | 42 CallRemoveRendererAndObserveActivityInAnyOrderShouldNotCrashTest_3); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 93 |
| 92 // Clears all in-memory caches when a tab is reloaded or the user navigates | 94 // Clears all in-memory caches when a tab is reloaded or the user navigates |
| 93 // to a different website. | 95 // to a different website. |
| 94 void ClearCacheOnNavigation(); | 96 void ClearCacheOnNavigation(); |
| 95 | 97 |
| 96 // content::NotificationObserver implementation: | 98 // content::NotificationObserver implementation: |
| 97 void Observe(int type, | 99 void Observe(int type, |
| 98 const content::NotificationSource& source, | 100 const content::NotificationSource& source, |
| 99 const content::NotificationDetails& details) override; | 101 const content::NotificationDetails& details) override; |
| 100 | 102 |
| 103 // base::trace_event::MemoryDUmpProvider implementation. | |
| 104 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | |
| 105 base::trace_event::ProcessMemoryDump* pmd) override; | |
| 106 | |
| 101 // Gets the default global size limit. This interrogates system metrics to | 107 // Gets the default global size limit. This interrogates system metrics to |
| 102 // tune the default size to the current system. | 108 // tune the default size to the current system. |
| 103 static size_t GetDefaultGlobalSizeLimit(); | 109 static size_t GetDefaultGlobalSizeLimit(); |
| 104 | 110 |
| 105 protected: | 111 protected: |
| 106 // The amount of idle time before we consider a tab to be "inactive" | 112 // The amount of idle time before we consider a tab to be "inactive" |
| 107 static const int kRendererInactiveThresholdMinutes = 5; | 113 static const int kRendererInactiveThresholdMinutes = 5; |
| 108 | 114 |
| 109 // Keep track of some renderer information. | 115 // Keep track of some renderer information. |
| 110 struct RendererInfo : blink::WebCache::UsageStats { | 116 struct RendererInfo : blink::WebCache::UsageStats { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 ON_NAVIGATION | 216 ON_NAVIGATION |
| 211 }; | 217 }; |
| 212 | 218 |
| 213 // Inform all |renderers| to clear their cache. | 219 // Inform all |renderers| to clear their cache. |
| 214 void ClearRendererCache(const std::set<int>& renderers, | 220 void ClearRendererCache(const std::set<int>& renderers, |
| 215 ClearCacheOccasion occation); | 221 ClearCacheOccasion occation); |
| 216 | 222 |
| 217 // Check to see if any active renderers have fallen inactive. | 223 // Check to see if any active renderers have fallen inactive. |
| 218 void FindInactiveRenderers(); | 224 void FindInactiveRenderers(); |
| 219 | 225 |
| 226 // Helper method to dump the cache usage stats of given renderer. | |
| 227 void DumpUsageStats(int renderer_id, | |
|
Primiano Tucci (use gerrit)
2015/08/12 10:04:45
nit: how about DumpMemoryStatsForRenderer ?
| |
| 228 base::trace_event::ProcessMemoryDump* pmd); | |
| 229 | |
| 220 // The global size limit for all in-memory caches. | 230 // The global size limit for all in-memory caches. |
| 221 size_t global_size_limit_; | 231 size_t global_size_limit_; |
| 222 | 232 |
| 223 // Maps every renderer_id our most recent copy of its statistics. | 233 // Maps every renderer_id our most recent copy of its statistics. |
| 224 StatsMap stats_; | 234 StatsMap stats_; |
| 225 | 235 |
| 226 // Every renderer we think is still around is in one of these two sets. | 236 // Every renderer we think is still around is in one of these two sets. |
| 227 // | 237 // |
| 228 // Active renderers are those renderers that have been active more recently | 238 // Active renderers are those renderers that have been active more recently |
| 229 // than they have been inactive. | 239 // than they have been inactive. |
| 230 std::set<int> active_renderers_; | 240 std::set<int> active_renderers_; |
| 231 // Inactive renderers are those renderers that have been inactive more | 241 // Inactive renderers are those renderers that have been inactive more |
| 232 // recently than they have been active. | 242 // recently than they have been active. |
| 233 std::set<int> inactive_renderers_; | 243 std::set<int> inactive_renderers_; |
| 234 | 244 |
| 235 content::NotificationRegistrar registrar_; | 245 content::NotificationRegistrar registrar_; |
| 236 | 246 |
| 237 base::WeakPtrFactory<WebCacheManager> weak_factory_; | 247 base::WeakPtrFactory<WebCacheManager> weak_factory_; |
| 238 | 248 |
| 239 DISALLOW_COPY_AND_ASSIGN(WebCacheManager); | 249 DISALLOW_COPY_AND_ASSIGN(WebCacheManager); |
| 240 }; | 250 }; |
| 241 | 251 |
| 242 } // namespace web_cache | 252 } // namespace web_cache |
| 243 | 253 |
| 244 #endif // COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ | 254 #endif // COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ |
| OLD | NEW |