| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/power_profiler/power_profiler_service.h" | 5 #include "content/browser/power_profiler/power_profiler_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 | 11 |
| 12 namespace { | |
| 13 | |
| 14 // Default sampling period, as recommended by Intel Power Gadget. | |
| 15 // Section 3.1 of http://software.intel.com/en-us/blogs/2013/10/03/using-the-int
el-power-gadget-api-on-windows | |
| 16 const int kDefaultSamplePeriodMs = 50; | |
| 17 | |
| 18 } // namespace | |
| 19 | |
| 20 namespace content { | 12 namespace content { |
| 21 | 13 |
| 22 PowerProfilerService::PowerProfilerService() | 14 PowerProfilerService::PowerProfilerService() |
| 23 : status_(UNINITIALIZED), | 15 : status_(UNINITIALIZED), |
| 24 sample_period_(base::TimeDelta::FromMilliseconds(kDefaultSamplePeriodMs)), | |
| 25 data_provider_(PowerDataProvider::Create()) { | 16 data_provider_(PowerDataProvider::Create()) { |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 17 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 27 | 18 |
| 28 // No provider supported for current platform. | 19 // No provider supported for current platform. |
| 29 if (!data_provider_.get()) | 20 if (!data_provider_.get()) |
| 30 return; | 21 return; |
| 31 | 22 sample_period_ = data_provider_->GetSamplingRate(); |
| 32 status_ = INITIALIZED; | 23 status_ = INITIALIZED; |
| 33 task_runner_ = BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 24 task_runner_ = BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 34 BrowserThread::GetBlockingPool()->GetSequenceToken()); | 25 BrowserThread::GetBlockingPool()->GetSequenceToken()); |
| 35 } | 26 } |
| 36 | 27 |
| 37 PowerProfilerService::PowerProfilerService( | 28 PowerProfilerService::PowerProfilerService( |
| 38 scoped_ptr<PowerDataProvider> provider, | 29 scoped_ptr<PowerDataProvider> provider, |
| 39 scoped_refptr<base::TaskRunner> task_runner, | 30 scoped_refptr<base::TaskRunner> task_runner, |
| 40 const base::TimeDelta& sample_period) | 31 const base::TimeDelta& sample_period) |
| 41 : task_runner_(task_runner), | 32 : task_runner_(task_runner), |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 100 |
| 110 // Get data and notify. | 101 // Get data and notify. |
| 111 PowerEventVector events = data_provider_->GetData(); | 102 PowerEventVector events = data_provider_->GetData(); |
| 112 if (events.size() != 0) { | 103 if (events.size() != 0) { |
| 113 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 104 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 114 &PowerProfilerService::Notify, base::Unretained(this), events)); | 105 &PowerProfilerService::Notify, base::Unretained(this), events)); |
| 115 } | 106 } |
| 116 } | 107 } |
| 117 | 108 |
| 118 } // namespace content | 109 } // namespace content |
| OLD | NEW |