OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "content/browser/memory/swap_metrics_observer.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 namespace { |
| 13 |
| 14 // Time between updating swap rates. |
| 15 const int kSwapMetricsIntervalSeconds = 60; |
| 16 |
| 17 } // namespace |
| 18 |
| 19 SwapMetricsObserver::SwapMetricsObserver() |
| 20 : update_interval_( |
| 21 base::TimeDelta::FromSeconds(kSwapMetricsIntervalSeconds)) {} |
| 22 |
| 23 SwapMetricsObserver::~SwapMetricsObserver() {} |
| 24 |
| 25 void SwapMetricsObserver::Start() { |
| 26 timer_.Start(FROM_HERE, update_interval_, this, |
| 27 &SwapMetricsObserver::UpdateMetrics); |
| 28 } |
| 29 |
| 30 void SwapMetricsObserver::Stop() { |
| 31 last_ticks_ = base::TimeTicks(); |
| 32 timer_.Stop(); |
| 33 } |
| 34 |
| 35 void SwapMetricsObserver::UpdateMetrics() { |
| 36 base::TimeTicks now = base::TimeTicks::Now(); |
| 37 base::TimeDelta interval = |
| 38 last_ticks_.is_null() ? base::TimeDelta() : now - last_ticks_; |
| 39 UpdateMetricsInternal(interval); |
| 40 last_ticks_ = now; |
| 41 } |
| 42 |
| 43 } // namespace content |
OLD | NEW |