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

Side by Side Diff: chrome/browser/renderer_host/web_cache_manager.h

Issue 63273002: Rename WebKit namespace to blink (part 4) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 CHROME_BROWSER_RENDERER_HOST_WEB_CACHE_MANAGER_H_ 8 #ifndef CHROME_BROWSER_RENDERER_HOST_WEB_CACHE_MANAGER_H_
9 #define CHROME_BROWSER_RENDERER_HOST_WEB_CACHE_MANAGER_H_ 9 #define CHROME_BROWSER_RENDERER_HOST_WEB_CACHE_MANAGER_H_
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // 51 //
52 // When a renderer moves from being inactive to being active, the cache 52 // When a renderer moves from being inactive to being active, the cache
53 // manager may decide to adjust its resource allocation, but it will delay 53 // manager may decide to adjust its resource allocation, but it will delay
54 // the recalculation, allowing ObserveActivity to return quickly. 54 // the recalculation, allowing ObserveActivity to return quickly.
55 void ObserveActivity(int renderer_id); 55 void ObserveActivity(int renderer_id);
56 56
57 // Periodically, renderers should inform the cache manager of their current 57 // Periodically, renderers should inform the cache manager of their current
58 // statistics. The more up-to-date the cache manager's statistics, the 58 // statistics. The more up-to-date the cache manager's statistics, the
59 // better it can allocate cache resources. 59 // better it can allocate cache resources.
60 void ObserveStats( 60 void ObserveStats(
61 int renderer_id, const WebKit::WebCache::UsageStats& stats); 61 int renderer_id, const blink::WebCache::UsageStats& stats);
62 62
63 // The global limit on the number of bytes in all the in-memory caches. 63 // The global limit on the number of bytes in all the in-memory caches.
64 size_t global_size_limit() const { return global_size_limit_; } 64 size_t global_size_limit() const { return global_size_limit_; }
65 65
66 // Sets the global size limit, forcing a recalculation of cache allocations. 66 // Sets the global size limit, forcing a recalculation of cache allocations.
67 void SetGlobalSizeLimit(size_t bytes); 67 void SetGlobalSizeLimit(size_t bytes);
68 68
69 // Clears all in-memory caches. 69 // Clears all in-memory caches.
70 void ClearCache(); 70 void ClearCache();
71 71
72 // Clears all in-memory caches when a tab is reloaded or the user navigates 72 // Clears all in-memory caches when a tab is reloaded or the user navigates
73 // to a different website. 73 // to a different website.
74 void ClearCacheOnNavigation(); 74 void ClearCacheOnNavigation();
75 75
76 // content::NotificationObserver implementation: 76 // content::NotificationObserver implementation:
77 virtual void Observe(int type, 77 virtual void Observe(int type,
78 const content::NotificationSource& source, 78 const content::NotificationSource& source,
79 const content::NotificationDetails& details) OVERRIDE; 79 const content::NotificationDetails& details) OVERRIDE;
80 80
81 // Gets the default global size limit. This interrogates system metrics to 81 // Gets the default global size limit. This interrogates system metrics to
82 // tune the default size to the current system. 82 // tune the default size to the current system.
83 static size_t GetDefaultGlobalSizeLimit(); 83 static size_t GetDefaultGlobalSizeLimit();
84 84
85 protected: 85 protected:
86 // The amount of idle time before we consider a tab to be "inactive" 86 // The amount of idle time before we consider a tab to be "inactive"
87 static const int kRendererInactiveThresholdMinutes = 5; 87 static const int kRendererInactiveThresholdMinutes = 5;
88 88
89 // Keep track of some renderer information. 89 // Keep track of some renderer information.
90 struct RendererInfo : WebKit::WebCache::UsageStats { 90 struct RendererInfo : blink::WebCache::UsageStats {
91 // The access time for this renderer. 91 // The access time for this renderer.
92 base::Time access; 92 base::Time access;
93 }; 93 };
94 94
95 typedef std::map<int, RendererInfo> StatsMap; 95 typedef std::map<int, RendererInfo> StatsMap;
96 96
97 // An allocation is the number of bytes a specific renderer should use for 97 // An allocation is the number of bytes a specific renderer should use for
98 // its cache. 98 // its cache.
99 typedef std::pair<int,size_t> Allocation; 99 typedef std::pair<int,size_t> Allocation;
100 100
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // Allow each renderer to keep cache resources it believes are currently 142 // Allow each renderer to keep cache resources it believes are currently
143 // being used, but instruct the renderer to discard all other data. 143 // being used, but instruct the renderer to discard all other data.
144 KEEP_LIVE, 144 KEEP_LIVE,
145 }; 145 };
146 146
147 // Helper functions for devising an allocation strategy 147 // Helper functions for devising an allocation strategy
148 148
149 // Add up all the stats from the given set of renderers and place the result 149 // Add up all the stats from the given set of renderers and place the result
150 // in |stats|. 150 // in |stats|.
151 void GatherStats(const std::set<int>& renderers, 151 void GatherStats(const std::set<int>& renderers,
152 WebKit::WebCache::UsageStats* stats); 152 blink::WebCache::UsageStats* stats);
153 153
154 // Get the amount of memory that would be required to implement |tactic| 154 // Get the amount of memory that would be required to implement |tactic|
155 // using the specified allocation tactic. This function defines the 155 // using the specified allocation tactic. This function defines the
156 // semantics for each of the tactics. 156 // semantics for each of the tactics.
157 static size_t GetSize(AllocationTactic tactic, 157 static size_t GetSize(AllocationTactic tactic,
158 const WebKit::WebCache::UsageStats& stats); 158 const blink::WebCache::UsageStats& stats);
159 159
160 // Attempt to use the specified tactics to compute an allocation strategy 160 // Attempt to use the specified tactics to compute an allocation strategy
161 // and place the result in |strategy|. |active_stats| and |inactive_stats| 161 // and place the result in |strategy|. |active_stats| and |inactive_stats|
162 // are the aggregate statistics for |active_renderers_| and 162 // are the aggregate statistics for |active_renderers_| and
163 // |inactive_renderers_|, respectively. 163 // |inactive_renderers_|, respectively.
164 // 164 //
165 // Returns |true| on success and |false| on failure. Does not modify 165 // Returns |true| on success and |false| on failure. Does not modify
166 // |strategy| on failure. 166 // |strategy| on failure.
167 bool AttemptTactic(AllocationTactic active_tactic, 167 bool AttemptTactic(AllocationTactic active_tactic,
168 const WebKit::WebCache::UsageStats& active_stats, 168 const blink::WebCache::UsageStats& active_stats,
169 AllocationTactic inactive_tactic, 169 AllocationTactic inactive_tactic,
170 const WebKit::WebCache::UsageStats& inactive_stats, 170 const blink::WebCache::UsageStats& inactive_stats,
171 AllocationStrategy* strategy); 171 AllocationStrategy* strategy);
172 172
173 // For each renderer in |renderers|, computes its allocation according to 173 // For each renderer in |renderers|, computes its allocation according to
174 // |tactic| and add the result to |strategy|. Any |extra_bytes_to_allocate| 174 // |tactic| and add the result to |strategy|. Any |extra_bytes_to_allocate|
175 // is divided evenly among the renderers. 175 // is divided evenly among the renderers.
176 void AddToStrategy(const std::set<int>& renderers, 176 void AddToStrategy(const std::set<int>& renderers,
177 AllocationTactic tactic, 177 AllocationTactic tactic,
178 size_t extra_bytes_to_allocate, 178 size_t extra_bytes_to_allocate,
179 AllocationStrategy* strategy); 179 AllocationStrategy* strategy);
180 180
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 std::set<int> inactive_renderers_; 213 std::set<int> inactive_renderers_;
214 214
215 base::WeakPtrFactory<WebCacheManager> weak_factory_; 215 base::WeakPtrFactory<WebCacheManager> weak_factory_;
216 216
217 content::NotificationRegistrar registrar_; 217 content::NotificationRegistrar registrar_;
218 218
219 DISALLOW_COPY_AND_ASSIGN(WebCacheManager); 219 DISALLOW_COPY_AND_ASSIGN(WebCacheManager);
220 }; 220 };
221 221
222 #endif // CHROME_BROWSER_RENDERER_HOST_WEB_CACHE_MANAGER_H_ 222 #endif // CHROME_BROWSER_RENDERER_HOST_WEB_CACHE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698