Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / browser / screen_orientation / screen_orientation_message_filter_android.cc
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_delegate_android.h"
8 #include "content/common/screen_orientation_messages.h"
9
10 namespace content {
11
12 ScreenOrientationMessageFilterAndroid::ScreenOrientationMessageFilterAndroid()
13     : BrowserMessageFilter(ScreenOrientationMsgStart)
14     , listeners_count_(0) {
15 }
16
17 ScreenOrientationMessageFilterAndroid::~ScreenOrientationMessageFilterAndroid()
18 {
19   if (listeners_count_ > 0)
20     ScreenOrientationDelegateAndroid::StopAccurateListening();
21 }
22
23 bool 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
36 void ScreenOrientationMessageFilterAndroid::OnStartListening() {
37   ++listeners_count_;
38   if (listeners_count_ == 1)
39     ScreenOrientationDelegateAndroid::StartAccurateListening();
40 }
41
42 void ScreenOrientationMessageFilterAndroid::OnStopListening() {
43   DCHECK(listeners_count_ > 0);
44   --listeners_count_;
45   if (listeners_count_ == 0)
46     ScreenOrientationDelegateAndroid::StopAccurateListening();
47 }
48
49 }  // namespace content