Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / begin_frame_observer_proxy.cc
blob06baa18bd2a128390dd6436cf581077043c0f5fc
1 // Copyright 2015 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/renderer_host/begin_frame_observer_proxy.h"
7 namespace content {
9 BeginFrameObserverProxy::BeginFrameObserverProxy(
10 BeginFrameObserverProxyClient* client)
11 : needs_begin_frames_(false),
12 client_(client),
13 compositor_(nullptr) {
16 BeginFrameObserverProxy::~BeginFrameObserverProxy() {
17 DCHECK(!compositor_);
20 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) {
21 if (needs_begin_frames_ == needs_begin_frames)
22 return;
24 needs_begin_frames_ = needs_begin_frames;
26 // In some cases, BeginFrame message is requested before |client_|'s window is
27 // added in the root window hierarchy.
28 if (!compositor_)
29 return;
31 if (needs_begin_frames)
32 StartObservingBeginFrames();
33 else
34 StopObservingBeginFrames();
37 void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) {
38 DCHECK(!compositor_);
39 DCHECK(compositor);
41 compositor_ = compositor;
42 compositor_->AddObserver(this);
43 if (needs_begin_frames_)
44 StartObservingBeginFrames();
47 void BeginFrameObserverProxy::ResetCompositor() {
48 if (!compositor_)
49 return;
50 compositor_->RemoveObserver(this);
52 if (needs_begin_frames_)
53 StopObservingBeginFrames();
54 compositor_ = nullptr;
57 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) {
58 if (last_sent_begin_frame_args_.frame_time != args.frame_time)
59 client_->SendBeginFrame(args);
60 last_sent_begin_frame_args_ = args;
63 void BeginFrameObserverProxy::OnCompositingShuttingDown(
64 ui::Compositor* compositor) {
65 ResetCompositor();
68 void BeginFrameObserverProxy::StartObservingBeginFrames() {
69 DCHECK(compositor_);
70 compositor_->AddBeginFrameObserver(this);
73 void BeginFrameObserverProxy::StopObservingBeginFrames() {
74 DCHECK(compositor_);
75 compositor_->RemoveBeginFrameObserver(this);
78 } // namespace content