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

Side by Side Diff: chromecast/browser/cast_memory_pressure_monitor.cc

Issue 2097753002: Make memory pressure notifier configurable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win Created 4 years, 5 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
« no previous file with comments | « chromecast/browser/cast_memory_pressure_monitor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chromecast/browser/cast_memory_pressure_monitor.h" 5 #include "chromecast/browser/cast_memory_pressure_monitor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 28 matching lines...) Expand all
39 &rtn_kb_); 39 &rtn_kb_);
40 DCHECK(rtn_kb_ >= 0); 40 DCHECK(rtn_kb_ >= 0);
41 return std::max(rtn_kb_, 0); 41 return std::max(rtn_kb_, 0);
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 CastMemoryPressureMonitor::CastMemoryPressureMonitor() 46 CastMemoryPressureMonitor::CastMemoryPressureMonitor()
47 : current_level_(base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE), 47 : current_level_(base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE),
48 system_reserved_kb_(GetSystemReservedKb()), 48 system_reserved_kb_(GetSystemReservedKb()),
49 dispatch_callback_(
50 base::Bind(&base::MemoryPressureListener::NotifyMemoryPressure)),
49 weak_ptr_factory_(this) { 51 weak_ptr_factory_(this) {
50 PollPressureLevel(); 52 PollPressureLevel();
51 } 53 }
52 54
53 CastMemoryPressureMonitor::~CastMemoryPressureMonitor() {} 55 CastMemoryPressureMonitor::~CastMemoryPressureMonitor() {}
54 56
55 CastMemoryPressureMonitor::MemoryPressureLevel 57 CastMemoryPressureMonitor::MemoryPressureLevel
56 CastMemoryPressureMonitor::GetCurrentPressureLevel() const { 58 CastMemoryPressureMonitor::GetCurrentPressureLevel() const {
57 return current_level_; 59 return current_level_;
58 } 60 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 106
105 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 107 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
106 FROM_HERE, base::Bind(&CastMemoryPressureMonitor::PollPressureLevel, 108 FROM_HERE, base::Bind(&CastMemoryPressureMonitor::PollPressureLevel,
107 weak_ptr_factory_.GetWeakPtr()), 109 weak_ptr_factory_.GetWeakPtr()),
108 base::TimeDelta::FromMilliseconds(kPollingIntervalMS)); 110 base::TimeDelta::FromMilliseconds(kPollingIntervalMS));
109 } 111 }
110 112
111 void CastMemoryPressureMonitor::UpdateMemoryPressureLevel( 113 void CastMemoryPressureMonitor::UpdateMemoryPressureLevel(
112 MemoryPressureLevel new_level) { 114 MemoryPressureLevel new_level) {
113 if (new_level != base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) 115 if (new_level != base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE)
114 base::MemoryPressureListener::NotifyMemoryPressure(new_level); 116 dispatch_callback_.Run(new_level);
115 117
116 if (new_level == current_level_) 118 if (new_level == current_level_)
117 return; 119 return;
118 120
119 current_level_ = new_level; 121 current_level_ = new_level;
120 metrics::CastMetricsHelper::GetInstance()->RecordApplicationEventWithValue( 122 metrics::CastMetricsHelper::GetInstance()->RecordApplicationEventWithValue(
121 "Memory.Pressure.LevelChange", new_level); 123 "Memory.Pressure.LevelChange", new_level);
122 } 124 }
123 125
126 void CastMemoryPressureMonitor::SetDispatchCallback(
127 const DispatchCallback& callback) {
128 dispatch_callback_ = callback;
129 }
130
124 } // namespace chromecast 131 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/browser/cast_memory_pressure_monitor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698