Chromium Code Reviews| Index: chrome/browser/media/router/receiver_presentation_service_delegate_impl.cc |
| diff --git a/chrome/browser/media/router/receiver_presentation_service_delegate_impl.cc b/chrome/browser/media/router/receiver_presentation_service_delegate_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2e32246ed95f86906017f84d79f49bd7230ee6e5 |
| --- /dev/null |
| +++ b/chrome/browser/media/router/receiver_presentation_service_delegate_impl.cc |
| @@ -0,0 +1,182 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
mark a. foltz
2016/10/08 00:33:41
Update copyright
zhaobin
2016/10/12 02:27:33
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/media/router/receiver_presentation_service_delegate_impl.h" |
| + |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "url/gurl.h" |
| + |
| +DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| + media_router::ReceiverPresentationServiceDelegateImpl); |
| + |
| +using content::PresentationServiceDelegate; |
| +using content::RenderFrameHost; |
| + |
| +namespace media_router { |
| + |
| +// static |
| +void ReceiverPresentationServiceDelegateImpl::CreateForWebContents( |
| + content::WebContents* web_contents, |
| + const std::string& presentation_id) { |
| + DCHECK(web_contents); |
| + |
| + if (FromWebContents(web_contents)) |
| + return; |
| + |
| + web_contents->SetUserData(UserDataKey(), |
| + new ReceiverPresentationServiceDelegateImpl( |
| + web_contents, presentation_id)); |
| +} |
| + |
| +ReceiverPresentationServiceDelegateImpl:: |
| + ~ReceiverPresentationServiceDelegateImpl() { |
| + for (auto& observer_pair : observers_) |
| + observer_pair.second->OnDelegateDestroyed(); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::AddObserver( |
|
mark a. foltz
2016/10/08 00:33:42
IMO it would be worth having a base class for the
zhaobin
2016/10/12 02:27:33
Done.
|
| + int render_process_id, |
| + int render_frame_id, |
| + content::PresentationServiceDelegate::Observer* observer) { |
| + DCHECK(observer); |
| + |
| + RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
| + DCHECK(!base::ContainsKey(observers_, rfh_id)); |
| + observers_[rfh_id] = observer; |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::RemoveObserver( |
| + int render_process_id, |
| + int render_frame_id) { |
| + observers_.erase(RenderFrameHostId(render_process_id, render_frame_id)); |
| +} |
| + |
| +bool ReceiverPresentationServiceDelegateImpl::AddScreenAvailabilityListener( |
| + int render_process_id, |
| + int render_frame_id, |
| + content::PresentationScreenAvailabilityListener* listener) { |
| + NOTIMPLEMENTED(); |
| + return false; |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::RemoveScreenAvailabilityListener( |
| + int render_process_id, |
| + int render_frame_id, |
| + content::PresentationScreenAvailabilityListener* listener) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::Reset(int render_process_id, |
| + int render_frame_id) { |
| + DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id; |
| + offscreen_presentation_manager_->OnOffscreenPresentationReceiverTerminated( |
| + presentation_id_); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::SetDefaultPresentationUrls( |
| + int render_process_id, |
| + int render_frame_id, |
| + const std::vector<std::string>& default_presentation_urls, |
| + const content::PresentationSessionStartedCallback& callback) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::StartSession( |
| + int render_process_id, |
| + int render_frame_id, |
| + const std::vector<std::string>& presentation_urls, |
| + const content::PresentationSessionStartedCallback& success_cb, |
| + const content::PresentationSessionErrorCallback& error_cb) { |
| + NOTIMPLEMENTED(); |
| + error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
| + "Not implemented")); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::JoinSession( |
| + int render_process_id, |
| + int render_frame_id, |
| + const std::vector<std::string>& presentation_urls, |
| + const std::string& presentation_id, |
| + const content::PresentationSessionStartedCallback& success_cb, |
| + const content::PresentationSessionErrorCallback& error_cb) { |
| + NOTIMPLEMENTED(); |
| + error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
| + "Not implemented")); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::CloseConnection( |
| + int render_process_id, |
| + int render_frame_id, |
| + const std::string& presentation_id) { |
| + NOTIMPLEMENTED(); |
|
mark a. foltz
2016/10/08 00:33:41
This should be implemented eventually right?
zhaobin
2016/10/12 02:27:33
Maybe not if close/terminate can be handled at ren
|
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::Terminate( |
| + int render_process_id, |
| + int render_frame_id, |
| + const std::string& presentation_id) { |
| + NOTIMPLEMENTED(); |
|
mark a. foltz
2016/10/08 00:33:41
Should be implemented in the future?
zhaobin
2016/10/12 02:27:33
Same as above.
|
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::ListenForSessionMessages( |
| + int render_process_id, |
| + int render_frame_id, |
| + const content::PresentationSessionInfo& session_info, |
| + const content::PresentationSessionMessageCallback& message_cb) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::SendMessage( |
| + int render_process_id, |
| + int render_frame_id, |
| + const content::PresentationSessionInfo& session_info, |
| + std::unique_ptr<content::PresentationSessionMessage> message, |
| + const SendMessageCallback& send_message_cb) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::ListenForConnectionStateChange( |
| + int render_process_id, |
| + int render_frame_id, |
| + const content::PresentationSessionInfo& connection, |
| + const content::PresentationConnectionStateChangedCallback& |
| + state_changed_cb) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +ReceiverPresentationServiceDelegateImpl:: |
| + ReceiverPresentationServiceDelegateImpl(content::WebContents* web_contents, |
| + const std::string& presentation_id) |
| + : web_contents_(web_contents), |
| + presentation_id_(presentation_id), |
| + offscreen_presentation_manager_( |
| + OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( |
| + Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| + ->GetOriginalProfile())) { |
| + DCHECK(web_contents_); |
| + DCHECK(!presentation_id.empty()); |
| + DCHECK(offscreen_presentation_manager_); |
| + DCHECK(web_contents_->GetBrowserContext()->IsOffTheRecord()); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::RegisterReceiverAvailableCallback( |
| + const content::ReceiverConnectionAvailableCallback& |
| + receiver_available_callback) { |
| + std::string presentation_url = web_contents_->GetURL().spec(); |
|
mark a. foltz
2016/10/08 00:33:41
Can you just pass the URL directly?
zhaobin
2016/10/12 02:27:33
Done.
|
| + offscreen_presentation_manager_->OnOffscreenPresentationReceiverCreated( |
| + presentation_id_, GURL(presentation_url), receiver_available_callback); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl:: |
| + RegisterOffscreenPresentationConnection( |
| + int render_process_id, |
| + int render_frame_id, |
| + const content::PresentationSessionInfo& session, |
| + content::PresentationConnectionPtr connection) { |
| + NOTREACHED(); |
| +} |
| + |
| +} // namespace media_router |