Index: content/browser/power_profiler/power_profiler_host.cc |
diff --git a/content/browser/power_profiler/power_profiler_host.cc b/content/browser/power_profiler/power_profiler_host.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f6d72e4adf44413a308ea1f2eb0fb4805eb8509c |
--- /dev/null |
+++ b/content/browser/power_profiler/power_profiler_host.cc |
@@ -0,0 +1,66 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/power_profiler/power_profiler_host.h" |
+ |
+#include "base/debug/trace_event.h" |
+#include "base/logging.h" |
+#include "content/browser/power_profiler/power_profiler_service.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+namespace content { |
+ |
+PowerProfilerHost::PowerProfilerHost() : resolution_(NORMAL) { |
+} |
+ |
+PowerProfilerHost::~PowerProfilerHost() { |
+} |
+ |
+bool PowerProfilerHost::Register() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ if (!PowerProfilerService::Get() || PowerProfilerService::UNINITIALIZED == |
+ PowerProfilerService::Get()->status()) |
+ return false; |
+ |
+ if (BrowserThread::PostTask(BrowserThread::POWER_PROFILER, FROM_HERE, |
+ base::Bind(&PowerProfilerHost::RegisterWrapper, this))) |
+ return true; |
+ |
+ return false; |
+} |
+ |
+void PowerProfilerHost::UnRegister() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ if (PowerProfilerService::Get()) |
+ BrowserThread::PostTask(BrowserThread::POWER_PROFILER, FROM_HERE, |
+ base::Bind(&PowerProfilerHost::UnRegisterWrapper, this)); |
+} |
+ |
+void PowerProfilerHost::SetResolution(Resolution resolution) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ resolution_ = resolution; |
+ if (PowerProfilerService::Get()) |
+ BrowserThread::PostTask(BrowserThread::POWER_PROFILER, FROM_HERE, |
+ base::Bind(&PowerProfilerHost::SetResolutionWrapper, this)); |
+} |
+ |
+void PowerProfilerHost::RegisterWrapper() { |
+ if (PowerProfilerService::Get()) |
+ PowerProfilerService::Get()->AddObserver(this); |
+} |
+ |
+void PowerProfilerHost::UnRegisterWrapper() { |
+ if (PowerProfilerService::Get()) |
+ PowerProfilerService::Get()->RemoveObserver(this); |
+} |
+ |
+void PowerProfilerHost::SetResolutionWrapper() { |
+ if (PowerProfilerService::Get()) |
+ PowerProfilerService::Get()->UpdateResolution(); |
+} |
+ |
+} // namespace base |