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

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

Issue 2837363002: [Media Router] Use DialMediaSinkService in MediaRouterMojoImpl (Closed)
Patch Set: resolve code review comments from Mark Created 3 years, 7 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_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque> 10 #include <deque>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <unordered_map> 15 #include <unordered_map>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/containers/hash_tables.h" 18 #include "base/containers/hash_tables.h"
19 #include "base/feature_list.h"
19 #include "base/gtest_prod_util.h" 20 #include "base/gtest_prod_util.h"
20 #include "base/macros.h" 21 #include "base/macros.h"
21 #include "base/memory/weak_ptr.h" 22 #include "base/memory/weak_ptr.h"
22 #include "base/observer_list.h" 23 #include "base/observer_list.h"
23 #include "base/optional.h" 24 #include "base/optional.h"
24 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
25 #include "build/build_config.h" 26 #include "build/build_config.h"
26 #include "chrome/browser/media/router/issue_manager.h" 27 #include "chrome/browser/media/router/issue_manager.h"
27 #include "chrome/browser/media/router/media_router_base.h" 28 #include "chrome/browser/media/router/media_router_base.h"
28 #include "chrome/browser/media/router/media_routes_observer.h" 29 #include "chrome/browser/media/router/media_routes_observer.h"
29 #include "chrome/common/media_router/issue.h" 30 #include "chrome/common/media_router/issue.h"
30 #include "chrome/common/media_router/mojo/media_router.mojom.h" 31 #include "chrome/common/media_router/mojo/media_router.mojom.h"
31 #include "chrome/common/media_router/route_request_result.h" 32 #include "chrome/common/media_router/route_request_result.h"
33 #include "content/public/browser/browser_thread.h"
32 #include "mojo/public/cpp/bindings/binding.h" 34 #include "mojo/public/cpp/bindings/binding.h"
33 35
34 namespace content { 36 namespace content {
35 class BrowserContext; 37 class BrowserContext;
36 } 38 }
37 39
38 namespace extensions { 40 namespace extensions {
39 class EventPageTracker; 41 class EventPageTracker;
40 class Extension; 42 class Extension;
41 } 43 }
42 44
45 namespace net {
46 class URLRequestContextGetter;
47 }
48
43 namespace media_router { 49 namespace media_router {
44 50
51 extern const base::Feature kEnableDialLocalDiscovery;
mark a. foltz 2017/05/01 20:32:57 Can these go in media_router_feature.cc and expose
zhaobin 2017/05/03 01:53:59 Done.
52 extern const base::Feature kEnableCastDiscovery;
mark a. foltz 2017/05/01 20:32:57 Is it okay to do static initialization of base::Fe
zhaobin 2017/05/03 01:54:00 Code removed. Seems fine. https://cs.chromium.org/
53
45 enum class MediaRouteProviderWakeReason; 54 enum class MediaRouteProviderWakeReason;
55 class DialMediaSinkService;
46 56
47 // MediaRouter implementation that delegates calls to the component extension. 57 // MediaRouter implementation that delegates calls to the component extension.
48 // Also handles the suspension and wakeup of the component extension. 58 // Also handles the suspension and wakeup of the component extension.
49 // Lives on the UI thread. 59 // Lives on the UI thread.
50 class MediaRouterMojoImpl : public MediaRouterBase, 60 class MediaRouterMojoImpl : public MediaRouterBase,
51 public mojom::MediaRouter { 61 public mojom::MediaRouter {
52 public: 62 public:
53 ~MediaRouterMojoImpl() override; 63 ~MediaRouterMojoImpl() override;
54 64
55 // Sets up the MediaRouterMojoImpl instance owned by |context| to handle 65 // Sets up the MediaRouterMojoImpl instance owned by |context| to handle
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 std::vector<std::string> joinable_route_ids; 217 std::vector<std::string> joinable_route_ids;
208 218
209 base::ObserverList<MediaRoutesObserver> observers; 219 base::ObserverList<MediaRoutesObserver> observers;
210 220
211 private: 221 private:
212 DISALLOW_COPY_AND_ASSIGN(MediaRoutesQuery); 222 DISALLOW_COPY_AND_ASSIGN(MediaRoutesQuery);
213 }; 223 };
214 224
215 // Standard constructor, used by 225 // Standard constructor, used by
216 // MediaRouterMojoImplFactory::GetApiForBrowserContext. 226 // MediaRouterMojoImplFactory::GetApiForBrowserContext.
217 explicit MediaRouterMojoImpl( 227 explicit MediaRouterMojoImpl(extensions::EventPageTracker* event_page_tracker,
218 extensions::EventPageTracker* event_page_tracker); 228 content::BrowserContext* context);
219 229
220 // Binds |this| to a Mojo interface request, so that clients can acquire a 230 // Binds |this| to a Mojo interface request, so that clients can acquire a
221 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. 231 // handle to a MediaRouterMojoImpl instance via the Mojo service connector.
222 // Stores the ID of |extension| in |media_route_provider_extension_id_|. 232 // Stores the ID of |extension| in |media_route_provider_extension_id_|.
223 void BindToMojoRequest( 233 void BindToMojoRequest(
224 mojo::InterfaceRequest<mojom::MediaRouter> request, 234 mojo::InterfaceRequest<mojom::MediaRouter> request,
225 const extensions::Extension& extension); 235 const extensions::Extension& extension);
226 236
227 // Enqueues a closure for later execution by ExecutePendingRequests(). 237 // Enqueues a closure for later execution by ExecutePendingRequests().
228 void EnqueueTask(base::OnceClosure closure); 238 void EnqueueTask(base::OnceClosure closure);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // period. 392 // period.
383 void EnsureMdnsDiscoveryEnabled(); 393 void EnsureMdnsDiscoveryEnabled();
384 void DoEnsureMdnsDiscoveryEnabled(); 394 void DoEnsureMdnsDiscoveryEnabled();
385 395
386 // Callback used to enabled mDNS in the MRPM if a firewall prompt will not be 396 // Callback used to enabled mDNS in the MRPM if a firewall prompt will not be
387 // triggered. If a firewall prompt would be triggered, enabling mDNS won't 397 // triggered. If a firewall prompt would be triggered, enabling mDNS won't
388 // happen until the user is clearly interacting with MR. 398 // happen until the user is clearly interacting with MR.
389 void OnFirewallCheckComplete(bool firewall_can_use_local_ports); 399 void OnFirewallCheckComplete(bool firewall_can_use_local_ports);
390 #endif 400 #endif
391 401
402 // Start browser side sink discovery.
403 void StartBrowserSideDiscovery(net::URLRequestContextGetter* request_context);
mark a. foltz 2017/05/01 20:32:57 Just StartDiscovery()? Since this is running in t
zhaobin 2017/05/03 01:53:59 Done.
404
405 // Invoked when browser side sink disocvery finished.
mark a. foltz 2017/05/01 20:32:57 Typo in discovery
zhaobin 2017/05/03 01:53:59 Done.
406 void OnDialMediaSinkDiscovered(const std::vector<MediaSinkInternal>& sinks);
407
392 // Requests MRPM to update media sinks. This allows MRPs that only do 408 // Requests MRPM to update media sinks. This allows MRPs that only do
393 // discovery on sink queries an opportunity to update discovery results 409 // discovery on sink queries an opportunity to update discovery results
394 // even if the MRP SinkAvailability is marked UNAVAILABLE. 410 // even if the MRP SinkAvailability is marked UNAVAILABLE.
395 void UpdateMediaSinks(const MediaSource::Id& source_id); 411 void UpdateMediaSinks(const MediaSource::Id& source_id);
396 void DoUpdateMediaSinks(const MediaSource::Id& source_id); 412 void DoUpdateMediaSinks(const MediaSource::Id& source_id);
397 413
398 // Invalidates and removes controllers from |route_controllers_| whose media 414 // Invalidates and removes controllers from |route_controllers_| whose media
399 // routes do not appear in |routes|. 415 // routes do not appear in |routes|.
400 void RemoveInvalidRouteControllers(const std::vector<MediaRoute>& routes); 416 void RemoveInvalidRouteControllers(const std::vector<MediaRoute>& routes);
401 417
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 MediaRouteProviderWakeReason current_wake_reason_; 468 MediaRouteProviderWakeReason current_wake_reason_;
453 469
454 // A flag to ensure that we record the provider version once, during the 470 // A flag to ensure that we record the provider version once, during the
455 // initial event page wakeup attempt. 471 // initial event page wakeup attempt.
456 bool provider_version_was_recorded_ = false; 472 bool provider_version_was_recorded_ = false;
457 473
458 // Stores route controllers that can be used to send media commands to the 474 // Stores route controllers that can be used to send media commands to the
459 // extension. 475 // extension.
460 std::unordered_map<MediaRoute::Id, MediaRouteController*> route_controllers_; 476 std::unordered_map<MediaRoute::Id, MediaRouteController*> route_controllers_;
461 477
478 // Media sink service for DIAL devices.
479 std::unique_ptr<DialMediaSinkService,
480 content::BrowserThread::DeleteOnIOThread>
mark a. foltz 2017/05/01 20:32:57 There could be a shutdown race condition here - th
zhaobin 2017/05/03 01:53:59 Per discussion with Derek, we are going to make Di
481 dial_media_sink_service_;
482
483 content::BrowserContext* context_;
484
462 #if defined(OS_WIN) 485 #if defined(OS_WIN)
463 // A pair of flags to ensure that mDNS discovery is only enabled on Windows 486 // A pair of flags to ensure that mDNS discovery is only enabled on Windows
464 // when there will be appropriate context for the user to associate a firewall 487 // when there will be appropriate context for the user to associate a firewall
465 // prompt with Media Router. |should_enable_mdns_discovery_| can only go from 488 // prompt with Media Router. |should_enable_mdns_discovery_| can only go from
466 // |false| to |true|. On Windows, |is_mdns_enabled_| is set to |false| in 489 // |false| to |true|. On Windows, |is_mdns_enabled_| is set to |false| in
467 // RegisterMediaRouteProvider and only set to |true| when we successfully call 490 // RegisterMediaRouteProvider and only set to |true| when we successfully call
468 // the extension to enable mDNS. 491 // the extension to enable mDNS.
469 bool is_mdns_enabled_ = false; 492 bool is_mdns_enabled_ = false;
470 bool should_enable_mdns_discovery_ = false; 493 bool should_enable_mdns_discovery_ = false;
471 #endif 494 #endif
472 495
473 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; 496 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_;
474 497
475 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); 498 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl);
476 }; 499 };
477 500
478 } // namespace media_router 501 } // namespace media_router
479 502
480 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ 503 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698