imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_BASE_H_ |
| 6 | #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_BASE_H_ |
| 7 | |
mfoltz | b4ba372 | 2016-03-18 17:13:44 | [diff] [blame] | 8 | #include <set> |
mfoltz | bdabddf | 2016-04-27 06:10:46 | [diff] [blame^] | 9 | #include <vector> |
mfoltz | b4ba372 | 2016-03-18 17:13:44 | [diff] [blame] | 10 | |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 11 | #include "base/callback_list.h" |
| 12 | #include "base/containers/scoped_ptr_hash_map.h" |
| 13 | #include "base/gtest_prod_util.h" |
| 14 | #include "base/macros.h" |
| 15 | #include "base/threading/thread_checker.h" |
mfoltz | bdabddf | 2016-04-27 06:10:46 | [diff] [blame^] | 16 | #include "chrome/browser/media/router/media_route.h" |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 17 | #include "chrome/browser/media/router/media_router.h" |
mfoltz | bdabddf | 2016-04-27 06:10:46 | [diff] [blame^] | 18 | #include "chrome/browser/media/router/media_routes_observer.h" |
mfoltz | b4ba372 | 2016-03-18 17:13:44 | [diff] [blame] | 19 | |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 20 | namespace media_router { |
| 21 | |
| 22 | class MediaRouterBase : public MediaRouter { |
| 23 | public: |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 24 | ~MediaRouterBase() override; |
| 25 | |
dcheng | c16dc809 | 2016-04-08 23:12:56 | [diff] [blame] | 26 | std::unique_ptr<PresentationConnectionStateSubscription> |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 27 | AddPresentationConnectionStateChangedCallback( |
| 28 | const MediaRoute::Id& route_id, |
| 29 | const content::PresentationConnectionStateChangedCallback& callback) |
| 30 | override; |
| 31 | |
mfoltz | b4ba372 | 2016-03-18 17:13:44 | [diff] [blame] | 32 | // Called when the off the record (incognito) profile for this instance is |
| 33 | // being shut down. This will terminate all off the record media routes. |
| 34 | void OnOffTheRecordProfileShutdown() override; |
| 35 | |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 36 | protected: |
| 37 | FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, |
| 38 | PresentationConnectionStateChangedCallback); |
imcheng | ed10e96 | 2016-02-23 06:34:44 | [diff] [blame] | 39 | FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest, |
| 40 | PresentationConnectionStateChangedCallbackRemoved); |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 41 | |
mfoltz | bdabddf | 2016-04-27 06:10:46 | [diff] [blame^] | 42 | MediaRouterBase(); |
| 43 | |
avayvod | ca19801 | 2016-04-18 17:21:18 | [diff] [blame] | 44 | // Generates a unique presentation id. Shared between Android and desktop. |
| 45 | static std::string CreatePresentationId(); |
| 46 | |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 47 | void NotifyPresentationConnectionStateChange( |
| 48 | const MediaRoute::Id& route_id, |
| 49 | content::PresentationConnectionState state); |
imcheng | ed10e96 | 2016-02-23 06:34:44 | [diff] [blame] | 50 | void NotifyPresentationConnectionClose( |
| 51 | const MediaRoute::Id& route_id, |
| 52 | content::PresentationConnectionCloseReason reason, |
| 53 | const std::string& message); |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 54 | |
mfoltz | bdabddf | 2016-04-27 06:10:46 | [diff] [blame^] | 55 | // Returns true when there is at least one MediaRoute with is_local = true. |
| 56 | bool HasLocalRoute() const; |
mfoltz | b4ba372 | 2016-03-18 17:13:44 | [diff] [blame] | 57 | |
imcheng | ed10e96 | 2016-02-23 06:34:44 | [diff] [blame] | 58 | using PresentationConnectionStateChangedCallbacks = base::CallbackList<void( |
| 59 | const content::PresentationConnectionStateChangeInfo&)>; |
mfoltz | bdabddf | 2016-04-27 06:10:46 | [diff] [blame^] | 60 | |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 61 | base::ScopedPtrHashMap< |
| 62 | MediaRoute::Id, |
dcheng | c16dc809 | 2016-04-08 23:12:56 | [diff] [blame] | 63 | std::unique_ptr<PresentationConnectionStateChangedCallbacks>> |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 64 | presentation_connection_state_callbacks_; |
| 65 | |
| 66 | base::ThreadChecker thread_checker_; |
| 67 | |
| 68 | private: |
mfoltz | bdabddf | 2016-04-27 06:10:46 | [diff] [blame^] | 69 | friend class MediaRouterFactory; |
| 70 | friend class MediaRouterMojoTest; |
| 71 | |
| 72 | class InternalMediaRoutesObserver; |
| 73 | |
| 74 | // Must be called before invoking any other method. |
| 75 | void Initialize(); |
| 76 | |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 77 | // Called when a PresentationConnectionStateChangedCallback associated with |
| 78 | // |route_id| is removed from |presentation_connection_state_callbacks_|. |
| 79 | void OnPresentationConnectionStateCallbackRemoved( |
| 80 | const MediaRoute::Id& route_id); |
| 81 | |
mfoltz | bdabddf | 2016-04-27 06:10:46 | [diff] [blame^] | 82 | // KeyedService |
| 83 | void Shutdown() override; |
| 84 | |
| 85 | std::unique_ptr<InternalMediaRoutesObserver> internal_routes_observer_; |
| 86 | bool initialized_; |
mfoltz | b4ba372 | 2016-03-18 17:13:44 | [diff] [blame] | 87 | |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 88 | DISALLOW_COPY_AND_ASSIGN(MediaRouterBase); |
| 89 | }; |
| 90 | |
| 91 | } // namespace media_router |
| 92 | |
| 93 | #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_BASE_H_ |