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 | |
17 PresentationDispatcher::~PresentationDispatcher() {} | |
mark a. foltz
2015/01/27 21:56:09
Is it okay to drop the ptr to presentation_service
whywhat
2015/01/28 01:52:37
presentation_service_ is a smart pointer (mojo::In
| |
18 | |
19 void PresentationDispatcher::setController( | |
20 blink::WebPresentationController* controller) { | |
21 // Provide the service with the callback to get the next |availablechange| | |
mark a. foltz
2015/01/27 21:56:09
Should we CHECK that controller_ == nullptr - assu
whywhat
2015/01/28 01:52:37
You mean that either controller_ or controller is
| |
22 // event if needed. Ignore a null or the same controller though. | |
23 if (controller != nullptr && controller_ != controller) | |
24 updateAvailableChangeWatched(controller->isAvailableChangeWatched()); | |
25 controller_ = controller; | |
26 } | |
27 | |
28 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { | |
29 ConnectToPresentationServiceIfNeeded(); | |
30 if (watched) { | |
31 presentation_service_->GetScreenAvailability( | |
mark a. foltz
2015/01/27 21:56:09
The lifetime of the PresentationDispatcher is tied
whywhat
2015/01/28 01:52:38
I don't know for sure. But my guess is that the ca
qsr
2015/01/28 15:41:10
The callback is stored on the persentation_service
| |
32 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, | |
33 base::Unretained(this))); | |
34 } | |
35 } | |
36 | |
37 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { | |
38 if (!controller_) | |
39 return; | |
40 | |
41 // Reset the callback to get the next event. | |
42 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); | |
43 | |
44 controller_->didChangeAvailability(available); | |
45 } | |
46 | |
47 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | |
48 if (presentation_service_.get()) | |
49 return; | |
50 | |
51 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | |
52 &presentation_service_); | |
mark a. foltz
2015/01/27 21:56:09
Can this ever fail? Do we need to CHECK the resul
whywhat
2015/01/28 01:52:37
This either calls the service's CreateService imme
qsr
2015/01/28 15:41:10
It depends a lot what you mean by fail. After this
| |
53 } | |
54 | |
55 } // namespace content | |
OLD | NEW |