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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return; | 55 return; |
56 | 56 |
57 observers_.AddObserver(observer); | 57 observers_.AddObserver(observer); |
58 if (status_ != PROFILING) | 58 if (status_ != PROFILING) |
59 Start(); | 59 Start(); |
60 } | 60 } |
61 | 61 |
62 void PowerProfilerService::RemoveObserver(PowerProfilerObserver* observer) { | 62 void PowerProfilerService::RemoveObserver(PowerProfilerObserver* observer) { |
63 observers_.RemoveObserver(observer); | 63 observers_.RemoveObserver(observer); |
64 | 64 |
65 if (!observers_.might_have_observers()) | 65 if (status_ == PROFILING && !observers_.might_have_observers()) |
66 Stop(); | 66 Stop(); |
67 } | 67 } |
68 | 68 |
69 void PowerProfilerService::Start() { | 69 void PowerProfilerService::Start() { |
70 DCHECK(status_ == INITIALIZED); | 70 DCHECK(status_ == INITIALIZED); |
71 status_ = PROFILING; | 71 status_ = PROFILING; |
72 | 72 |
73 // Send out power events immediately. | 73 // Send out power events immediately. |
74 QueryData(); | 74 QueryData(); |
75 | 75 |
(...skipping 24 matching lines...) Expand all Loading... |
100 | 100 |
101 // Get data and notify. | 101 // Get data and notify. |
102 PowerEventVector events = data_provider_->GetData(); | 102 PowerEventVector events = data_provider_->GetData(); |
103 if (events.size() != 0) { | 103 if (events.size() != 0) { |
104 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 104 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
105 &PowerProfilerService::Notify, base::Unretained(this), events)); | 105 &PowerProfilerService::Notify, base::Unretained(this), events)); |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 } // namespace content | 109 } // namespace content |
OLD | NEW |