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..0e64b1e539bc1cf43ab6c3407d574ba94d0fb82d |
| --- /dev/null |
| +++ b/chrome/browser/media/router/receiver_presentation_service_delegate_impl.cc |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// 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 "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::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/11/08 23:40:51
Can AddObserver/RemoveObserver be moved into Prese
zhaobin
2016/11/10 04:14:00
Done.
|
| + int render_process_id, |
| + int render_frame_id, |
| + content::PresentationServiceDelegateBase::Observer* observer) { |
| + DCHECK(observer); |
| + |
| + RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
| + DCHECK(!base::ContainsKey(observers_, rfh_id)); |
| + observers_[rfh_id] = observer; |
|
mark a. foltz
2016/11/08 23:40:51
I am not sure why the map is needed. Is it import
zhaobin
2016/11/10 04:14:00
multiple PSImpl objects may reference to the same
|
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl::RemoveObserver( |
| + int render_process_id, |
| + int render_frame_id) { |
| + observers_.erase(RenderFrameHostId(render_process_id, render_frame_id)); |
| +} |
| + |
| +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_); |
| +} |
| + |
| +ReceiverPresentationServiceDelegateImpl:: |
| + ReceiverPresentationServiceDelegateImpl(content::WebContents* web_contents, |
| + const std::string& presentation_id) |
| + : web_contents_(web_contents), |
| + presentation_id_(presentation_id), |
| + offscreen_presentation_manager_( |
| + OffscreenPresentationManagerFactory:: |
| + GetOrCreateForReceiverBrowserContext(web_contents_)) { |
| + DCHECK(web_contents_); |
| + DCHECK(!presentation_id.empty()); |
| + DCHECK(offscreen_presentation_manager_); |
| +} |
| + |
| +void ReceiverPresentationServiceDelegateImpl:: |
| + RegisterReceiverConnectionAvailableCallback( |
| + const content::ReceiverConnectionAvailableCallback& |
| + receiver_available_callback) { |
| + offscreen_presentation_manager_->OnOffscreenPresentationReceiverCreated( |
| + presentation_id_, web_contents_->GetLastCommittedURL(), |
| + receiver_available_callback); |
| +} |
| + |
| +} // namespace media_router |