Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: content/browser/power_profiler/power_profiler_service.cc

Issue 140583003: Chrome power profiler service (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/power_profiler/power_profiler_service.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "content/browser/power_profiler/power_data_provider_factory.h"
11 #include "content/public/browser/browser_thread.h"
12
13 namespace content {
14
15 PowerProfilerService::PowerProfilerService()
16 : status_(UNINITIALIZED),
17 delay_(base::TimeDelta::FromMilliseconds(50)),
jeremy 2014/02/16 14:09:19 Where does this value come from? Recommend initia
Pan 2014/02/17 03:17:15 This value is recommended by Intel Power Gadget, c
18 data_provider_(PowerDataProviderFactory::Create()) {
19 if (data_provider_.get()) {
20 status_ = INITIALIZED;
21 task_runner_ = BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
22 BrowserThread::GetBlockingPool()->GetSequenceToken());
23 }
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
jeremy 2014/02/16 14:09:19 IMHO this should be at the start of the function.
Pan 2014/02/17 03:17:15 Done.
25 }
26
27 PowerProfilerService::PowerProfilerService(
28 scoped_ptr<PowerDataProvider> provider,
29 scoped_refptr<base::TaskRunner> task_runner,
30 const base::TimeDelta& delay)
31 : task_runner_(task_runner),
32 status_(UNINITIALIZED),
33 delay_(delay),
34 data_provider_(provider.Pass()) {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
36
37 if (data_provider_.get())
38 status_ = INITIALIZED;
39 }
40
41 bool PowerProfilerService::IsAvailable() {
42 return status_ != UNINITIALIZED;
43 }
44
45 PowerProfilerService* PowerProfilerService::GetInstance() {
46 return Singleton<PowerProfilerService>::get();
47 }
48
49 void PowerProfilerService::AddObserver(PowerProfilerObserver* obs) {
jeremy 2014/02/16 14:09:19 obs -> observer
Pan 2014/02/17 03:17:15 Done.
50 if (UNINITIALIZED == status_)
jeremy 2014/02/16 14:09:19 status_ == UNINITALIZED constant on rhs in compar
Pan 2014/02/17 03:17:15 Done.
51 return;
52
53 observers_.AddObserver(obs);
54 if (PROFILING != status_)
55 Start();
56 }
57
58 void PowerProfilerService::RemoveObserver(PowerProfilerObserver* obs) {
59 observers_.RemoveObserver(obs);
60
61 if (!observers_.might_have_observers())
62 Stop();
63 }
64
65 void PowerProfilerService::Start() {
66 DCHECK(INITIALIZED == status_);
67 status_ = PROFILING;
68
69 // send out power events immediately.
jeremy 2014/02/16 14:09:19 Send
Pan 2014/02/17 03:17:15 Done.
70 QueryData();
71
72 query_power_timer_.Start(FROM_HERE,
73 delay_, this, &PowerProfilerService::QueryData);
74 }
75
76 void PowerProfilerService::Stop() {
77 DCHECK(PROFILING == status_);
78
79 // stop timer, set status to INITIALIZED
jeremy 2014/02/16 14:09:19 I think this comment is redundant.
Pan 2014/02/17 03:17:15 Done.
80 query_power_timer_.Stop();
81 status_ = INITIALIZED;
82 }
83
84 void PowerProfilerService::QueryData() {
85 task_runner_->PostTask(
86 FROM_HERE, base::Bind(&PowerProfilerService::QueryDataOnTaskRunner,
87 base::Unretained(this)));
88 }
89
90 void PowerProfilerService::Notify(const PowerEventVector& events) {
91 FOR_EACH_OBSERVER(PowerProfilerObserver, observers_, OnPowerEvent(events));
92 }
93
94 void PowerProfilerService::QueryDataOnTaskRunner() {
95 DCHECK(task_runner_->RunsTasksOnCurrentThread());
96 if (PROFILING != status_)
97 return;
98
99 // Get Data and Notify
jeremy 2014/02/16 14:09:19 . at end of comment. Data and Notify shouldn't be
Pan 2014/02/17 03:17:15 Done.
100 PowerEventVector events = data_provider_->GetData();
101 if (events.size() != 0) {
102 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
103 &PowerProfilerService::Notify, base::Unretained(this), events));
104 }
105 }
106
107 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698