Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: content/browser/presentation/presentation_service_impl.cc

Issue 2622993002: [Presentation API] Move presentation.mojom to content/common/presentation (Closed)
Patch Set: Fix presentation_service_delegate. DEPS failure Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/presentation/presentation_service_impl.h" 5 #include "content/browser/presentation/presentation_service_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 19 matching lines...) Expand all
30 30
31 int GetNextRequestSessionId() { 31 int GetNextRequestSessionId() {
32 static int next_request_session_id = 0; 32 static int next_request_session_id = 0;
33 return ++next_request_session_id; 33 return ++next_request_session_id;
34 } 34 }
35 35
36 // Converts a PresentationConnectionMessage |input| to a ConnectionMessage. 36 // Converts a PresentationConnectionMessage |input| to a ConnectionMessage.
37 // |input|: The message to convert. 37 // |input|: The message to convert.
38 // |pass_ownership|: If true, function may reuse strings or buffers from 38 // |pass_ownership|: If true, function may reuse strings or buffers from
39 // |input| without copying. |input| can be freely modified. 39 // |input| without copying. |input| can be freely modified.
40 blink::mojom::ConnectionMessagePtr ToMojoConnectionMessage( 40 content::mojom::ConnectionMessagePtr ToMojoConnectionMessage(
41 content::PresentationConnectionMessage* input, 41 content::PresentationConnectionMessage* input,
42 bool pass_ownership) { 42 bool pass_ownership) {
43 DCHECK(input); 43 DCHECK(input);
44 blink::mojom::ConnectionMessagePtr output( 44 content::mojom::ConnectionMessagePtr output(
45 blink::mojom::ConnectionMessage::New()); 45 content::mojom::ConnectionMessage::New());
46 if (input->is_binary()) { 46 if (input->is_binary()) {
47 // binary data 47 // binary data
48 DCHECK(input->data); 48 DCHECK(input->data);
49 output->type = blink::mojom::PresentationMessageType::BINARY; 49 output->type = content::mojom::PresentationMessageType::BINARY;
50 if (pass_ownership) { 50 if (pass_ownership) {
51 output->data = std::move(*(input->data)); 51 output->data = std::move(*(input->data));
52 } else { 52 } else {
53 output->data = *(input->data); 53 output->data = *(input->data);
54 } 54 }
55 } else { 55 } else {
56 // string message 56 // string message
57 output->type = blink::mojom::PresentationMessageType::TEXT; 57 output->type = content::mojom::PresentationMessageType::TEXT;
58 if (pass_ownership) { 58 if (pass_ownership) {
59 output->message = std::move(input->message); 59 output->message = std::move(input->message);
60 } else { 60 } else {
61 output->message = input->message; 61 output->message = input->message;
62 } 62 }
63 } 63 }
64 return output; 64 return output;
65 } 65 }
66 66
67 std::unique_ptr<PresentationConnectionMessage> GetPresentationConnectionMessage( 67 std::unique_ptr<PresentationConnectionMessage> GetPresentationConnectionMessage(
68 blink::mojom::ConnectionMessagePtr input) { 68 content::mojom::ConnectionMessagePtr input) {
69 std::unique_ptr<content::PresentationConnectionMessage> output; 69 std::unique_ptr<content::PresentationConnectionMessage> output;
70 if (input.is_null()) 70 if (input.is_null())
71 return output; 71 return output;
72 72
73 switch (input->type) { 73 switch (input->type) {
74 case blink::mojom::PresentationMessageType::TEXT: { 74 case content::mojom::PresentationMessageType::TEXT: {
75 // Return nullptr PresentationConnectionMessage if invalid (unset 75 // Return nullptr PresentationConnectionMessage if invalid (unset
76 // |message|, 76 // |message|,
77 // set |data|, or size too large). 77 // set |data|, or size too large).
78 if (input->data || !input->message || 78 if (input->data || !input->message ||
79 input->message->size() > 79 input->message->size() >
80 content::kMaxPresentationConnectionMessageSize) 80 content::kMaxPresentationConnectionMessageSize)
81 return output; 81 return output;
82 82
83 output.reset( 83 output.reset(
84 new PresentationConnectionMessage(PresentationMessageType::TEXT)); 84 new PresentationConnectionMessage(PresentationMessageType::TEXT));
85 output->message = std::move(input->message.value()); 85 output->message = std::move(input->message.value());
86 return output; 86 return output;
87 } 87 }
88 case blink::mojom::PresentationMessageType::BINARY: { 88 case content::mojom::PresentationMessageType::BINARY: {
89 // Return nullptr PresentationConnectionMessage if invalid (unset |data|, 89 // Return nullptr PresentationConnectionMessage if invalid (unset |data|,
90 // set 90 // set
91 // |message|, or size too large). 91 // |message|, or size too large).
92 if (!input->data || input->message || 92 if (!input->data || input->message ||
93 input->data->size() > content::kMaxPresentationConnectionMessageSize) 93 input->data->size() > content::kMaxPresentationConnectionMessageSize)
94 return output; 94 return output;
95 95
96 output.reset( 96 output.reset(
97 new PresentationConnectionMessage(PresentationMessageType::BINARY)); 97 new PresentationConnectionMessage(PresentationMessageType::BINARY));
98 output->data.reset( 98 output->data.reset(
99 new std::vector<uint8_t>(std::move(input->data.value()))); 99 new std::vector<uint8_t>(std::move(input->data.value())));
100 return output; 100 return output;
101 } 101 }
102 } 102 }
103 103
104 NOTREACHED() << "Invalid presentation message type " << input->type; 104 NOTREACHED() << "Invalid presentation message type " << input->type;
105 return output; 105 return output;
106 } 106 }
107 107
108 void InvokeNewSessionCallbackWithError( 108 void InvokeNewSessionCallbackWithError(
109 const PresentationServiceImpl::NewSessionCallback& callback) { 109 const PresentationServiceImpl::NewSessionCallback& callback) {
110 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 110 callback.Run(content::mojom::PresentationSessionInfoPtr(),
111 blink::mojom::PresentationError::From(PresentationError( 111 content::mojom::PresentationError::From(PresentationError(
112 PRESENTATION_ERROR_UNKNOWN, "Internal error"))); 112 PRESENTATION_ERROR_UNKNOWN, "Internal error")));
113 } 113 }
114 114
115 } // namespace 115 } // namespace
116 116
117 PresentationServiceImpl::PresentationServiceImpl( 117 PresentationServiceImpl::PresentationServiceImpl(
118 RenderFrameHost* render_frame_host, 118 RenderFrameHost* render_frame_host,
119 WebContents* web_contents, 119 WebContents* web_contents,
120 ControllerPresentationServiceDelegate* controller_delegate, 120 ControllerPresentationServiceDelegate* controller_delegate,
121 ReceiverPresentationServiceDelegate* receiver_delegate) 121 ReceiverPresentationServiceDelegate* receiver_delegate)
(...skipping 19 matching lines...) Expand all
141 DVLOG(2) << __FUNCTION__ << ": " << render_process_id_ << ", " 141 DVLOG(2) << __FUNCTION__ << ": " << render_process_id_ << ", "
142 << render_frame_id_; 142 << render_frame_id_;
143 143
144 if (auto* delegate = GetPresentationServiceDelegate()) 144 if (auto* delegate = GetPresentationServiceDelegate())
145 delegate->RemoveObserver(render_process_id_, render_frame_id_); 145 delegate->RemoveObserver(render_process_id_, render_frame_id_);
146 } 146 }
147 147
148 // static 148 // static
149 void PresentationServiceImpl::CreateMojoService( 149 void PresentationServiceImpl::CreateMojoService(
150 RenderFrameHost* render_frame_host, 150 RenderFrameHost* render_frame_host,
151 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { 151 mojo::InterfaceRequest<content::mojom::PresentationService> request) {
152 DVLOG(2) << "CreateMojoService"; 152 DVLOG(2) << "CreateMojoService";
153 WebContents* web_contents = 153 WebContents* web_contents =
154 WebContents::FromRenderFrameHost(render_frame_host); 154 WebContents::FromRenderFrameHost(render_frame_host);
155 DCHECK(web_contents); 155 DCHECK(web_contents);
156 156
157 auto* browser = GetContentClient()->browser(); 157 auto* browser = GetContentClient()->browser();
158 auto* receiver_delegate = 158 auto* receiver_delegate =
159 browser->GetReceiverPresentationServiceDelegate(web_contents); 159 browser->GetReceiverPresentationServiceDelegate(web_contents);
160 160
161 // In current implementation, web_contents can be controller or receiver 161 // In current implementation, web_contents can be controller or receiver
162 // but not both. 162 // but not both.
163 auto* controller_delegate = 163 auto* controller_delegate =
164 receiver_delegate 164 receiver_delegate
165 ? nullptr 165 ? nullptr
166 : browser->GetControllerPresentationServiceDelegate(web_contents); 166 : browser->GetControllerPresentationServiceDelegate(web_contents);
167 167
168 // This object will be deleted when the RenderFrameHost is about to be 168 // This object will be deleted when the RenderFrameHost is about to be
169 // deleted (RenderFrameDeleted). 169 // deleted (RenderFrameDeleted).
170 PresentationServiceImpl* impl = new PresentationServiceImpl( 170 PresentationServiceImpl* impl = new PresentationServiceImpl(
171 render_frame_host, web_contents, controller_delegate, receiver_delegate); 171 render_frame_host, web_contents, controller_delegate, receiver_delegate);
172 impl->Bind(std::move(request)); 172 impl->Bind(std::move(request));
173 } 173 }
174 174
175 void PresentationServiceImpl::Bind( 175 void PresentationServiceImpl::Bind(
176 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { 176 mojo::InterfaceRequest<content::mojom::PresentationService> request) {
177 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>( 177 binding_.reset(new mojo::Binding<content::mojom::PresentationService>(
178 this, std::move(request))); 178 this, std::move(request)));
179 } 179 }
180 180
181 void PresentationServiceImpl::SetClient( 181 void PresentationServiceImpl::SetClient(
182 blink::mojom::PresentationServiceClientPtr client) { 182 content::mojom::PresentationServiceClientPtr client) {
183 DCHECK(!client_.get()); 183 DCHECK(!client_.get());
184 // TODO(imcheng): Set ErrorHandler to listen for errors. 184 // TODO(imcheng): Set ErrorHandler to listen for errors.
185 client_ = std::move(client); 185 client_ = std::move(client);
186 186
187 if (receiver_delegate_) { 187 if (receiver_delegate_) {
188 receiver_delegate_->RegisterReceiverConnectionAvailableCallback( 188 receiver_delegate_->RegisterReceiverConnectionAvailableCallback(
189 base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable, 189 base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable,
190 weak_factory_.GetWeakPtr())); 190 weak_factory_.GetWeakPtr()));
191 } 191 }
192 } 192 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 render_process_id_, render_frame_id_, listener_it->second.get()); 225 render_process_id_, render_frame_id_, listener_it->second.get());
226 screen_availability_listeners_.erase(listener_it); 226 screen_availability_listeners_.erase(listener_it);
227 } 227 }
228 228
229 void PresentationServiceImpl::StartSession( 229 void PresentationServiceImpl::StartSession(
230 const std::vector<GURL>& presentation_urls, 230 const std::vector<GURL>& presentation_urls,
231 const NewSessionCallback& callback) { 231 const NewSessionCallback& callback) {
232 DVLOG(2) << "StartSession"; 232 DVLOG(2) << "StartSession";
233 if (!controller_delegate_) { 233 if (!controller_delegate_) {
234 callback.Run( 234 callback.Run(
235 blink::mojom::PresentationSessionInfoPtr(), 235 content::mojom::PresentationSessionInfoPtr(),
236 blink::mojom::PresentationError::From(PresentationError( 236 content::mojom::PresentationError::From(PresentationError(
237 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found."))); 237 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found.")));
238 return; 238 return;
239 } 239 }
240 240
241 // There is a StartSession request in progress. To avoid queueing up 241 // There is a StartSession request in progress. To avoid queueing up
242 // requests, the incoming request is rejected. 242 // requests, the incoming request is rejected.
243 if (start_session_request_id_ != kInvalidRequestSessionId) { 243 if (start_session_request_id_ != kInvalidRequestSessionId) {
244 InvokeNewSessionCallbackWithError(callback); 244 InvokeNewSessionCallbackWithError(callback);
245 return; 245 return;
246 } 246 }
247 247
248 start_session_request_id_ = GetNextRequestSessionId(); 248 start_session_request_id_ = GetNextRequestSessionId();
249 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback)); 249 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback));
250 controller_delegate_->StartSession( 250 controller_delegate_->StartSession(
251 render_process_id_, render_frame_id_, presentation_urls, 251 render_process_id_, render_frame_id_, presentation_urls,
252 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, 252 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded,
253 weak_factory_.GetWeakPtr(), start_session_request_id_), 253 weak_factory_.GetWeakPtr(), start_session_request_id_),
254 base::Bind(&PresentationServiceImpl::OnStartSessionError, 254 base::Bind(&PresentationServiceImpl::OnStartSessionError,
255 weak_factory_.GetWeakPtr(), start_session_request_id_)); 255 weak_factory_.GetWeakPtr(), start_session_request_id_));
256 } 256 }
257 257
258 void PresentationServiceImpl::JoinSession( 258 void PresentationServiceImpl::JoinSession(
259 const std::vector<GURL>& presentation_urls, 259 const std::vector<GURL>& presentation_urls,
260 const base::Optional<std::string>& presentation_id, 260 const base::Optional<std::string>& presentation_id,
261 const NewSessionCallback& callback) { 261 const NewSessionCallback& callback) {
262 DVLOG(2) << "JoinSession"; 262 DVLOG(2) << "JoinSession";
263 if (!controller_delegate_) { 263 if (!controller_delegate_) {
264 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 264 callback.Run(content::mojom::PresentationSessionInfoPtr(),
265 blink::mojom::PresentationError::From(PresentationError( 265 content::mojom::PresentationError::From(PresentationError(
266 PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 266 PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
267 "Error joining route: No matching route"))); 267 "Error joining route: No matching route")));
268 return; 268 return;
269 } 269 }
270 270
271 int request_session_id = RegisterJoinSessionCallback(callback); 271 int request_session_id = RegisterJoinSessionCallback(callback);
272 if (request_session_id == kInvalidRequestSessionId) { 272 if (request_session_id == kInvalidRequestSessionId) {
273 InvokeNewSessionCallbackWithError(callback); 273 InvokeNewSessionCallbackWithError(callback);
274 return; 274 return;
275 } 275 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 307 }
308 308
309 void PresentationServiceImpl::OnStartSessionSucceeded( 309 void PresentationServiceImpl::OnStartSessionSucceeded(
310 int request_session_id, 310 int request_session_id,
311 const PresentationSessionInfo& session_info) { 311 const PresentationSessionInfo& session_info) {
312 if (request_session_id != start_session_request_id_) 312 if (request_session_id != start_session_request_id_)
313 return; 313 return;
314 314
315 CHECK(pending_start_session_cb_.get()); 315 CHECK(pending_start_session_cb_.get());
316 pending_start_session_cb_->Run( 316 pending_start_session_cb_->Run(
317 blink::mojom::PresentationSessionInfo::From(session_info), 317 content::mojom::PresentationSessionInfo::From(session_info),
318 blink::mojom::PresentationErrorPtr()); 318 content::mojom::PresentationErrorPtr());
319 ListenForConnectionStateChangeAndChangeState(session_info); 319 ListenForConnectionStateChangeAndChangeState(session_info);
320 pending_start_session_cb_.reset(); 320 pending_start_session_cb_.reset();
321 start_session_request_id_ = kInvalidRequestSessionId; 321 start_session_request_id_ = kInvalidRequestSessionId;
322 } 322 }
323 323
324 void PresentationServiceImpl::OnStartSessionError( 324 void PresentationServiceImpl::OnStartSessionError(
325 int request_session_id, 325 int request_session_id,
326 const PresentationError& error) { 326 const PresentationError& error) {
327 if (request_session_id != start_session_request_id_) 327 if (request_session_id != start_session_request_id_)
328 return; 328 return;
329 329
330 CHECK(pending_start_session_cb_.get()); 330 CHECK(pending_start_session_cb_.get());
331 pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(), 331 pending_start_session_cb_->Run(
332 blink::mojom::PresentationError::From(error)); 332 content::mojom::PresentationSessionInfoPtr(),
333 content::mojom::PresentationError::From(error));
333 pending_start_session_cb_.reset(); 334 pending_start_session_cb_.reset();
334 start_session_request_id_ = kInvalidRequestSessionId; 335 start_session_request_id_ = kInvalidRequestSessionId;
335 } 336 }
336 337
337 void PresentationServiceImpl::OnJoinSessionSucceeded( 338 void PresentationServiceImpl::OnJoinSessionSucceeded(
338 int request_session_id, 339 int request_session_id,
339 const PresentationSessionInfo& session_info) { 340 const PresentationSessionInfo& session_info) {
340 if (RunAndEraseJoinSessionMojoCallback( 341 if (RunAndEraseJoinSessionMojoCallback(
341 request_session_id, 342 request_session_id,
342 blink::mojom::PresentationSessionInfo::From(session_info), 343 content::mojom::PresentationSessionInfo::From(session_info),
343 blink::mojom::PresentationErrorPtr())) { 344 content::mojom::PresentationErrorPtr())) {
344 ListenForConnectionStateChangeAndChangeState(session_info); 345 ListenForConnectionStateChangeAndChangeState(session_info);
345 } 346 }
346 } 347 }
347 348
348 void PresentationServiceImpl::OnJoinSessionError( 349 void PresentationServiceImpl::OnJoinSessionError(
349 int request_session_id, 350 int request_session_id,
350 const PresentationError& error) { 351 const PresentationError& error) {
351 RunAndEraseJoinSessionMojoCallback( 352 RunAndEraseJoinSessionMojoCallback(
352 request_session_id, blink::mojom::PresentationSessionInfoPtr(), 353 request_session_id, content::mojom::PresentationSessionInfoPtr(),
353 blink::mojom::PresentationError::From(error)); 354 content::mojom::PresentationError::From(error));
354 } 355 }
355 356
356 bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback( 357 bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback(
357 int request_session_id, 358 int request_session_id,
358 blink::mojom::PresentationSessionInfoPtr session, 359 content::mojom::PresentationSessionInfoPtr session,
359 blink::mojom::PresentationErrorPtr error) { 360 content::mojom::PresentationErrorPtr error) {
360 auto it = pending_join_session_cbs_.find(request_session_id); 361 auto it = pending_join_session_cbs_.find(request_session_id);
361 if (it == pending_join_session_cbs_.end()) 362 if (it == pending_join_session_cbs_.end())
362 return false; 363 return false;
363 364
364 DCHECK(it->second.get()); 365 DCHECK(it->second.get());
365 it->second->Run(std::move(session), std::move(error)); 366 it->second->Run(std::move(session), std::move(error));
366 pending_join_session_cbs_.erase(it); 367 pending_join_session_cbs_.erase(it);
367 return true; 368 return true;
368 } 369 }
369 370
370 void PresentationServiceImpl::SetDefaultPresentationUrls( 371 void PresentationServiceImpl::SetDefaultPresentationUrls(
371 const std::vector<GURL>& presentation_urls) { 372 const std::vector<GURL>& presentation_urls) {
372 DVLOG(2) << "SetDefaultPresentationUrls"; 373 DVLOG(2) << "SetDefaultPresentationUrls";
373 if (!controller_delegate_) 374 if (!controller_delegate_)
374 return; 375 return;
375 376
376 if (default_presentation_urls_ == presentation_urls) 377 if (default_presentation_urls_ == presentation_urls)
377 return; 378 return;
378 379
379 default_presentation_urls_ = presentation_urls; 380 default_presentation_urls_ = presentation_urls;
380 controller_delegate_->SetDefaultPresentationUrls( 381 controller_delegate_->SetDefaultPresentationUrls(
381 render_process_id_, render_frame_id_, presentation_urls, 382 render_process_id_, render_frame_id_, presentation_urls,
382 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 383 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
383 weak_factory_.GetWeakPtr())); 384 weak_factory_.GetWeakPtr()));
384 } 385 }
385 386
386 void PresentationServiceImpl::SendConnectionMessage( 387 void PresentationServiceImpl::SendConnectionMessage(
387 blink::mojom::PresentationSessionInfoPtr session, 388 content::mojom::PresentationSessionInfoPtr session,
388 blink::mojom::ConnectionMessagePtr connection_message, 389 content::mojom::ConnectionMessagePtr connection_message,
389 const SendConnectionMessageCallback& callback) { 390 const SendConnectionMessageCallback& callback) {
390 DVLOG(2) << "SendConnectionMessage" 391 DVLOG(2) << "SendConnectionMessage"
391 << " [id]: " << session->id; 392 << " [id]: " << session->id;
392 DCHECK(!connection_message.is_null()); 393 DCHECK(!connection_message.is_null());
393 // send_message_callback_ should be null by now, otherwise resetting of 394 // send_message_callback_ should be null by now, otherwise resetting of
394 // send_message_callback_ with new callback will drop the old callback. 395 // send_message_callback_ with new callback will drop the old callback.
395 if (!controller_delegate_ || send_message_callback_) { 396 if (!controller_delegate_ || send_message_callback_) {
396 callback.Run(false); 397 callback.Run(false);
397 return; 398 return;
398 } 399 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 435
435 void PresentationServiceImpl::OnConnectionStateChanged( 436 void PresentationServiceImpl::OnConnectionStateChanged(
436 const PresentationSessionInfo& connection, 437 const PresentationSessionInfo& connection,
437 const PresentationConnectionStateChangeInfo& info) { 438 const PresentationConnectionStateChangeInfo& info) {
438 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged " 439 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged "
439 << "[presentation_id]: " << connection.presentation_id 440 << "[presentation_id]: " << connection.presentation_id
440 << " [state]: " << info.state; 441 << " [state]: " << info.state;
441 DCHECK(client_.get()); 442 DCHECK(client_.get());
442 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) { 443 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) {
443 client_->OnConnectionClosed( 444 client_->OnConnectionClosed(
444 blink::mojom::PresentationSessionInfo::From(connection), 445 content::mojom::PresentationSessionInfo::From(connection),
445 content::PresentationConnectionCloseReasonToMojo(info.close_reason), 446 content::PresentationConnectionCloseReasonToMojo(info.close_reason),
446 info.message); 447 info.message);
447 } else { 448 } else {
448 client_->OnConnectionStateChanged( 449 client_->OnConnectionStateChanged(
449 blink::mojom::PresentationSessionInfo::From(connection), 450 content::mojom::PresentationSessionInfo::From(connection),
450 PresentationConnectionStateToMojo(info.state)); 451 PresentationConnectionStateToMojo(info.state));
451 } 452 }
452 } 453 }
453 454
454 bool PresentationServiceImpl::FrameMatches( 455 bool PresentationServiceImpl::FrameMatches(
455 content::RenderFrameHost* render_frame_host) const { 456 content::RenderFrameHost* render_frame_host) const {
456 if (!render_frame_host) 457 if (!render_frame_host)
457 return false; 458 return false;
458 459
459 return render_frame_host->GetProcess()->GetID() == render_process_id_ && 460 return render_frame_host->GetProcess()->GetID() == render_process_id_ &&
460 render_frame_host->GetRoutingID() == render_frame_id_; 461 render_frame_host->GetRoutingID() == render_frame_id_;
461 } 462 }
462 463
463 PresentationServiceDelegate* 464 PresentationServiceDelegate*
464 PresentationServiceImpl::GetPresentationServiceDelegate() { 465 PresentationServiceImpl::GetPresentationServiceDelegate() {
465 return receiver_delegate_ 466 return receiver_delegate_
466 ? static_cast<PresentationServiceDelegate*>(receiver_delegate_) 467 ? static_cast<PresentationServiceDelegate*>(receiver_delegate_)
467 : static_cast<PresentationServiceDelegate*>(controller_delegate_); 468 : static_cast<PresentationServiceDelegate*>(controller_delegate_);
468 } 469 }
469 470
470 void PresentationServiceImpl::ListenForConnectionMessages( 471 void PresentationServiceImpl::ListenForConnectionMessages(
471 blink::mojom::PresentationSessionInfoPtr session) { 472 content::mojom::PresentationSessionInfoPtr session) {
472 DVLOG(2) << "ListenForConnectionMessages"; 473 DVLOG(2) << "ListenForConnectionMessages";
473 if (!controller_delegate_) 474 if (!controller_delegate_)
474 return; 475 return;
475 476
476 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); 477 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
477 controller_delegate_->ListenForConnectionMessages( 478 controller_delegate_->ListenForConnectionMessages(
478 render_process_id_, render_frame_id_, session_info, 479 render_process_id_, render_frame_id_, session_info,
479 base::Bind(&PresentationServiceImpl::OnConnectionMessages, 480 base::Bind(&PresentationServiceImpl::OnConnectionMessages,
480 weak_factory_.GetWeakPtr(), session_info)); 481 weak_factory_.GetWeakPtr(), session_info));
481 } 482 }
482 483
483 void PresentationServiceImpl::SetPresentationConnection( 484 void PresentationServiceImpl::SetPresentationConnection(
484 blink::mojom::PresentationSessionInfoPtr session, 485 content::mojom::PresentationSessionInfoPtr session,
485 blink::mojom::PresentationConnectionPtr controller_connection_ptr, 486 content::mojom::PresentationConnectionPtr controller_connection_ptr,
486 blink::mojom::PresentationConnectionRequest receiver_connection_request) { 487 content::mojom::PresentationConnectionRequest receiver_connection_request) {
487 DVLOG(2) << "SetPresentationConnection"; 488 DVLOG(2) << "SetPresentationConnection";
488 489
489 if (!controller_delegate_) 490 if (!controller_delegate_)
490 return; 491 return;
491 492
492 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); 493 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
493 controller_delegate_->ConnectToOffscreenPresentation( 494 controller_delegate_->ConnectToOffscreenPresentation(
494 render_process_id_, render_frame_id_, session_info, 495 render_process_id_, render_frame_id_, session_info,
495 std::move(controller_connection_ptr), 496 std::move(controller_connection_ptr),
496 std::move(receiver_connection_request)); 497 std::move(receiver_connection_request));
497 } 498 }
498 499
499 void PresentationServiceImpl::OnConnectionMessages( 500 void PresentationServiceImpl::OnConnectionMessages(
500 const PresentationSessionInfo& session, 501 const PresentationSessionInfo& session,
501 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& messages, 502 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& messages,
502 bool pass_ownership) { 503 bool pass_ownership) {
503 DCHECK(client_); 504 DCHECK(client_);
504 505
505 DVLOG(2) << "OnConnectionMessages" 506 DVLOG(2) << "OnConnectionMessages"
506 << " [id]: " << session.presentation_id; 507 << " [id]: " << session.presentation_id;
507 std::vector<blink::mojom::ConnectionMessagePtr> mojo_messages( 508 std::vector<content::mojom::ConnectionMessagePtr> mojo_messages(
508 messages.size()); 509 messages.size());
509 std::transform( 510 std::transform(
510 messages.begin(), messages.end(), mojo_messages.begin(), 511 messages.begin(), messages.end(), mojo_messages.begin(),
511 [pass_ownership]( 512 [pass_ownership](
512 const std::unique_ptr<PresentationConnectionMessage>& message) { 513 const std::unique_ptr<PresentationConnectionMessage>& message) {
513 return ToMojoConnectionMessage(message.get(), pass_ownership); 514 return ToMojoConnectionMessage(message.get(), pass_ownership);
514 }); 515 });
515 516
516 client_->OnConnectionMessagesReceived( 517 client_->OnConnectionMessagesReceived(
517 blink::mojom::PresentationSessionInfo::From(session), 518 content::mojom::PresentationSessionInfo::From(session),
518 std::move(mojo_messages)); 519 std::move(mojo_messages));
519 } 520 }
520 521
521 void PresentationServiceImpl::OnReceiverConnectionAvailable( 522 void PresentationServiceImpl::OnReceiverConnectionAvailable(
522 const content::PresentationSessionInfo& session_info, 523 const content::PresentationSessionInfo& session_info,
523 PresentationConnectionPtr controller_connection_ptr, 524 PresentationConnectionPtr controller_connection_ptr,
524 PresentationConnectionRequest receiver_connection_request) { 525 PresentationConnectionRequest receiver_connection_request) {
525 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable"; 526 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable";
526 527
527 client_->OnReceiverConnectionAvailable( 528 client_->OnReceiverConnectionAvailable(
528 blink::mojom::PresentationSessionInfo::From(session_info), 529 content::mojom::PresentationSessionInfo::From(session_info),
529 std::move(controller_connection_ptr), 530 std::move(controller_connection_ptr),
530 std::move(receiver_connection_request)); 531 std::move(receiver_connection_request));
531 } 532 }
532 533
533 void PresentationServiceImpl::DidNavigateAnyFrame( 534 void PresentationServiceImpl::DidNavigateAnyFrame(
534 content::RenderFrameHost* render_frame_host, 535 content::RenderFrameHost* render_frame_host,
535 const content::LoadCommittedDetails& details, 536 const content::LoadCommittedDetails& details,
536 const content::FrameNavigateParams& params) { 537 const content::FrameNavigateParams& params) {
537 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; 538 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame";
538 if (!FrameMatches(render_frame_host)) 539 if (!FrameMatches(render_frame_host))
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 584
584 screen_availability_listeners_.clear(); 585 screen_availability_listeners_.clear();
585 586
586 start_session_request_id_ = kInvalidRequestSessionId; 587 start_session_request_id_ = kInvalidRequestSessionId;
587 pending_start_session_cb_.reset(); 588 pending_start_session_cb_.reset();
588 589
589 pending_join_session_cbs_.clear(); 590 pending_join_session_cbs_.clear();
590 591
591 if (on_connection_messages_callback_.get()) { 592 if (on_connection_messages_callback_.get()) {
592 on_connection_messages_callback_->Run( 593 on_connection_messages_callback_->Run(
593 std::vector<blink::mojom::ConnectionMessagePtr>()); 594 std::vector<content::mojom::ConnectionMessagePtr>());
594 on_connection_messages_callback_.reset(); 595 on_connection_messages_callback_.reset();
595 } 596 }
596 597
597 if (send_message_callback_) { 598 if (send_message_callback_) {
598 // Run the callback with false, indicating the renderer to stop sending 599 // Run the callback with false, indicating the renderer to stop sending
599 // the requests and invalidate all pending requests. 600 // the requests and invalidate all pending requests.
600 send_message_callback_->Run(false); 601 send_message_callback_->Run(false);
601 send_message_callback_.reset(); 602 send_message_callback_.reset();
602 } 603 }
603 } 604 }
604 605
605 void PresentationServiceImpl::OnDelegateDestroyed() { 606 void PresentationServiceImpl::OnDelegateDestroyed() {
606 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; 607 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed";
607 controller_delegate_ = nullptr; 608 controller_delegate_ = nullptr;
608 receiver_delegate_ = nullptr; 609 receiver_delegate_ = nullptr;
609 Reset(); 610 Reset();
610 } 611 }
611 612
612 void PresentationServiceImpl::OnDefaultPresentationStarted( 613 void PresentationServiceImpl::OnDefaultPresentationStarted(
613 const PresentationSessionInfo& connection) { 614 const PresentationSessionInfo& connection) {
614 DCHECK(client_.get()); 615 DCHECK(client_.get());
615 client_->OnDefaultSessionStarted( 616 client_->OnDefaultSessionStarted(
616 blink::mojom::PresentationSessionInfo::From(connection)); 617 content::mojom::PresentationSessionInfo::From(connection));
617 ListenForConnectionStateChangeAndChangeState(connection); 618 ListenForConnectionStateChangeAndChangeState(connection);
618 } 619 }
619 620
620 PresentationServiceImpl::ScreenAvailabilityListenerImpl:: 621 PresentationServiceImpl::ScreenAvailabilityListenerImpl::
621 ScreenAvailabilityListenerImpl(const GURL& availability_url, 622 ScreenAvailabilityListenerImpl(const GURL& availability_url,
622 PresentationServiceImpl* service) 623 PresentationServiceImpl* service)
623 : availability_url_(availability_url), service_(service) { 624 : availability_url_(availability_url), service_(service) {
624 DCHECK(service_); 625 DCHECK(service_);
625 DCHECK(service_->client_.get()); 626 DCHECK(service_->client_.get());
626 } 627 }
(...skipping 22 matching lines...) Expand all
649 : callback_(callback) { 650 : callback_(callback) {
650 } 651 }
651 652
652 PresentationServiceImpl::NewSessionCallbackWrapper 653 PresentationServiceImpl::NewSessionCallbackWrapper
653 ::~NewSessionCallbackWrapper() { 654 ::~NewSessionCallbackWrapper() {
654 if (!callback_.is_null()) 655 if (!callback_.is_null())
655 InvokeNewSessionCallbackWithError(callback_); 656 InvokeNewSessionCallbackWithError(callback_);
656 } 657 }
657 658
658 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( 659 void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
659 blink::mojom::PresentationSessionInfoPtr session, 660 content::mojom::PresentationSessionInfoPtr session,
660 blink::mojom::PresentationErrorPtr error) { 661 content::mojom::PresentationErrorPtr error) {
661 DCHECK(!callback_.is_null()); 662 DCHECK(!callback_.is_null());
662 callback_.Run(std::move(session), std::move(error)); 663 callback_.Run(std::move(session), std::move(error));
663 callback_.Reset(); 664 callback_.Reset();
664 } 665 }
665 666
666 } // namespace content 667 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698