OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "content/renderer/presentation/presentation_dispatcher.h" | |
6 | |
7 #include "content/common/presentation/presentation_service.mojom.h" | |
8 #include "content/public/common/service_registry.h" | |
9 #include "content/public/renderer/render_frame.h" | |
10 #include "third_party/WebKit/public/platform/WebPresentationController.h" | |
11 | |
12 namespace content { | |
13 | |
14 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) | |
15 : RenderFrameObserver(render_frame), | |
16 controller_(nullptr) { | |
17 } | |
18 | |
19 PresentationDispatcher::~PresentationDispatcher() { | |
20 if (controller_) { | |
21 updateAvailableChangeWatched(false); | |
22 controller_->onClientDestroyed(); | |
23 } | |
24 } | |
25 | |
26 void PresentationDispatcher::setController( | |
27 blink::WebPresentationController* controller) { | |
28 // There shouldn't be any swapping from one non-null controller to another. | |
29 CHECK(controller != controller_ && (!controller || !controller_)); | |
Avi (use Gerrit)
2015/01/28 19:04:05
Why CHECK? We usually do DCHECK for programming er
whywhat
2015/01/28 20:26:04
Done.
| |
30 controller_ = controller; | |
31 | |
32 // Notify the service that the controller has changed so it could either | |
33 // stop or start sending the availability events. | |
34 updateAvailableChangeWatched( | |
35 controller && controller->isAvailableChangeWatched()); | |
36 } | |
37 | |
38 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { | |
39 ConnectToPresentationServiceIfNeeded(); | |
40 if (watched) { | |
41 presentation_service_->GetScreenAvailability( | |
42 mojo::String(), | |
43 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, | |
44 base::Unretained(this))); | |
45 } else { | |
46 presentation_service_->OnScreenAvailabilityListenerRemoved(); | |
47 } | |
48 } | |
49 | |
50 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { | |
51 if (!controller_) | |
52 return; | |
53 | |
54 // Reset the callback to get the next event. | |
55 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); | |
56 | |
57 controller_->didChangeAvailability(available); | |
58 } | |
59 | |
60 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | |
61 if (presentation_service_.get()) | |
62 return; | |
63 | |
64 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | |
65 &presentation_service_); | |
66 } | |
67 | |
68 } // namespace content | |
OLD | NEW |