Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "chrome/browser/media/router/receiver_presentation_service_delegate_imp l.h" | |
| 6 | |
| 7 #include "content/public/browser/render_frame_host.h" | |
| 8 #include "content/public/browser/render_process_host.h" | |
| 9 #include "url/gurl.h" | |
| 10 | |
| 11 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | |
| 12 media_router::ReceiverPresentationServiceDelegateImpl); | |
| 13 | |
| 14 using content::RenderFrameHost; | |
| 15 | |
| 16 namespace media_router { | |
| 17 | |
| 18 // static | |
| 19 void ReceiverPresentationServiceDelegateImpl::CreateForWebContents( | |
| 20 content::WebContents* web_contents, | |
| 21 const std::string& presentation_id) { | |
| 22 DCHECK(web_contents); | |
| 23 | |
| 24 if (FromWebContents(web_contents)) | |
| 25 return; | |
| 26 | |
| 27 web_contents->SetUserData(UserDataKey(), | |
| 28 new ReceiverPresentationServiceDelegateImpl( | |
| 29 web_contents, presentation_id)); | |
| 30 } | |
| 31 | |
| 32 ReceiverPresentationServiceDelegateImpl:: | |
| 33 ~ReceiverPresentationServiceDelegateImpl() { | |
| 34 for (auto& observer_pair : observers_) | |
| 35 observer_pair.second->OnDelegateDestroyed(); | |
| 36 } | |
| 37 | |
| 38 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.
| |
| 39 int render_process_id, | |
| 40 int render_frame_id, | |
| 41 content::PresentationServiceDelegateBase::Observer* observer) { | |
| 42 DCHECK(observer); | |
| 43 | |
| 44 RenderFrameHostId rfh_id(render_process_id, render_frame_id); | |
| 45 DCHECK(!base::ContainsKey(observers_, rfh_id)); | |
| 46 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
| |
| 47 } | |
| 48 | |
| 49 void ReceiverPresentationServiceDelegateImpl::RemoveObserver( | |
| 50 int render_process_id, | |
| 51 int render_frame_id) { | |
| 52 observers_.erase(RenderFrameHostId(render_process_id, render_frame_id)); | |
| 53 } | |
| 54 | |
| 55 void ReceiverPresentationServiceDelegateImpl::Reset(int render_process_id, | |
| 56 int render_frame_id) { | |
| 57 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id; | |
| 58 offscreen_presentation_manager_->OnOffscreenPresentationReceiverTerminated( | |
| 59 presentation_id_); | |
| 60 } | |
| 61 | |
| 62 ReceiverPresentationServiceDelegateImpl:: | |
| 63 ReceiverPresentationServiceDelegateImpl(content::WebContents* web_contents, | |
| 64 const std::string& presentation_id) | |
| 65 : web_contents_(web_contents), | |
| 66 presentation_id_(presentation_id), | |
| 67 offscreen_presentation_manager_( | |
| 68 OffscreenPresentationManagerFactory:: | |
| 69 GetOrCreateForReceiverBrowserContext(web_contents_)) { | |
| 70 DCHECK(web_contents_); | |
| 71 DCHECK(!presentation_id.empty()); | |
| 72 DCHECK(offscreen_presentation_manager_); | |
| 73 } | |
| 74 | |
| 75 void ReceiverPresentationServiceDelegateImpl:: | |
| 76 RegisterReceiverConnectionAvailableCallback( | |
| 77 const content::ReceiverConnectionAvailableCallback& | |
| 78 receiver_available_callback) { | |
| 79 offscreen_presentation_manager_->OnOffscreenPresentationReceiverCreated( | |
| 80 presentation_id_, web_contents_->GetLastCommittedURL(), | |
| 81 receiver_available_callback); | |
| 82 } | |
| 83 | |
| 84 } // namespace media_router | |
| OLD | NEW |