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

Unified Diff: content/child/power_monitor_broadcast_source.cc

Issue 2433203003: Mojoify PoweMonitorMessageBroadcaster IPC from browser to child process (Closed)
Patch Set: code rebase Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/child/power_monitor_broadcast_source.cc
diff --git a/content/child/power_monitor_broadcast_source.cc b/content/child/power_monitor_broadcast_source.cc
index bf6684f4dbb2acae2834363efd5508ed6700c10e..94d11a87f5b6dc4ac96469271a6cb5c3d1ee1cd2 100644
--- a/content/child/power_monitor_broadcast_source.cc
+++ b/content/child/power_monitor_broadcast_source.cc
@@ -6,102 +6,40 @@
#include "base/location.h"
#include "base/macros.h"
-#include "base/single_thread_task_runner.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "content/common/power_monitor_messages.h"
-#include "ipc/message_filter.h"
+#include "content/child/child_thread_impl.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "services/service_manager/public/cpp/interface_provider.h"
namespace content {
-class PowerMessageFilter : public IPC::MessageFilter {
- public:
- PowerMessageFilter(PowerMonitorBroadcastSource* source,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : source_(source), task_runner_(task_runner) {}
-
- bool OnMessageReceived(const IPC::Message& message) override {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(PowerMessageFilter, message)
- IPC_MESSAGE_HANDLER(PowerMonitorMsg_PowerStateChange, OnPowerStateChange)
- IPC_MESSAGE_HANDLER(PowerMonitorMsg_Suspend, OnSuspend)
- IPC_MESSAGE_HANDLER(PowerMonitorMsg_Resume, OnResume)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
- }
-
- void RemoveSource() {
- source_ = NULL;
- }
-
- private:
- friend class base::RefCounted<PowerMessageFilter>;
-
- ~PowerMessageFilter() override{};
-
- void OnPowerStateChange(bool on_battery_power) {
- task_runner_->PostTask(
- FROM_HERE, base::Bind(&PowerMessageFilter::NotifySourcePowerStateChange,
- this, on_battery_power));
- }
- void OnSuspend() {
- task_runner_->PostTask(
- FROM_HERE, base::Bind(&PowerMessageFilter::NotifySourceSuspend, this));
- }
- void OnResume() {
- task_runner_->PostTask(
- FROM_HERE, base::Bind(&PowerMessageFilter::NotifySourceResume, this));
- }
-
- void NotifySourcePowerStateChange(bool on_battery_power) {
- if (source_)
- source_->OnPowerStateChange(on_battery_power);
- }
- void NotifySourceSuspend() {
- if (source_)
- source_->OnSuspend();
- }
- void NotifySourceResume() {
- if (source_)
- source_->OnResume();
- }
-
- // source_ should only be accessed on the thread associated with
- // message_loop_.
- PowerMonitorBroadcastSource* source_;
- scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
-
- DISALLOW_COPY_AND_ASSIGN(PowerMessageFilter);
-};
-
PowerMonitorBroadcastSource::PowerMonitorBroadcastSource()
- : last_reported_battery_power_state_(false) {
- message_filter_ =
- new PowerMessageFilter(this, base::ThreadTaskRunnerHandle::Get());
+ : last_reported_battery_power_state_(false), binding_(this) {
+ // May be null during test execution.
+ if (ChildThreadImpl::current()) {
+ device::mojom::PowerMonitorPtr power_monitor;
+ ChildThreadImpl::current()->GetRemoteInterfaces()->GetInterface(
+ mojo::GetProxy(&power_monitor));
+ power_monitor->SetClient(binding_.CreateInterfacePtrAndBind());
+ }
}
PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() {
- message_filter_->RemoveSource();
-}
-
-IPC::MessageFilter* PowerMonitorBroadcastSource::GetMessageFilter() {
- return message_filter_.get();
}
bool PowerMonitorBroadcastSource::IsOnBatteryPowerImpl() {
return last_reported_battery_power_state_;
}
-void PowerMonitorBroadcastSource::OnPowerStateChange(bool on_battery_power) {
+void PowerMonitorBroadcastSource::PowerStateChange(bool on_battery_power) {
last_reported_battery_power_state_ = on_battery_power;
ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT);
}
-void PowerMonitorBroadcastSource::OnSuspend() {
+void PowerMonitorBroadcastSource::Suspend() {
ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT);
}
-void PowerMonitorBroadcastSource::OnResume() {
+void PowerMonitorBroadcastSource::Resume() {
ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT);
}
« no previous file with comments | « content/child/power_monitor_broadcast_source.h ('k') | content/child/power_monitor_broadcast_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698