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

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: Created 3 years, 8 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
43 namespace media_router { 45 namespace media_router {
44 46
47 #if !defined(OS_ANDROID)
48 extern const base::Feature kEnableBrowserSideDiscovery;
49 #endif
50
45 enum class MediaRouteProviderWakeReason; 51 enum class MediaRouteProviderWakeReason;
52 class DialMediaSinkService;
46 53
47 // MediaRouter implementation that delegates calls to the component extension. 54 // MediaRouter implementation that delegates calls to the component extension.
48 // Also handles the suspension and wakeup of the component extension. 55 // Also handles the suspension and wakeup of the component extension.
49 // Lives on the UI thread. 56 // Lives on the UI thread.
50 class MediaRouterMojoImpl : public MediaRouterBase, 57 class MediaRouterMojoImpl : public MediaRouterBase,
51 public mojom::MediaRouter { 58 public mojom::MediaRouter {
52 public: 59 public:
53 ~MediaRouterMojoImpl() override; 60 ~MediaRouterMojoImpl() override;
54 61
55 // Sets up the MediaRouterMojoImpl instance owned by |context| to handle 62 // 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; 214 std::vector<std::string> joinable_route_ids;
208 215
209 base::ObserverList<MediaRoutesObserver> observers; 216 base::ObserverList<MediaRoutesObserver> observers;
210 217
211 private: 218 private:
212 DISALLOW_COPY_AND_ASSIGN(MediaRoutesQuery); 219 DISALLOW_COPY_AND_ASSIGN(MediaRoutesQuery);
213 }; 220 };
214 221
215 // Standard constructor, used by 222 // Standard constructor, used by
216 // MediaRouterMojoImplFactory::GetApiForBrowserContext. 223 // MediaRouterMojoImplFactory::GetApiForBrowserContext.
217 explicit MediaRouterMojoImpl( 224 explicit MediaRouterMojoImpl(extensions::EventPageTracker* event_page_tracker,
218 extensions::EventPageTracker* event_page_tracker); 225 content::BrowserContext* context);
219 226
220 // Binds |this| to a Mojo interface request, so that clients can acquire a 227 // Binds |this| to a Mojo interface request, so that clients can acquire a
221 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. 228 // handle to a MediaRouterMojoImpl instance via the Mojo service connector.
222 // Stores the ID of |extension| in |media_route_provider_extension_id_|. 229 // Stores the ID of |extension| in |media_route_provider_extension_id_|.
223 void BindToMojoRequest( 230 void BindToMojoRequest(
224 mojo::InterfaceRequest<mojom::MediaRouter> request, 231 mojo::InterfaceRequest<mojom::MediaRouter> request,
225 const extensions::Extension& extension); 232 const extensions::Extension& extension);
226 233
227 // Enqueues a closure for later execution by ExecutePendingRequests(). 234 // Enqueues a closure for later execution by ExecutePendingRequests().
228 void EnqueueTask(base::OnceClosure closure); 235 void EnqueueTask(base::OnceClosure closure);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // period. 389 // period.
383 void EnsureMdnsDiscoveryEnabled(); 390 void EnsureMdnsDiscoveryEnabled();
384 void DoEnsureMdnsDiscoveryEnabled(); 391 void DoEnsureMdnsDiscoveryEnabled();
385 392
386 // Callback used to enabled mDNS in the MRPM if a firewall prompt will not be 393 // 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 394 // triggered. If a firewall prompt would be triggered, enabling mDNS won't
388 // happen until the user is clearly interacting with MR. 395 // happen until the user is clearly interacting with MR.
389 void OnFirewallCheckComplete(bool firewall_can_use_local_ports); 396 void OnFirewallCheckComplete(bool firewall_can_use_local_ports);
390 #endif 397 #endif
391 398
399 #if !defined(OS_ANDROID)
mark a. foltz 2017/04/26 23:52:55 Do we even compile MediaRouterMojoImpl for Android
zhaobin 2017/05/03 01:53:59 Done.
400 // Start browser side sink discovery.
401 void StartBrowserSideDiscovery();
402
403 // Invoked when browser side sink disocvery finished.
404 void OnDialMediaSinkDiscovered(const std::vector<MediaSinkInternal>& sinks);
405 #endif
406
392 // Requests MRPM to update media sinks. This allows MRPs that only do 407 // Requests MRPM to update media sinks. This allows MRPs that only do
393 // discovery on sink queries an opportunity to update discovery results 408 // discovery on sink queries an opportunity to update discovery results
394 // even if the MRP SinkAvailability is marked UNAVAILABLE. 409 // even if the MRP SinkAvailability is marked UNAVAILABLE.
395 void UpdateMediaSinks(const MediaSource::Id& source_id); 410 void UpdateMediaSinks(const MediaSource::Id& source_id);
396 void DoUpdateMediaSinks(const MediaSource::Id& source_id); 411 void DoUpdateMediaSinks(const MediaSource::Id& source_id);
397 412
398 // Invalidates and removes controllers from |route_controllers_| whose media 413 // Invalidates and removes controllers from |route_controllers_| whose media
399 // routes do not appear in |routes|. 414 // routes do not appear in |routes|.
400 void RemoveInvalidRouteControllers(const std::vector<MediaRoute>& routes); 415 void RemoveInvalidRouteControllers(const std::vector<MediaRoute>& routes);
401 416
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // Allows the extension to be monitored for suspend, and woken. 450 // Allows the extension to be monitored for suspend, and woken.
436 // This is a reference to a BrowserContext keyed service that outlives this 451 // This is a reference to a BrowserContext keyed service that outlives this
437 // instance. 452 // instance.
438 extensions::EventPageTracker* event_page_tracker_; 453 extensions::EventPageTracker* event_page_tracker_;
439 454
440 // GUID unique to each browser run. Component extension uses this to detect 455 // GUID unique to each browser run. Component extension uses this to detect
441 // when its persisted state was written by an older browser instance, and is 456 // when its persisted state was written by an older browser instance, and is
442 // therefore stale. 457 // therefore stale.
443 std::string instance_id_; 458 std::string instance_id_;
444 459
460 // Whether or not to enable browser side device discovery. Controlled by
461 // feature |kEnableBrowserSideDiscovery|.
462 bool enable_browser_side_discovery_;
mark a. foltz 2017/04/26 23:52:55 We probably want flags for individual providers (D
zhaobin 2017/05/03 01:53:59 Done.
463
445 // The last reported sink availability from the media route provider manager. 464 // The last reported sink availability from the media route provider manager.
446 mojom::MediaRouter::SinkAvailability availability_; 465 mojom::MediaRouter::SinkAvailability availability_;
447 466
448 int wakeup_attempt_count_ = 0; 467 int wakeup_attempt_count_ = 0;
449 468
450 // Records the current reason the extension is being woken up. Is set to 469 // Records the current reason the extension is being woken up. Is set to
451 // MediaRouteProviderWakeReason::TOTAL_COUNT if there is no pending reason. 470 // MediaRouteProviderWakeReason::TOTAL_COUNT if there is no pending reason.
452 MediaRouteProviderWakeReason current_wake_reason_; 471 MediaRouteProviderWakeReason current_wake_reason_;
453 472
454 // A flag to ensure that we record the provider version once, during the 473 // A flag to ensure that we record the provider version once, during the
455 // initial event page wakeup attempt. 474 // initial event page wakeup attempt.
456 bool provider_version_was_recorded_ = false; 475 bool provider_version_was_recorded_ = false;
457 476
458 // Stores route controllers that can be used to send media commands to the 477 // Stores route controllers that can be used to send media commands to the
459 // extension. 478 // extension.
460 std::unordered_map<MediaRoute::Id, MediaRouteController*> route_controllers_; 479 std::unordered_map<MediaRoute::Id, MediaRouteController*> route_controllers_;
461 480
481 // Media sink service for DIAL devices.
482 std::unique_ptr<DialMediaSinkService,
483 content::BrowserThread::DeleteOnIOThread>
484 dial_media_sink_service_;
485
486 content::BrowserContext* context_;
487
462 #if defined(OS_WIN) 488 #if defined(OS_WIN)
463 // A pair of flags to ensure that mDNS discovery is only enabled on Windows 489 // 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 490 // 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 491 // 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 492 // |false| to |true|. On Windows, |is_mdns_enabled_| is set to |false| in
467 // RegisterMediaRouteProvider and only set to |true| when we successfully call 493 // RegisterMediaRouteProvider and only set to |true| when we successfully call
468 // the extension to enable mDNS. 494 // the extension to enable mDNS.
469 bool is_mdns_enabled_ = false; 495 bool is_mdns_enabled_ = false;
470 bool should_enable_mdns_discovery_ = false; 496 bool should_enable_mdns_discovery_ = false;
471 #endif 497 #endif
472 498
473 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; 499 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_;
474 500
475 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); 501 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl);
476 }; 502 };
477 503
478 } // namespace media_router 504 } // namespace media_router
479 505
480 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ 506 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698