IndexedDB: Protect against use-after-free in ChainedBlobWriter.
[chromium-blink-merge.git] / base / timer / hi_res_timer_manager_win.cc
blob692f72b4e594481897bf022e256d51bb65b1f1b9
1 // Copyright (c) 2011 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.
5 #include "base/timer/hi_res_timer_manager.h"
7 #include "base/power_monitor/power_monitor.h"
8 #include "base/time/time.h"
10 namespace base {
12 HighResolutionTimerManager::HighResolutionTimerManager()
13 : hi_res_clock_available_(false) {
14 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
15 DCHECK(power_monitor != NULL);
16 power_monitor->AddObserver(this);
17 UseHiResClock(!power_monitor->IsOnBatteryPower());
20 HighResolutionTimerManager::~HighResolutionTimerManager() {
21 base::PowerMonitor::Get()->RemoveObserver(this);
22 UseHiResClock(false);
25 void HighResolutionTimerManager::OnPowerStateChange(bool on_battery_power) {
26 UseHiResClock(!on_battery_power);
29 void HighResolutionTimerManager::UseHiResClock(bool use) {
30 if (use == hi_res_clock_available_)
31 return;
32 hi_res_clock_available_ = use;
33 base::Time::EnableHighResolutionTimer(use);
36 } // namespace base