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.
5 #include "content/browser/screen_orientation/screen_orientation_message_filter_android.h"
7 #include "content/browser/screen_orientation/screen_orientation_delegate_android.h"
8 #include "content/common/screen_orientation_messages.h"
12 ScreenOrientationMessageFilterAndroid::ScreenOrientationMessageFilterAndroid()
13 : BrowserMessageFilter(ScreenOrientationMsgStart)
14 , listeners_count_(0) {
17 ScreenOrientationMessageFilterAndroid::~ScreenOrientationMessageFilterAndroid()
19 if (listeners_count_ > 0)
20 ScreenOrientationDelegateAndroid::StopAccurateListening();
23 bool ScreenOrientationMessageFilterAndroid::OnMessageReceived(
24 const IPC::Message& message) {
26 IPC_BEGIN_MESSAGE_MAP(ScreenOrientationMessageFilterAndroid, message)
27 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_StartListening,
29 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_StopListening,
31 IPC_MESSAGE_UNHANDLED(handled = false)
36 void ScreenOrientationMessageFilterAndroid::OnStartListening() {
38 if (listeners_count_ == 1)
39 ScreenOrientationDelegateAndroid::StartAccurateListening();
42 void ScreenOrientationMessageFilterAndroid::OnStopListening() {
43 DCHECK(listeners_count_ > 0);
45 if (listeners_count_ == 0)
46 ScreenOrientationDelegateAndroid::StopAccurateListening();
49 } // namespace content