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 <stddef.h> | 11 #include <stddef.h> |
12 | 12 |
13 #include <list> | 13 #include <list> |
14 #include <map> | 14 #include <map> |
15 #include <set> | 15 #include <set> |
16 | 16 |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "components/web_cache/public/interfaces/web_cache_service.mojom.h" |
22 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
24 | 25 |
25 namespace base { | 26 namespace base { |
26 template<typename Type> | 27 template<typename Type> |
27 struct DefaultSingletonTraits; | 28 struct DefaultSingletonTraits; |
28 } // namespace base | 29 } // namespace base |
29 | 30 |
30 class PrefRegistrySimple; | 31 class PrefRegistrySimple; |
31 | 32 |
32 namespace web_cache { | 33 namespace web_cache { |
33 | 34 |
| 35 using mojom::WebCacheServicePtr; |
| 36 |
34 // Note: memory usage uses uint64_t because potentially the browser could be | 37 // Note: memory usage uses uint64_t because potentially the browser could be |
35 // 32 bit and the renderers 64 bits. | 38 // 32 bit and the renderers 64 bits. |
36 class WebCacheManager : public content::NotificationObserver { | 39 class WebCacheManager : public content::NotificationObserver { |
37 friend class WebCacheManagerTest; | 40 friend class WebCacheManagerTest; |
38 FRIEND_TEST_ALL_PREFIXES( | 41 FRIEND_TEST_ALL_PREFIXES( |
39 WebCacheManagerTest, | 42 WebCacheManagerTest, |
40 GatherStatsTest); | 43 GatherStatsTest); |
41 FRIEND_TEST_ALL_PREFIXES( | 44 FRIEND_TEST_ALL_PREFIXES( |
42 WebCacheManagerTest, | 45 WebCacheManagerTest, |
43 CallRemoveRendererAndObserveActivityInAnyOrderShouldNotCrashTest_1); | 46 CallRemoveRendererAndObserveActivityInAnyOrderShouldNotCrashTest_1); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 typedef std::map<int, RendererInfo> StatsMap; | 136 typedef std::map<int, RendererInfo> StatsMap; |
134 | 137 |
135 // An allocation is the number of bytes a specific renderer should use for | 138 // An allocation is the number of bytes a specific renderer should use for |
136 // its cache. | 139 // its cache. |
137 typedef std::pair<int,uint64_t> Allocation; | 140 typedef std::pair<int,uint64_t> Allocation; |
138 | 141 |
139 // An allocation strategy is a list of allocations specifying the resources | 142 // An allocation strategy is a list of allocations specifying the resources |
140 // each renderer is permitted to consume for its cache. | 143 // each renderer is permitted to consume for its cache. |
141 typedef std::list<Allocation> AllocationStrategy; | 144 typedef std::list<Allocation> AllocationStrategy; |
142 | 145 |
| 146 typedef std::map<int, WebCacheServicePtr> WebCacheServicesMap; |
| 147 |
143 // This class is a singleton. Do not instantiate directly. | 148 // This class is a singleton. Do not instantiate directly. |
144 WebCacheManager(); | 149 WebCacheManager(); |
145 friend struct base::DefaultSingletonTraits<WebCacheManager>; | 150 friend struct base::DefaultSingletonTraits<WebCacheManager>; |
146 | 151 |
147 ~WebCacheManager() override; | 152 ~WebCacheManager() override; |
148 | 153 |
149 // Recomputes the allocation of cache resources among the renderers. Also | 154 // Recomputes the allocation of cache resources among the renderers. Also |
150 // informs the renderers of their new allocation. | 155 // informs the renderers of their new allocation. |
151 void ReviseAllocationStrategy(); | 156 void ReviseAllocationStrategy(); |
152 | 157 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // | 255 // |
251 // Active renderers are those renderers that have been active more recently | 256 // Active renderers are those renderers that have been active more recently |
252 // than they have been inactive. | 257 // than they have been inactive. |
253 std::set<int> active_renderers_; | 258 std::set<int> active_renderers_; |
254 // Inactive renderers are those renderers that have been inactive more | 259 // Inactive renderers are those renderers that have been inactive more |
255 // recently than they have been active. | 260 // recently than they have been active. |
256 std::set<int> inactive_renderers_; | 261 std::set<int> inactive_renderers_; |
257 | 262 |
258 content::NotificationRegistrar registrar_; | 263 content::NotificationRegistrar registrar_; |
259 | 264 |
| 265 // Maps every renderer_id with its corresponding WebCacheServicePtr. |
| 266 WebCacheServicesMap web_cache_services_; |
| 267 |
260 base::WeakPtrFactory<WebCacheManager> weak_factory_; | 268 base::WeakPtrFactory<WebCacheManager> weak_factory_; |
261 | 269 |
262 DISALLOW_COPY_AND_ASSIGN(WebCacheManager); | 270 DISALLOW_COPY_AND_ASSIGN(WebCacheManager); |
263 }; | 271 }; |
264 | 272 |
265 } // namespace web_cache | 273 } // namespace web_cache |
266 | 274 |
267 #endif // COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ | 275 #endif // COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ |
OLD | NEW |