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

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl.h

Issue 1406013003: [Presentation API / Media Router] Clean up default pres URL logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile again Created 5 years, 2 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 #ifndef CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "chrome/browser/media/router/media_router.h" 17 #include "chrome/browser/media/router/media_router.h"
18 #include "chrome/browser/media/router/media_source.h" 18 #include "chrome/browser/media/router/media_source.h"
19 #include "chrome/browser/media/router/presentation_request.h"
20 #include "chrome/browser/media/router/render_frame_host_id.h"
19 #include "content/public/browser/presentation_service_delegate.h" 21 #include "content/public/browser/presentation_service_delegate.h"
20 #include "content/public/browser/web_contents_observer.h" 22 #include "content/public/browser/web_contents_observer.h"
21 #include "content/public/browser/web_contents_user_data.h" 23 #include "content/public/browser/web_contents_user_data.h"
22 24
23 namespace content { 25 namespace content {
24 class RenderFrameHost; 26 class RenderFrameHost;
25 class PresentationScreenAvailabilityListener; 27 class PresentationScreenAvailabilityListener;
26 class WebContents; 28 class WebContents;
27 struct PresentationSessionInfo; 29 struct PresentationSessionInfo;
28 struct PresentationSessionMessage; 30 struct PresentationSessionMessage;
29 } // namespace content 31 } // namespace content
30 32
31 namespace media_router { 33 namespace media_router {
32 34
33 class MediaRoute; 35 class MediaRoute;
34 class MediaSinksObserver; 36 class MediaSinksObserver;
35 class PresentationFrameManager; 37 class PresentationFrameManager;
36 class PresentationSessionStateObserver; 38 class PresentationSessionStateObserver;
37 39
38 using RenderFrameHostId = std::pair<int, int>;
39
40 // Implementation of PresentationServiceDelegate that interfaces an 40 // Implementation of PresentationServiceDelegate that interfaces an
41 // instance of WebContents with the Chrome Media Router. It uses the Media 41 // instance of WebContents with the Chrome Media Router. It uses the Media
42 // Router to handle presentation API calls forwarded from 42 // Router to handle presentation API calls forwarded from
43 // PresentationServiceImpl. In addition, it also 43 // PresentationServiceImpl. In addition, it also
44 // provides default presentation URL that is required for creating 44 // provides default presentation URL that is required for creating
45 // browser-initiated sessions. 45 // browser-initiated sessions.
46 // It is scoped to the lifetime of a WebContents, and is managed by the 46 // It is scoped to the lifetime of a WebContents, and is managed by the
47 // associated WebContents. 47 // associated WebContents.
48 class PresentationServiceDelegateImpl 48 class PresentationServiceDelegateImpl
49 : public content::WebContentsUserData<PresentationServiceDelegateImpl>, 49 : public content::WebContentsUserData<PresentationServiceDelegateImpl>,
50 public content::PresentationServiceDelegate { 50 public content::PresentationServiceDelegate {
51 public: 51 public:
52 // Observer interface for listening to default presentation request
53 // changes for the WebContents.
54 class DefaultPresentationRequestObserver {
55 public:
56 virtual ~DefaultPresentationRequestObserver() {}
57
58 // Called when default presentation for the corresponding WebContents has
59 // changed.
60 // |default_presentation_info|: New default presentation, or nullptr if
61 // there is no default presentation.
62 virtual void OnDefaultPresentationChanged(
63 const PresentationRequest* default_presentation_request) = 0;
64 };
65
52 // Retrieves the instance of PresentationServiceDelegateImpl that was attached 66 // Retrieves the instance of PresentationServiceDelegateImpl that was attached
53 // to the specified WebContents. If no instance was attached, creates one, 67 // to the specified WebContents. If no instance was attached, creates one,
54 // and attaches it to the specified WebContents. 68 // and attaches it to the specified WebContents.
55 static PresentationServiceDelegateImpl* GetOrCreateForWebContents( 69 static PresentationServiceDelegateImpl* GetOrCreateForWebContents(
56 content::WebContents* web_contents); 70 content::WebContents* web_contents);
57 71
58 ~PresentationServiceDelegateImpl() override; 72 ~PresentationServiceDelegateImpl() override;
59 73
60 // content::PresentationServiceDelegate implementation. 74 // content::PresentationServiceDelegate implementation.
61 void AddObserver( 75 void AddObserver(
62 int render_process_id, 76 int render_process_id,
63 int render_frame_id, 77 int render_frame_id,
64 content::PresentationServiceDelegate::Observer* observer) override; 78 content::PresentationServiceDelegate::Observer* observer) override;
65 void RemoveObserver(int render_process_id, int render_frame_id) override; 79 void RemoveObserver(int render_process_id, int render_frame_id) override;
66 bool AddScreenAvailabilityListener( 80 bool AddScreenAvailabilityListener(
67 int render_process_id, 81 int render_process_id,
68 int render_frame_id, 82 int render_frame_id,
69 content::PresentationScreenAvailabilityListener* listener) override; 83 content::PresentationScreenAvailabilityListener* listener) override;
70 void RemoveScreenAvailabilityListener( 84 void RemoveScreenAvailabilityListener(
71 int render_process_id, 85 int render_process_id,
72 int render_frame_id, 86 int render_frame_id,
73 content::PresentationScreenAvailabilityListener* listener) override; 87 content::PresentationScreenAvailabilityListener* listener) override;
74 void Reset(int render_process_id, int render_frame_id) override; 88 void Reset(int render_process_id, int render_frame_id) override;
75 void SetDefaultPresentationUrl( 89 void SetDefaultPresentationUrl(
76 int render_process_id, 90 int render_process_id,
77 int render_frame_id, 91 int render_frame_id,
78 const std::string& default_presentation_url) override; 92 const std::string& default_presentation_url,
79 void StartSession(int render_process_id, 93 const content::PresentationSessionStartedCallback& callback) override;
80 int render_frame_id, 94 void StartSession(
81 const std::string& presentation_url, 95 int render_process_id,
82 const PresentationSessionSuccessCallback& success_cb, 96 int render_frame_id,
83 const PresentationSessionErrorCallback& error_cb) override; 97 const std::string& presentation_url,
84 void JoinSession(int render_process_id, 98 const content::PresentationSessionStartedCallback& success_cb,
85 int render_frame_id, 99 const content::PresentationSessionErrorCallback& error_cb) override;
86 const std::string& presentation_url, 100 void JoinSession(
87 const std::string& presentation_id, 101 int render_process_id,
88 const PresentationSessionSuccessCallback& success_cb, 102 int render_frame_id,
89 const PresentationSessionErrorCallback& error_cb) override; 103 const std::string& presentation_url,
104 const std::string& presentation_id,
105 const content::PresentationSessionStartedCallback& success_cb,
106 const content::PresentationSessionErrorCallback& error_cb) override;
90 void CloseSession(int render_process_id, 107 void CloseSession(int render_process_id,
91 int render_frame_id, 108 int render_frame_id,
92 const std::string& presentation_id) override; 109 const std::string& presentation_id) override;
93 void ListenForSessionMessages( 110 void ListenForSessionMessages(
94 int render_process_id, 111 int render_process_id,
95 int render_frame_id, 112 int render_frame_id,
96 const content::PresentationSessionInfo& session, 113 const content::PresentationSessionInfo& session,
97 const content::PresentationSessionMessageCallback& message_cb) override; 114 const content::PresentationSessionMessageCallback& message_cb) override;
98 void SendMessage(int render_process_id, 115 void SendMessage(int render_process_id,
99 int render_frame_id, 116 int render_frame_id,
100 const content::PresentationSessionInfo& session, 117 const content::PresentationSessionInfo& session,
101 scoped_ptr<content::PresentationSessionMessage> message, 118 scoped_ptr<content::PresentationSessionMessage> message,
102 const SendMessageCallback& send_message_cb) override; 119 const SendMessageCallback& send_message_cb) override;
103 void ListenForSessionStateChange( 120 void ListenForSessionStateChange(
104 int render_process_id, 121 int render_process_id,
105 int render_frame_id, 122 int render_frame_id,
106 const content::SessionStateChangedCallback& state_changed_cb) override; 123 const content::SessionStateChangedCallback& state_changed_cb) override;
107 124
108 // Callback invoked when there is a route response from CreateRoute/JoinRoute 125 // Callback invoked when there is a presentation route response from
109 // outside of a Presentation API request. This could be due to 126 // CreateRoute/JoinRoute outside of an explicit Presentation API
110 // browser action (e.g., browser initiated media router dialog) or 127 // start()/reconnect() call, such as due to browser action (e.g., browser
111 // a media route provider (e.g., autojoin). 128 // initiated media router dialog).
mark a. foltz 2015/10/20 20:15:25 I found this comment a little confusing. Do you m
imcheng 2015/10/24 00:41:19 Well this method is only called on response to the
112 void OnRouteResponse(const MediaRoute* route, 129 void OnRouteResponse(const PresentationRequest& request,
130 const MediaRoute* route,
113 const std::string& presentation_id, 131 const std::string& presentation_id,
114 const std::string& error); 132 const std::string& error);
115 133
116 // Returns the default MediaSource for this tab if there is one. 134 // Adds / removes an observer for listening to default presentation changes.
mark a. foltz 2015/10/20 20:15:25 Nit: default PresentationRequest changes
imcheng 2015/10/24 00:41:19 Done.
117 // Returns an empty MediaSource otherwise. 135 void AddDefaultPresentationRequestObserver(
118 MediaSource default_source() const { return default_source_; } 136 DefaultPresentationRequestObserver* observer);
137 void RemoveDefaultPresentationRequestObserver(
138 DefaultPresentationRequestObserver* observer);
139
140 // Gets the default presentation request for the owning tab WebContents, or
141 // nullptr if it does not exist.
142 const PresentationRequest* GetDefaultPresentationRequest() const;
119 143
120 content::WebContents* web_contents() const { return web_contents_; } 144 content::WebContents* web_contents() const { return web_contents_; }
121 const GURL& default_frame_url() const { return default_frame_url_; }
122 145
123 // Observer interface for listening to default MediaSource changes for the 146 base::WeakPtr<PresentationServiceDelegateImpl> GetWeakPtr();
124 // WebContents.
125 class DefaultMediaSourceObserver {
126 public:
127 virtual ~DefaultMediaSourceObserver() {}
128
129 // Called when default media source for the corresponding WebContents has
130 // changed.
131 // |source|: New default MediaSource, or empty if default was removed.
132 // |frame_url|: URL of the frame that contains the default media
133 // source, or empty if there is no default media source.
134 virtual void OnDefaultMediaSourceChanged(const MediaSource& source,
135 const GURL& frame_url) = 0;
136 };
137
138 // Adds / removes an observer for listening to default MediaSource changes.
139 void AddDefaultMediaSourceObserver(DefaultMediaSourceObserver* observer);
140 void RemoveDefaultMediaSourceObserver(DefaultMediaSourceObserver* observer);
141 147
142 void SetMediaRouterForTest(MediaRouter* router); 148 void SetMediaRouterForTest(MediaRouter* router);
143 bool HasScreenAvailabilityListenerForTest( 149 bool HasScreenAvailabilityListenerForTest(
144 int render_process_id, 150 int render_process_id,
145 int render_frame_id, 151 int render_frame_id,
146 const MediaSource::Id& source_id) const; 152 const MediaSource::Id& source_id) const;
147 153
148 base::WeakPtr<PresentationServiceDelegateImpl> GetWeakPtr();
149
150 private: 154 private:
151 friend class content::WebContentsUserData<PresentationServiceDelegateImpl>; 155 friend class content::WebContentsUserData<PresentationServiceDelegateImpl>;
152 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, 156 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
153 DelegateObservers); 157 DelegateObservers);
158 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
159 SetDefaultPresentationUrl);
160 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
161 DefaultPresentationRequestObserver);
162 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
163 DefaultPresentationUrlCallback);
154 164
155 explicit PresentationServiceDelegateImpl(content::WebContents* web_contents); 165 explicit PresentationServiceDelegateImpl(content::WebContents* web_contents);
156 166
157 // Returns |listener|'s presentation URL as a MediaSource. If |listener| does 167 // Returns |listener|'s presentation URL as a MediaSource. If |listener| does
158 // not have a persentation URL, returns the tab mirroring MediaSource. 168 // not have a persentation URL, returns the tab mirroring MediaSource.
159 MediaSource GetMediaSourceFromListener( 169 MediaSource GetMediaSourceFromListener(
160 content::PresentationScreenAvailabilityListener* listener); 170 content::PresentationScreenAvailabilityListener* listener);
161 171
162 void OnJoinRouteResponse(int render_process_id, 172 void OnJoinRouteResponse(
163 int render_frame_id, 173 int render_process_id,
164 const content::PresentationSessionInfo& session, 174 int render_frame_id,
165 const PresentationSessionSuccessCallback& success_cb, 175 const content::PresentationSessionInfo& session,
166 const PresentationSessionErrorCallback& error_cb, 176 const content::PresentationSessionStartedCallback& success_cb,
167 const MediaRoute* route, 177 const content::PresentationSessionErrorCallback& error_cb,
168 const std::string& presentation_id, 178 const MediaRoute* route,
169 const std::string& error_text); 179 const std::string& presentation_id,
180 const std::string& error_text);
170 181
171 void OnStartSessionSucceeded( 182 void OnStartSessionSucceeded(
172 int render_process_id, 183 int render_process_id,
173 int render_frame_id, 184 int render_frame_id,
174 const PresentationSessionSuccessCallback& success_cb, 185 const content::PresentationSessionStartedCallback& success_cb,
175 const content::PresentationSessionInfo& new_session, 186 const content::PresentationSessionInfo& new_session,
176 const MediaRoute::Id& route_id); 187 const MediaRoute::Id& route_id);
177 188
178 // Returns |true| if the frame is the main frame of |web_contents_|.
179 bool IsMainFrame(int render_process_id, int render_frame_id) const;
180
181 // Updates tab-level default MediaSource, default frame URL, and the
182 // originating frame. If the source or frame URL changed, notify the
183 // observers.
184 void UpdateDefaultMediaSourceAndNotifyObservers(
185 const RenderFrameHostId& render_frame_host_id,
186 const MediaSource& new_default_source,
187 const GURL& new_default_frame_url);
188
189 // ID of RenderFrameHost that contains the default presentation.
190 RenderFrameHostId default_presentation_render_frame_host_id_;
191 // Default MediaSource for the tab associated with this instance.
192 MediaSource default_source_;
193 // URL of the frame that contains the default MediaSource.
194 GURL default_frame_url_;
195
196 // References to the observers listening for changes to default media source.
197 base::ObserverList<
198 DefaultMediaSourceObserver> default_media_source_observers_;
199
200 // References to the WebContents that owns this instance, and associated 189 // References to the WebContents that owns this instance, and associated
201 // browser profile's MediaRouter instance. 190 // browser profile's MediaRouter instance.
202 content::WebContents* web_contents_; 191 content::WebContents* const web_contents_;
203 MediaRouter* router_; 192 MediaRouter* router_;
204 193
205 scoped_ptr<PresentationFrameManager> frame_manager_; 194 scoped_ptr<PresentationFrameManager> frame_manager_;
206 195
207 base::WeakPtrFactory<PresentationServiceDelegateImpl> weak_factory_; 196 base::WeakPtrFactory<PresentationServiceDelegateImpl> weak_factory_;
208 197
209 DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImpl); 198 DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImpl);
210 }; 199 };
211 200
212 } // namespace media_router 201 } // namespace media_router
213 202
214 #endif // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ 203 #endif // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698