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

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

Issue 1419853003: [Media Router] Connection reattempt logic and bound pending request queue size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/media/router/media_router_mojo_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_MEDIA_ROUTER_MOJO_IMPL_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
7 7
8 #include <deque>
8 #include <map> 9 #include <map>
9 #include <set> 10 #include <set>
10 #include <string> 11 #include <string>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
14 #include "base/containers/scoped_ptr_hash_map.h" 15 #include "base/containers/scoped_ptr_hash_map.h"
15 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 92 }
92 93
93 void set_instance_id_for_test(const std::string& instance_id) { 94 void set_instance_id_for_test(const std::string& instance_id) {
94 instance_id_ = instance_id; 95 instance_id_ = instance_id;
95 } 96 }
96 97
97 private: 98 private:
98 friend class MediaRouterFactory; 99 friend class MediaRouterFactory;
99 friend class MediaRouterMojoExtensionTest; 100 friend class MediaRouterMojoExtensionTest;
100 friend class MediaRouterMojoTest; 101 friend class MediaRouterMojoTest;
101
102 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, 102 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
103 RegisterAndUnregisterMediaSinksObserver); 103 RegisterAndUnregisterMediaSinksObserver);
104 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, 104 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
105 RegisterMediaSinksObserverWithAvailabilityChange); 105 RegisterMediaSinksObserverWithAvailabilityChange);
106 FRIEND_TEST_ALL_PREFIXES( 106 FRIEND_TEST_ALL_PREFIXES(
107 MediaRouterMojoImplTest, 107 MediaRouterMojoImplTest,
108 RegisterAndUnregisterMediaSinksObserverWithAvailabilityChange); 108 RegisterAndUnregisterMediaSinksObserverWithAvailabilityChange);
109 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, 109 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
110 RegisterAndUnregisterMediaRoutesObserver); 110 RegisterAndUnregisterMediaRoutesObserver);
111 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, HandleIssue); 111 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, HandleIssue);
112 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest, 112 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
113 DeferredBindingAndSuspension); 113 DeferredBindingAndSuspension);
114 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
115 DrainPendingRequestQueue);
116 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
117 DropOldestPendingRequest);
118 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
119 AttemptedWakeupTooManyTimes);
120 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
121 WakeupFailedDrainsQueue);
122
123 // The max number of pending requests allowed. When number of pending requests
124 // exceeds this number, the oldest request will be dropped.
125 static const int kMaxPendingRequests = 30;
126
127 // Max consecutive attempts to wake up the component extension before
128 // giving up and draining the pending request queue.
129 static const int kMaxWakeupAttemptCount = 3;
114 130
115 class MediaRouterMediaRoutesObserver : 131 class MediaRouterMediaRoutesObserver :
116 public media_router::MediaRoutesObserver { 132 public media_router::MediaRoutesObserver {
117 public: 133 public:
118 explicit MediaRouterMediaRoutesObserver(MediaRouterMojoImpl* router); 134 explicit MediaRouterMediaRoutesObserver(MediaRouterMojoImpl* router);
119 ~MediaRouterMediaRoutesObserver() override; 135 ~MediaRouterMediaRoutesObserver() override;
120 136
121 // media_router::MediaRoutesObserver: 137 // media_router::MediaRoutesObserver:
122 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes) 138 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes)
123 override; 139 override;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // Enqueues a closure for later execution by ExecutePendingRequests(). 173 // Enqueues a closure for later execution by ExecutePendingRequests().
158 void EnqueueTask(const base::Closure& closure); 174 void EnqueueTask(const base::Closure& closure);
159 175
160 // Runs a closure if the extension monitored by |extension_monitor_| is 176 // Runs a closure if the extension monitored by |extension_monitor_| is
161 // active, or defers it for later execution if the extension is suspended. 177 // active, or defers it for later execution if the extension is suspended.
162 void RunOrDefer(const base::Closure& request); 178 void RunOrDefer(const base::Closure& request);
163 179
164 // Dispatches the Mojo requests queued in |pending_requests_|. 180 // Dispatches the Mojo requests queued in |pending_requests_|.
165 void ExecutePendingRequests(); 181 void ExecutePendingRequests();
166 182
183 // Drops all pending requests. Called when we have a connection error to
184 // component extension and further reattempts are unlikely to help.
185 void DrainPendingRequests();
186
167 // MediaRouter implementation. 187 // MediaRouter implementation.
168 bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override; 188 bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
169 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override; 189 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override;
170 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override; 190 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
171 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override; 191 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
172 void RegisterIssuesObserver(IssuesObserver* observer) override; 192 void RegisterIssuesObserver(IssuesObserver* observer) override;
173 void UnregisterIssuesObserver(IssuesObserver* observer) override; 193 void UnregisterIssuesObserver(IssuesObserver* observer) override;
174 void RegisterPresentationSessionMessagesObserver( 194 void RegisterPresentationSessionMessagesObserver(
175 PresentationSessionMessagesObserver* observer) override; 195 PresentationSessionMessagesObserver* observer) override;
176 void UnregisterPresentationSessionMessagesObserver( 196 void UnregisterPresentationSessionMessagesObserver(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute() 253 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute()
234 // into a local callback. 254 // into a local callback.
235 void RouteResponseReceived( 255 void RouteResponseReceived(
236 const std::string& presentation_id, 256 const std::string& presentation_id,
237 const std::vector<MediaRouteResponseCallback>& callbacks, 257 const std::vector<MediaRouteResponseCallback>& callbacks,
238 interfaces::MediaRoutePtr media_route, 258 interfaces::MediaRoutePtr media_route,
239 const mojo::String& error_text); 259 const mojo::String& error_text);
240 260
241 void UpdateHasLocalRoute(bool has_local_route); 261 void UpdateHasLocalRoute(bool has_local_route);
242 262
263 // Callback invoked by |event_page_tracker_| after an attempt to wake the
264 // component extension. If |success| is false, the pending request queue is
265 // drained.
266 void EventPageWakeComplete(bool success);
267
268 // Removes all requests from the pending requests queue. Called when there is
269 // a permanent error connecting to component extension.
270 void DrainRequestQueue();
271
272 // Calls to |event_page_tracker_| to wake the component extension.
273 // |media_route_provider_extension_id_| must not be empty and the extension
274 // should be currently suspended.
275 // If there have already been too many wakeup attempts, give up and drain
276 // the pending request queue.
277 void AttemptWakeEventPage();
278
243 // Pending requests queued to be executed once component extension 279 // Pending requests queued to be executed once component extension
244 // becomes ready. 280 // becomes ready.
245 std::vector<base::Closure> pending_requests_; 281 std::deque<base::Closure> pending_requests_;
246 282
247 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaSinksQuery>> 283 base::ScopedPtrHashMap<MediaSource::Id, scoped_ptr<MediaSinksQuery>>
248 sinks_queries_; 284 sinks_queries_;
249 285
250 base::ObserverList<LocalMediaRoutesObserver> local_routes_observers_; 286 base::ObserverList<LocalMediaRoutesObserver> local_routes_observers_;
251 287
252 base::ObserverList<MediaRoutesObserver> routes_observers_; 288 base::ObserverList<MediaRoutesObserver> routes_observers_;
253 289
254 using PresentationSessionMessagesObserverList = 290 using PresentationSessionMessagesObserverList =
255 base::ObserverList<PresentationSessionMessagesObserver>; 291 base::ObserverList<PresentationSessionMessagesObserver>;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // Set to true if there are routes started on this instance. 327 // Set to true if there are routes started on this instance.
292 bool has_local_route_; 328 bool has_local_route_;
293 329
294 // Observes local routes in order to notify LocalMediaRoutesObservers when 330 // Observes local routes in order to notify LocalMediaRoutesObservers when
295 // there are no more local routes. 331 // there are no more local routes.
296 scoped_ptr<MediaRoutesObserver> routes_observer_; 332 scoped_ptr<MediaRoutesObserver> routes_observer_;
297 333
298 // The last reported sink availability from the media route provider manager. 334 // The last reported sink availability from the media route provider manager.
299 interfaces::MediaRouter::SinkAvailability availability_; 335 interfaces::MediaRouter::SinkAvailability availability_;
300 336
337 int wakeup_attempt_count_;
338
301 base::ThreadChecker thread_checker_; 339 base::ThreadChecker thread_checker_;
302 340
341 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_;
342
303 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); 343 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl);
304 }; 344 };
305 345
306 } // namespace media_router 346 } // namespace media_router
307 347
308 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_ 348 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/media/router/media_router_mojo_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698