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

Side by Side Diff: athena/resource_manager/memory_pressure_notifier.cc

Issue 863033002: Delete athena/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "athena/resource_manager/memory_pressure_notifier.h"
6
7 #include "athena/resource_manager/public/resource_manager_delegate.h"
8 #include "base/time/time.h"
9
10
11 namespace athena {
12
13 MemoryPressureNotifier::MemoryPressureNotifier(
14 MemoryPressureObserver* listener)
15 : listener_(listener),
16 current_pressure_(ResourceManager::MEMORY_PRESSURE_UNKNOWN) {
17 StartObserving();
18 }
19
20 MemoryPressureNotifier::~MemoryPressureNotifier() {
21 StopObserving();
22 }
23
24 void MemoryPressureNotifier::StartObserving() {
25 int time_in_ms = listener_->GetDelegate()->MemoryPressureIntervalInMS();
26 timer_.Start(FROM_HERE,
27 base::TimeDelta::FromMilliseconds(time_in_ms),
28 base::Bind(&MemoryPressureNotifier::CheckMemoryPressure,
29 base::Unretained(this)));
30 }
31
32 void MemoryPressureNotifier::StopObserving() {
33 // If StartObserving failed, StopObserving will still get called.
34 timer_.Stop();
35 }
36
37 void MemoryPressureNotifier::CheckMemoryPressure() {
38 ResourceManager::MemoryPressure pressure =
39 GetMemoryPressureLevelFromFillLevel(
40 listener_->GetDelegate()->GetUsedMemoryInPercent());
41 if (current_pressure_ != pressure ||
42 (pressure != ResourceManager::MEMORY_PRESSURE_LOW &&
43 pressure != ResourceManager::MEMORY_PRESSURE_UNKNOWN)) {
44 // If we are anything worse than |MEMORY_PRESSURE_LOW|, we notify the
45 // listener.
46 current_pressure_ = pressure;
47 listener_->OnMemoryPressure(current_pressure_);
48 }
49 }
50
51 ResourceManager::MemoryPressure
52 MemoryPressureNotifier::GetMemoryPressureLevelFromFillLevel(
53 int memory_fill_level) {
54 if (memory_fill_level == 0)
55 return ResourceManager::MEMORY_PRESSURE_UNKNOWN;
56 if (memory_fill_level < 50)
57 return ResourceManager::MEMORY_PRESSURE_LOW;
58 if (memory_fill_level < 75)
59 return ResourceManager::MEMORY_PRESSURE_MODERATE;
60 if (memory_fill_level < 90)
61 return ResourceManager::MEMORY_PRESSURE_HIGH;
62 return ResourceManager::MEMORY_PRESSURE_CRITICAL;
63 }
64
65 } // namespace athena
OLDNEW
« no previous file with comments | « athena/resource_manager/memory_pressure_notifier.h ('k') | athena/resource_manager/memory_pressure_notifier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698