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

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 #include and OWNERS 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 PresentationServiceDelegate* delegate) 120 PresentationServiceDelegate* delegate)
121 : WebContentsObserver(web_contents), 121 : WebContentsObserver(web_contents),
(...skipping 13 matching lines...) Expand all
135 } 135 }
136 136
137 PresentationServiceImpl::~PresentationServiceImpl() { 137 PresentationServiceImpl::~PresentationServiceImpl() {
138 if (delegate_) 138 if (delegate_)
139 delegate_->RemoveObserver(render_process_id_, render_frame_id_); 139 delegate_->RemoveObserver(render_process_id_, render_frame_id_);
140 } 140 }
141 141
142 // static 142 // static
143 void PresentationServiceImpl::CreateMojoService( 143 void PresentationServiceImpl::CreateMojoService(
144 RenderFrameHost* render_frame_host, 144 RenderFrameHost* render_frame_host,
145 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { 145 mojo::InterfaceRequest<content::mojom::PresentationService> request) {
146 DVLOG(2) << "CreateMojoService"; 146 DVLOG(2) << "CreateMojoService";
147 WebContents* web_contents = 147 WebContents* web_contents =
148 WebContents::FromRenderFrameHost(render_frame_host); 148 WebContents::FromRenderFrameHost(render_frame_host);
149 DCHECK(web_contents); 149 DCHECK(web_contents);
150 150
151 // This object will be deleted when the RenderFrameHost is about to be 151 // This object will be deleted when the RenderFrameHost is about to be
152 // deleted (RenderFrameDeleted). 152 // deleted (RenderFrameDeleted).
153 PresentationServiceImpl* impl = new PresentationServiceImpl( 153 PresentationServiceImpl* impl = new PresentationServiceImpl(
154 render_frame_host, 154 render_frame_host,
155 web_contents, 155 web_contents,
156 GetContentClient()->browser()->GetPresentationServiceDelegate( 156 GetContentClient()->browser()->GetPresentationServiceDelegate(
157 web_contents)); 157 web_contents));
158 impl->Bind(std::move(request)); 158 impl->Bind(std::move(request));
159 } 159 }
160 160
161 void PresentationServiceImpl::Bind( 161 void PresentationServiceImpl::Bind(
162 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { 162 mojo::InterfaceRequest<content::mojom::PresentationService> request) {
163 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>( 163 binding_.reset(new mojo::Binding<content::mojom::PresentationService>(
164 this, std::move(request))); 164 this, std::move(request)));
165 } 165 }
166 166
167 void PresentationServiceImpl::SetClient( 167 void PresentationServiceImpl::SetClient(
168 blink::mojom::PresentationServiceClientPtr client) { 168 content::mojom::PresentationServiceClientPtr client) {
169 DCHECK(!client_.get()); 169 DCHECK(!client_.get());
170 // TODO(imcheng): Set ErrorHandler to listen for errors. 170 // TODO(imcheng): Set ErrorHandler to listen for errors.
171 client_ = std::move(client); 171 client_ = std::move(client);
172 } 172 }
173 173
174 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { 174 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) {
175 DVLOG(2) << "ListenForScreenAvailability " << url.spec(); 175 DVLOG(2) << "ListenForScreenAvailability " << url.spec();
176 if (!delegate_) { 176 if (!delegate_) {
177 client_->OnScreenAvailabilityUpdated(url, false); 177 client_->OnScreenAvailabilityUpdated(url, false);
178 return; 178 return;
(...skipping 28 matching lines...) Expand all
207 render_process_id_, render_frame_id_, listener_it->second.get()); 207 render_process_id_, render_frame_id_, listener_it->second.get());
208 screen_availability_listeners_.erase(listener_it); 208 screen_availability_listeners_.erase(listener_it);
209 } 209 }
210 210
211 void PresentationServiceImpl::StartSession( 211 void PresentationServiceImpl::StartSession(
212 const std::vector<GURL>& presentation_urls, 212 const std::vector<GURL>& presentation_urls,
213 const NewSessionCallback& callback) { 213 const NewSessionCallback& callback) {
214 DVLOG(2) << "StartSession"; 214 DVLOG(2) << "StartSession";
215 if (!delegate_) { 215 if (!delegate_) {
216 callback.Run( 216 callback.Run(
217 blink::mojom::PresentationSessionInfoPtr(), 217 content::mojom::PresentationSessionInfoPtr(),
218 blink::mojom::PresentationError::From(PresentationError( 218 content::mojom::PresentationError::From(PresentationError(
219 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found."))); 219 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found.")));
220 return; 220 return;
221 } 221 }
222 222
223 // There is a StartSession request in progress. To avoid queueing up 223 // There is a StartSession request in progress. To avoid queueing up
224 // requests, the incoming request is rejected. 224 // requests, the incoming request is rejected.
225 if (start_session_request_id_ != kInvalidRequestSessionId) { 225 if (start_session_request_id_ != kInvalidRequestSessionId) {
226 InvokeNewSessionCallbackWithError(callback); 226 InvokeNewSessionCallbackWithError(callback);
227 return; 227 return;
228 } 228 }
229 229
230 start_session_request_id_ = GetNextRequestSessionId(); 230 start_session_request_id_ = GetNextRequestSessionId();
231 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback)); 231 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback));
232 delegate_->StartSession( 232 delegate_->StartSession(
233 render_process_id_, render_frame_id_, presentation_urls, 233 render_process_id_, render_frame_id_, presentation_urls,
234 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, 234 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded,
235 weak_factory_.GetWeakPtr(), start_session_request_id_), 235 weak_factory_.GetWeakPtr(), start_session_request_id_),
236 base::Bind(&PresentationServiceImpl::OnStartSessionError, 236 base::Bind(&PresentationServiceImpl::OnStartSessionError,
237 weak_factory_.GetWeakPtr(), start_session_request_id_)); 237 weak_factory_.GetWeakPtr(), start_session_request_id_));
238 } 238 }
239 239
240 void PresentationServiceImpl::JoinSession( 240 void PresentationServiceImpl::JoinSession(
241 const std::vector<GURL>& presentation_urls, 241 const std::vector<GURL>& presentation_urls,
242 const base::Optional<std::string>& presentation_id, 242 const base::Optional<std::string>& presentation_id,
243 const NewSessionCallback& callback) { 243 const NewSessionCallback& callback) {
244 DVLOG(2) << "JoinSession"; 244 DVLOG(2) << "JoinSession";
245 if (!delegate_) { 245 if (!delegate_) {
246 callback.Run(blink::mojom::PresentationSessionInfoPtr(), 246 callback.Run(content::mojom::PresentationSessionInfoPtr(),
247 blink::mojom::PresentationError::From(PresentationError( 247 content::mojom::PresentationError::From(PresentationError(
248 PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 248 PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
249 "Error joining route: No matching route"))); 249 "Error joining route: No matching route")));
250 return; 250 return;
251 } 251 }
252 252
253 int request_session_id = RegisterJoinSessionCallback(callback); 253 int request_session_id = RegisterJoinSessionCallback(callback);
254 if (request_session_id == kInvalidRequestSessionId) { 254 if (request_session_id == kInvalidRequestSessionId) {
255 InvokeNewSessionCallbackWithError(callback); 255 InvokeNewSessionCallbackWithError(callback);
256 return; 256 return;
257 } 257 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 289 }
290 290
291 void PresentationServiceImpl::OnStartSessionSucceeded( 291 void PresentationServiceImpl::OnStartSessionSucceeded(
292 int request_session_id, 292 int request_session_id,
293 const PresentationSessionInfo& session_info) { 293 const PresentationSessionInfo& session_info) {
294 if (request_session_id != start_session_request_id_) 294 if (request_session_id != start_session_request_id_)
295 return; 295 return;
296 296
297 CHECK(pending_start_session_cb_.get()); 297 CHECK(pending_start_session_cb_.get());
298 pending_start_session_cb_->Run( 298 pending_start_session_cb_->Run(
299 blink::mojom::PresentationSessionInfo::From(session_info), 299 content::mojom::PresentationSessionInfo::From(session_info),
300 blink::mojom::PresentationErrorPtr()); 300 content::mojom::PresentationErrorPtr());
301 ListenForConnectionStateChangeAndChangeState(session_info); 301 ListenForConnectionStateChangeAndChangeState(session_info);
302 pending_start_session_cb_.reset(); 302 pending_start_session_cb_.reset();
303 start_session_request_id_ = kInvalidRequestSessionId; 303 start_session_request_id_ = kInvalidRequestSessionId;
304 } 304 }
305 305
306 void PresentationServiceImpl::OnStartSessionError( 306 void PresentationServiceImpl::OnStartSessionError(
307 int request_session_id, 307 int request_session_id,
308 const PresentationError& error) { 308 const PresentationError& error) {
309 if (request_session_id != start_session_request_id_) 309 if (request_session_id != start_session_request_id_)
310 return; 310 return;
311 311
312 CHECK(pending_start_session_cb_.get()); 312 CHECK(pending_start_session_cb_.get());
313 pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(), 313 pending_start_session_cb_->Run(
314 blink::mojom::PresentationError::From(error)); 314 content::mojom::PresentationSessionInfoPtr(),
315 content::mojom::PresentationError::From(error));
315 pending_start_session_cb_.reset(); 316 pending_start_session_cb_.reset();
316 start_session_request_id_ = kInvalidRequestSessionId; 317 start_session_request_id_ = kInvalidRequestSessionId;
317 } 318 }
318 319
319 void PresentationServiceImpl::OnJoinSessionSucceeded( 320 void PresentationServiceImpl::OnJoinSessionSucceeded(
320 int request_session_id, 321 int request_session_id,
321 const PresentationSessionInfo& session_info) { 322 const PresentationSessionInfo& session_info) {
322 if (RunAndEraseJoinSessionMojoCallback( 323 if (RunAndEraseJoinSessionMojoCallback(
323 request_session_id, 324 request_session_id,
324 blink::mojom::PresentationSessionInfo::From(session_info), 325 content::mojom::PresentationSessionInfo::From(session_info),
325 blink::mojom::PresentationErrorPtr())) { 326 content::mojom::PresentationErrorPtr())) {
326 ListenForConnectionStateChangeAndChangeState(session_info); 327 ListenForConnectionStateChangeAndChangeState(session_info);
327 } 328 }
328 } 329 }
329 330
330 void PresentationServiceImpl::OnJoinSessionError( 331 void PresentationServiceImpl::OnJoinSessionError(
331 int request_session_id, 332 int request_session_id,
332 const PresentationError& error) { 333 const PresentationError& error) {
333 RunAndEraseJoinSessionMojoCallback( 334 RunAndEraseJoinSessionMojoCallback(
334 request_session_id, blink::mojom::PresentationSessionInfoPtr(), 335 request_session_id, content::mojom::PresentationSessionInfoPtr(),
335 blink::mojom::PresentationError::From(error)); 336 content::mojom::PresentationError::From(error));
336 } 337 }
337 338
338 bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback( 339 bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback(
339 int request_session_id, 340 int request_session_id,
340 blink::mojom::PresentationSessionInfoPtr session, 341 content::mojom::PresentationSessionInfoPtr session,
341 blink::mojom::PresentationErrorPtr error) { 342 content::mojom::PresentationErrorPtr error) {
342 auto it = pending_join_session_cbs_.find(request_session_id); 343 auto it = pending_join_session_cbs_.find(request_session_id);
343 if (it == pending_join_session_cbs_.end()) 344 if (it == pending_join_session_cbs_.end())
344 return false; 345 return false;
345 346
346 DCHECK(it->second.get()); 347 DCHECK(it->second.get());
347 it->second->Run(std::move(session), std::move(error)); 348 it->second->Run(std::move(session), std::move(error));
348 pending_join_session_cbs_.erase(it); 349 pending_join_session_cbs_.erase(it);
349 return true; 350 return true;
350 } 351 }
351 352
352 void PresentationServiceImpl::SetDefaultPresentationUrls( 353 void PresentationServiceImpl::SetDefaultPresentationUrls(
353 const std::vector<GURL>& presentation_urls) { 354 const std::vector<GURL>& presentation_urls) {
354 DVLOG(2) << "SetDefaultPresentationUrls"; 355 DVLOG(2) << "SetDefaultPresentationUrls";
355 if (!delegate_) 356 if (!delegate_)
356 return; 357 return;
357 358
358 if (default_presentation_urls_ == presentation_urls) 359 if (default_presentation_urls_ == presentation_urls)
359 return; 360 return;
360 361
361 default_presentation_urls_ = presentation_urls; 362 default_presentation_urls_ = presentation_urls;
362 delegate_->SetDefaultPresentationUrls( 363 delegate_->SetDefaultPresentationUrls(
363 render_process_id_, render_frame_id_, presentation_urls, 364 render_process_id_, render_frame_id_, presentation_urls,
364 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 365 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
365 weak_factory_.GetWeakPtr())); 366 weak_factory_.GetWeakPtr()));
366 } 367 }
367 368
368 void PresentationServiceImpl::SendConnectionMessage( 369 void PresentationServiceImpl::SendConnectionMessage(
369 blink::mojom::PresentationSessionInfoPtr session, 370 content::mojom::PresentationSessionInfoPtr session,
370 blink::mojom::ConnectionMessagePtr connection_message, 371 content::mojom::ConnectionMessagePtr connection_message,
371 const SendConnectionMessageCallback& callback) { 372 const SendConnectionMessageCallback& callback) {
372 DVLOG(2) << "SendConnectionMessage"; 373 DVLOG(2) << "SendConnectionMessage";
373 DCHECK(!connection_message.is_null()); 374 DCHECK(!connection_message.is_null());
374 // send_message_callback_ should be null by now, otherwise resetting of 375 // send_message_callback_ should be null by now, otherwise resetting of
375 // send_message_callback_ with new callback will drop the old callback. 376 // send_message_callback_ with new callback will drop the old callback.
376 if (!delegate_ || send_message_callback_) { 377 if (!delegate_ || send_message_callback_) {
377 callback.Run(false); 378 callback.Run(false);
378 return; 379 return;
379 } 380 }
380 381
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 415
415 void PresentationServiceImpl::OnConnectionStateChanged( 416 void PresentationServiceImpl::OnConnectionStateChanged(
416 const PresentationSessionInfo& connection, 417 const PresentationSessionInfo& connection,
417 const PresentationConnectionStateChangeInfo& info) { 418 const PresentationConnectionStateChangeInfo& info) {
418 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged " 419 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged "
419 << "[presentation_id]: " << connection.presentation_id 420 << "[presentation_id]: " << connection.presentation_id
420 << " [state]: " << info.state; 421 << " [state]: " << info.state;
421 DCHECK(client_.get()); 422 DCHECK(client_.get());
422 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) { 423 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) {
423 client_->OnConnectionClosed( 424 client_->OnConnectionClosed(
424 blink::mojom::PresentationSessionInfo::From(connection), 425 content::mojom::PresentationSessionInfo::From(connection),
425 content::PresentationConnectionCloseReasonToMojo(info.close_reason), 426 content::PresentationConnectionCloseReasonToMojo(info.close_reason),
426 info.message); 427 info.message);
427 } else { 428 } else {
428 client_->OnConnectionStateChanged( 429 client_->OnConnectionStateChanged(
429 blink::mojom::PresentationSessionInfo::From(connection), 430 content::mojom::PresentationSessionInfo::From(connection),
430 PresentationConnectionStateToMojo(info.state)); 431 PresentationConnectionStateToMojo(info.state));
431 } 432 }
432 } 433 }
433 434
434 bool PresentationServiceImpl::FrameMatches( 435 bool PresentationServiceImpl::FrameMatches(
435 content::RenderFrameHost* render_frame_host) const { 436 content::RenderFrameHost* render_frame_host) const {
436 if (!render_frame_host) 437 if (!render_frame_host)
437 return false; 438 return false;
438 439
439 return render_frame_host->GetProcess()->GetID() == render_process_id_ && 440 return render_frame_host->GetProcess()->GetID() == render_process_id_ &&
440 render_frame_host->GetRoutingID() == render_frame_id_; 441 render_frame_host->GetRoutingID() == render_frame_id_;
441 } 442 }
442 443
443 void PresentationServiceImpl::ListenForConnectionMessages( 444 void PresentationServiceImpl::ListenForConnectionMessages(
444 blink::mojom::PresentationSessionInfoPtr session) { 445 content::mojom::PresentationSessionInfoPtr session) {
445 DVLOG(2) << "ListenForConnectionMessages"; 446 DVLOG(2) << "ListenForConnectionMessages";
446 if (!delegate_) 447 if (!delegate_)
447 return; 448 return;
448 449
449 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); 450 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
450 delegate_->ListenForConnectionMessages( 451 delegate_->ListenForConnectionMessages(
451 render_process_id_, render_frame_id_, session_info, 452 render_process_id_, render_frame_id_, session_info,
452 base::Bind(&PresentationServiceImpl::OnConnectionMessages, 453 base::Bind(&PresentationServiceImpl::OnConnectionMessages,
453 weak_factory_.GetWeakPtr(), session_info)); 454 weak_factory_.GetWeakPtr(), session_info));
454 } 455 }
455 456
456 void PresentationServiceImpl::OnConnectionMessages( 457 void PresentationServiceImpl::OnConnectionMessages(
457 const PresentationSessionInfo& session, 458 const PresentationSessionInfo& session,
458 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& messages, 459 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& messages,
459 bool pass_ownership) { 460 bool pass_ownership) {
460 DCHECK(client_); 461 DCHECK(client_);
461 462
462 DVLOG(2) << "OnConnectionMessages"; 463 DVLOG(2) << "OnConnectionMessages";
463 std::vector<blink::mojom::ConnectionMessagePtr> mojo_messages( 464 std::vector<content::mojom::ConnectionMessagePtr> mojo_messages(
464 messages.size()); 465 messages.size());
465 std::transform( 466 std::transform(
466 messages.begin(), messages.end(), mojo_messages.begin(), 467 messages.begin(), messages.end(), mojo_messages.begin(),
467 [pass_ownership]( 468 [pass_ownership](
468 const std::unique_ptr<PresentationConnectionMessage>& message) { 469 const std::unique_ptr<PresentationConnectionMessage>& message) {
469 return ToMojoConnectionMessage(message.get(), pass_ownership); 470 return ToMojoConnectionMessage(message.get(), pass_ownership);
470 }); 471 });
471 472
472 client_->OnConnectionMessagesReceived( 473 client_->OnConnectionMessagesReceived(
473 blink::mojom::PresentationSessionInfo::From(session), 474 content::mojom::PresentationSessionInfo::From(session),
474 std::move(mojo_messages)); 475 std::move(mojo_messages));
475 } 476 }
476 477
477 void PresentationServiceImpl::DidNavigateAnyFrame( 478 void PresentationServiceImpl::DidNavigateAnyFrame(
478 content::RenderFrameHost* render_frame_host, 479 content::RenderFrameHost* render_frame_host,
479 const content::LoadCommittedDetails& details, 480 const content::LoadCommittedDetails& details,
480 const content::FrameNavigateParams& params) { 481 const content::FrameNavigateParams& params) {
481 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; 482 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame";
482 if (!FrameMatches(render_frame_host)) 483 if (!FrameMatches(render_frame_host))
483 return; 484 return;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 527
527 screen_availability_listeners_.clear(); 528 screen_availability_listeners_.clear();
528 529
529 start_session_request_id_ = kInvalidRequestSessionId; 530 start_session_request_id_ = kInvalidRequestSessionId;
530 pending_start_session_cb_.reset(); 531 pending_start_session_cb_.reset();
531 532
532 pending_join_session_cbs_.clear(); 533 pending_join_session_cbs_.clear();
533 534
534 if (on_connection_messages_callback_.get()) { 535 if (on_connection_messages_callback_.get()) {
535 on_connection_messages_callback_->Run( 536 on_connection_messages_callback_->Run(
536 std::vector<blink::mojom::ConnectionMessagePtr>()); 537 std::vector<content::mojom::ConnectionMessagePtr>());
537 on_connection_messages_callback_.reset(); 538 on_connection_messages_callback_.reset();
538 } 539 }
539 540
540 if (send_message_callback_) { 541 if (send_message_callback_) {
541 // Run the callback with false, indicating the renderer to stop sending 542 // Run the callback with false, indicating the renderer to stop sending
542 // the requests and invalidate all pending requests. 543 // the requests and invalidate all pending requests.
543 send_message_callback_->Run(false); 544 send_message_callback_->Run(false);
544 send_message_callback_.reset(); 545 send_message_callback_.reset();
545 } 546 }
546 } 547 }
547 548
548 void PresentationServiceImpl::OnDelegateDestroyed() { 549 void PresentationServiceImpl::OnDelegateDestroyed() {
549 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; 550 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed";
550 delegate_ = nullptr; 551 delegate_ = nullptr;
551 Reset(); 552 Reset();
552 } 553 }
553 554
554 void PresentationServiceImpl::OnDefaultPresentationStarted( 555 void PresentationServiceImpl::OnDefaultPresentationStarted(
555 const PresentationSessionInfo& connection) { 556 const PresentationSessionInfo& connection) {
556 DCHECK(client_.get()); 557 DCHECK(client_.get());
557 client_->OnDefaultSessionStarted( 558 client_->OnDefaultSessionStarted(
558 blink::mojom::PresentationSessionInfo::From(connection)); 559 content::mojom::PresentationSessionInfo::From(connection));
559 ListenForConnectionStateChangeAndChangeState(connection); 560 ListenForConnectionStateChangeAndChangeState(connection);
560 } 561 }
561 562
562 PresentationServiceImpl::ScreenAvailabilityListenerImpl:: 563 PresentationServiceImpl::ScreenAvailabilityListenerImpl::
563 ScreenAvailabilityListenerImpl(const GURL& availability_url, 564 ScreenAvailabilityListenerImpl(const GURL& availability_url,
564 PresentationServiceImpl* service) 565 PresentationServiceImpl* service)
565 : availability_url_(availability_url), service_(service) { 566 : availability_url_(availability_url), service_(service) {
566 DCHECK(service_); 567 DCHECK(service_);
567 DCHECK(service_->client_.get()); 568 DCHECK(service_->client_.get());
568 } 569 }
(...skipping 22 matching lines...) Expand all
591 : callback_(callback) { 592 : callback_(callback) {
592 } 593 }
593 594
594 PresentationServiceImpl::NewSessionCallbackWrapper 595 PresentationServiceImpl::NewSessionCallbackWrapper
595 ::~NewSessionCallbackWrapper() { 596 ::~NewSessionCallbackWrapper() {
596 if (!callback_.is_null()) 597 if (!callback_.is_null())
597 InvokeNewSessionCallbackWithError(callback_); 598 InvokeNewSessionCallbackWithError(callback_);
598 } 599 }
599 600
600 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( 601 void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
601 blink::mojom::PresentationSessionInfoPtr session, 602 content::mojom::PresentationSessionInfoPtr session,
602 blink::mojom::PresentationErrorPtr error) { 603 content::mojom::PresentationErrorPtr error) {
603 DCHECK(!callback_.is_null()); 604 DCHECK(!callback_.is_null());
604 callback_.Run(std::move(session), std::move(error)); 605 callback_.Run(std::move(session), std::move(error));
605 callback_.Reset(); 606 callback_.Reset();
606 } 607 }
607 608
608 } // namespace content 609 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698