Android media: VideoFrame should not store so many sync points.
[chromium-blink-merge.git] / content / browser / screen_orientation / screen_orientation_dispatcher_host.cc
blobde5b089703fb5a227ad3676c347f6f93b3205b23
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_dispatcher_host.h"
7 #include "content/browser/screen_orientation/screen_orientation_provider.h"
8 #include "content/common/screen_orientation_messages.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/render_process_host.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/render_widget_host.h"
13 #include "content/public/browser/web_contents.h"
14 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
16 namespace content {
18 ScreenOrientationDispatcherHost::LockInformation::LockInformation(
19 int request_id, int process_id, int routing_id)
20 : request_id(request_id),
21 process_id(process_id),
22 routing_id(routing_id) {
25 ScreenOrientationDispatcherHost::ScreenOrientationDispatcherHost(
26 WebContents* web_contents)
27 : WebContentsObserver(web_contents),
28 current_lock_(NULL) {
29 provider_.reset(ScreenOrientationProvider::Create(this, web_contents));
32 ScreenOrientationDispatcherHost::~ScreenOrientationDispatcherHost() {
33 ResetCurrentLock();
36 void ScreenOrientationDispatcherHost::ResetCurrentLock() {
37 if (current_lock_) {
38 delete current_lock_;
39 current_lock_ = 0;
43 bool ScreenOrientationDispatcherHost::OnMessageReceived(
44 const IPC::Message& message,
45 RenderFrameHost* render_frame_host) {
46 bool handled = true;
48 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ScreenOrientationDispatcherHost, message,
49 render_frame_host)
50 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_LockRequest, OnLockRequest)
51 IPC_MESSAGE_HANDLER(ScreenOrientationHostMsg_Unlock, OnUnlockRequest)
52 IPC_MESSAGE_UNHANDLED(handled = false)
53 IPC_END_MESSAGE_MAP()
55 return handled;
58 RenderFrameHost*
59 ScreenOrientationDispatcherHost::GetRenderFrameHostForRequestID(
60 int request_id) {
61 if (!current_lock_ || current_lock_->request_id != request_id)
62 return NULL;
64 return RenderFrameHost::FromID(current_lock_->process_id,
65 current_lock_->routing_id);
68 void ScreenOrientationDispatcherHost::NotifyLockSuccess(int request_id) {
69 RenderFrameHost* render_frame_host =
70 GetRenderFrameHostForRequestID(request_id);
71 if (!render_frame_host)
72 return;
74 render_frame_host->Send(new ScreenOrientationMsg_LockSuccess(
75 render_frame_host->GetRoutingID(), request_id));
76 ResetCurrentLock();
79 void ScreenOrientationDispatcherHost::NotifyLockError(
80 int request_id, blink::WebLockOrientationError error) {
81 RenderFrameHost* render_frame_host =
82 GetRenderFrameHostForRequestID(request_id);
83 if (!render_frame_host)
84 return;
86 render_frame_host->Send(new ScreenOrientationMsg_LockError(
87 render_frame_host->GetRoutingID(), request_id, error));
88 ResetCurrentLock();
91 void ScreenOrientationDispatcherHost::OnOrientationChange() {
92 if (provider_)
93 provider_->OnOrientationChange();
96 void ScreenOrientationDispatcherHost::OnLockRequest(
97 RenderFrameHost* render_frame_host,
98 blink::WebScreenOrientationLockType orientation,
99 int request_id) {
100 if (current_lock_) {
101 NotifyLockError(current_lock_->request_id,
102 blink::WebLockOrientationErrorCanceled);
105 current_lock_ = new LockInformation(request_id,
106 render_frame_host->GetProcess()->GetID(),
107 render_frame_host->GetRoutingID());
109 if (!provider_) {
110 NotifyLockError(request_id,
111 blink::WebLockOrientationErrorNotAvailable);
112 return;
115 provider_->LockOrientation(request_id, orientation);
118 void ScreenOrientationDispatcherHost::OnUnlockRequest(
119 RenderFrameHost* render_frame_host) {
120 if (current_lock_) {
121 NotifyLockError(current_lock_->request_id,
122 blink::WebLockOrientationErrorCanceled);
125 if (!provider_.get())
126 return;
128 provider_->UnlockOrientation();
131 } // namespace content