OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "components/web_cache/browser/web_cache_manager.h" | 5 #include "components/web_cache/browser/web_cache_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/location.h" |
11 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
12 #include "base/message_loop/message_loop.h" | |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/single_thread_task_runner.h" |
16 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 18 #include "base/thread_task_runner_handle.h" |
17 #include "base/time/time.h" | 19 #include "base/time/time.h" |
18 #include "components/web_cache/common/web_cache_messages.h" | 20 #include "components/web_cache/common/web_cache_messages.h" |
19 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
21 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
22 | 24 |
23 using base::Time; | 25 using base::Time; |
24 using base::TimeDelta; | 26 using base::TimeDelta; |
25 using blink::WebCache; | 27 using blink::WebCache; |
26 | 28 |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 EnactStrategy(strategy); | 410 EnactStrategy(strategy); |
409 } else { | 411 } else { |
410 // DIVIDE_EVENLY / DIVIDE_EVENLY should always succeed. | 412 // DIVIDE_EVENLY / DIVIDE_EVENLY should always succeed. |
411 NOTREACHED() << "Unable to find a cache allocation"; | 413 NOTREACHED() << "Unable to find a cache allocation"; |
412 } | 414 } |
413 } | 415 } |
414 | 416 |
415 void WebCacheManager::ReviseAllocationStrategyLater() { | 417 void WebCacheManager::ReviseAllocationStrategyLater() { |
416 // Ask to be called back in a few milliseconds to actually recompute our | 418 // Ask to be called back in a few milliseconds to actually recompute our |
417 // allocation. | 419 // allocation. |
418 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 420 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
419 base::Bind( | 421 FROM_HERE, base::Bind(&WebCacheManager::ReviseAllocationStrategy, |
420 &WebCacheManager::ReviseAllocationStrategy, | 422 weak_factory_.GetWeakPtr()), |
421 weak_factory_.GetWeakPtr()), | |
422 base::TimeDelta::FromMilliseconds(kReviseAllocationDelayMS)); | 423 base::TimeDelta::FromMilliseconds(kReviseAllocationDelayMS)); |
423 } | 424 } |
424 | 425 |
425 void WebCacheManager::FindInactiveRenderers() { | 426 void WebCacheManager::FindInactiveRenderers() { |
426 std::set<int>::const_iterator iter = active_renderers_.begin(); | 427 std::set<int>::const_iterator iter = active_renderers_.begin(); |
427 while (iter != active_renderers_.end()) { | 428 while (iter != active_renderers_.end()) { |
428 StatsMap::iterator elmt = stats_.find(*iter); | 429 StatsMap::iterator elmt = stats_.find(*iter); |
429 DCHECK(elmt != stats_.end()); | 430 DCHECK(elmt != stats_.end()); |
430 TimeDelta idle = Time::Now() - elmt->second.access; | 431 TimeDelta idle = Time::Now() - elmt->second.access; |
431 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { | 432 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { |
432 // Moved to inactive status. This invalidates our iterator. | 433 // Moved to inactive status. This invalidates our iterator. |
433 inactive_renderers_.insert(*iter); | 434 inactive_renderers_.insert(*iter); |
434 active_renderers_.erase(*iter); | 435 active_renderers_.erase(*iter); |
435 iter = active_renderers_.begin(); | 436 iter = active_renderers_.begin(); |
436 continue; | 437 continue; |
437 } | 438 } |
438 ++iter; | 439 ++iter; |
439 } | 440 } |
440 } | 441 } |
441 | 442 |
442 } // namespace web_cache | 443 } // namespace web_cache |
OLD | NEW |