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 content { | 12 namespace content { |
13 | 13 |
14 PowerProfilerService::PowerProfilerService() | 14 PowerProfilerService::PowerProfilerService() |
15 : status_(UNINITIALIZED), | 15 : status_(UNINITIALIZED), |
16 data_provider_(PowerDataProvider::Create()) { | 16 data_provider_(PowerDataProvider::Create()) { |
17 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 17 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
18 | 18 |
19 // No provider supported for current platform. | 19 // No provider supported for current platform. |
20 if (!data_provider_.get()) | 20 if (!data_provider_.get()) |
21 return; | 21 return; |
22 sample_period_ = data_provider_->GetSamplingRate(); | 22 sample_period_ = data_provider_->GetSamplingRate(); |
23 status_ = INITIALIZED; | 23 status_ = INITIALIZED; |
24 task_runner_ = BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 24 task_runner_ = BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
25 BrowserThread::GetBlockingPool()->GetSequenceToken()); | 25 BrowserThread::GetBlockingPool()->GetSequenceToken()); |
26 } | 26 } |
27 | 27 |
28 PowerProfilerService::PowerProfilerService( | 28 PowerProfilerService::PowerProfilerService( |
29 scoped_ptr<PowerDataProvider> provider, | 29 scoped_ptr<PowerDataProvider> provider, |
30 scoped_refptr<base::TaskRunner> task_runner, | 30 scoped_refptr<base::TaskRunner> task_runner, |
31 const base::TimeDelta& sample_period) | 31 const base::TimeDelta& sample_period) |
32 : task_runner_(task_runner), | 32 : task_runner_(task_runner), |
33 status_(UNINITIALIZED), | 33 status_(UNINITIALIZED), |
34 sample_period_(sample_period), | 34 sample_period_(sample_period), |
35 data_provider_(provider.Pass()) { | 35 data_provider_(provider.Pass()) { |
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 36 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
37 | 37 |
38 if (data_provider_.get()) | 38 if (data_provider_.get()) |
39 status_ = INITIALIZED; | 39 status_ = INITIALIZED; |
40 } | 40 } |
41 | 41 |
42 PowerProfilerService::~PowerProfilerService() { | 42 PowerProfilerService::~PowerProfilerService() { |
43 } | 43 } |
44 | 44 |
45 bool PowerProfilerService::IsAvailable() const { | 45 bool PowerProfilerService::IsAvailable() const { |
46 return status_ != UNINITIALIZED; | 46 return status_ != UNINITIALIZED; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 // Get data and notify. | 114 // Get data and notify. |
115 PowerEventVector events = data_provider_->GetData(); | 115 PowerEventVector events = data_provider_->GetData(); |
116 if (events.size() != 0) { | 116 if (events.size() != 0) { |
117 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 117 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
118 &PowerProfilerService::Notify, base::Unretained(this), events)); | 118 &PowerProfilerService::Notify, base::Unretained(this), events)); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 } // namespace content | 122 } // namespace content |
OLD | NEW |