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/screen_orientation/screen_orientation_message_filter_android.h" 6 7 #include "content/browser/screen_orientation/screen_orientation_provider_android.h" 8 #include "content/common/screen_orientation_messages.h" 9 10 namespace content { 11 ScreenOrientationMessageFilterAndroid()12ScreenOrientationMessageFilterAndroid::ScreenOrientationMessageFilterAndroid() 13 : BrowserMessageFilter(ScreenOrientationMsgStart) 14 , listeners_count_(0) { 15 } 16 ~ScreenOrientationMessageFilterAndroid()17ScreenOrientationMessageFilterAndroid::~ScreenOrientationMessageFilterAndroid() 18 { 19 if (listeners_count_ > 0) 20 ScreenOrientationProviderAndroid::StopAccurateListening(); 21 } 22 OnMessageReceived(const IPC::Message & message)23bool ScreenOrientationMessageFilterAndroid::OnMessageReceived( 24 const IPC::Message& message) { 25 bool handled = true; 26 IPC_BEGIN_MESSAGE_MAP(ScreenOrientationMessageFilterAndroid, message) 27 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_StartListening, 28 OnStartListening) 29 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_StopListening, 30 OnStopListening) 31 IPC_MESSAGE_UNHANDLED(handled = false) 32 IPC_END_MESSAGE_MAP() 33 return handled; 34 } 35 OnStartListening()36void ScreenOrientationMessageFilterAndroid::OnStartListening() { 37 ++listeners_count_; 38 if (listeners_count_ == 1) 39 ScreenOrientationProviderAndroid::StartAccurateListening(); 40 } 41 OnStopListening()42void ScreenOrientationMessageFilterAndroid::OnStopListening() { 43 DCHECK(listeners_count_ > 0); 44 --listeners_count_; 45 if (listeners_count_ == 0) 46 ScreenOrientationProviderAndroid::StopAccurateListening(); 47 } 48 49 } // namespace content 50