forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlow_memory_mode_controller.cc
61 lines (48 loc) · 1.62 KB
/
low_memory_mode_controller.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/low_memory_mode_controller.h"
#include "base/metrics/histogram_macros.h"
#include "third_party/blink/public/web/blink.h"
#include "v8/include/v8.h"
namespace content {
LowMemoryModeController::LowMemoryModeController() = default;
LowMemoryModeController::~LowMemoryModeController() = default;
void LowMemoryModeController::OnFrameCreated(bool is_main_frame) {
if (is_main_frame) {
// If the process is gaining its first main frame, disable memory
// savings mode.
if (++main_frame_count_ == 1) {
Disable();
}
} else if (main_frame_count_ == 0) {
// The process is getting a new frame and none is main, enable
// memory savings mode (if not already on).
Enable();
}
}
void LowMemoryModeController::OnFrameDestroyed(bool is_main_frame) {
// If the process is losing its last main frame, enable memory
// savings mode.
if (is_main_frame && --main_frame_count_ == 0) {
Enable();
}
}
void LowMemoryModeController::Enable() {
if (is_enabled_)
return;
blink::MainThreadIsolate()->EnableMemorySavingsMode();
RecordHistogram(true);
is_enabled_ = true;
}
void LowMemoryModeController::Disable() {
if (!is_enabled_)
return;
blink::MainThreadIsolate()->DisableMemorySavingsMode();
RecordHistogram(false);
is_enabled_ = false;
}
void LowMemoryModeController::RecordHistogram(bool enabled) {
UMA_HISTOGRAM_BOOLEAN("SiteIsolation.LowMemoryMode.Transition", enabled);
}
} // namespace content