| Index: content/browser/memory/swap_metrics_observer.cc
|
| diff --git a/content/browser/memory/swap_metrics_observer.cc b/content/browser/memory/swap_metrics_observer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..79e9853f2a5187a9269bd8a2a1a76352450fb0b3
|
| --- /dev/null
|
| +++ b/content/browser/memory/swap_metrics_observer.cc
|
| @@ -0,0 +1,42 @@
|
| +// Copyright 2017 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/browser/memory/swap_metrics_observer.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +// Time between updating swap rates.
|
| +const int kSwapMetricsIntervalSeconds = 60;
|
| +}
|
| +
|
| +SwapMetricsObserver::SwapMetricsObserver()
|
| + : update_interval_(
|
| + base::TimeDelta::FromSeconds(kSwapMetricsIntervalSeconds)) {}
|
| +
|
| +SwapMetricsObserver::~SwapMetricsObserver() {}
|
| +
|
| +void SwapMetricsObserver::Start() {
|
| + timer_.Start(FROM_HERE, update_interval_, this,
|
| + &SwapMetricsObserver::UpdateMetrics);
|
| +}
|
| +
|
| +void SwapMetricsObserver::Stop() {
|
| + last_ticks_ = base::TimeTicks();
|
| + timer_.Stop();
|
| +}
|
| +
|
| +void SwapMetricsObserver::UpdateMetrics() {
|
| + base::TimeTicks now = base::TimeTicks::Now();
|
| + base::TimeDelta interval =
|
| + last_ticks_.is_null() ? base::TimeDelta() : now - last_ticks_;
|
| + UpdateMetricsInternal(interval);
|
| + last_ticks_ = now;
|
| +}
|
| +
|
| +} // namespace content
|
|
|