blob: 933f840de134a797bd056899ebc683180174eee3 [file] [log] [blame]
imchengf3e5a012015-11-20 04:08:371// 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
mfoltzb4ba3722016-03-18 17:13:448#include <set>
mfoltzbdabddf2016-04-27 06:10:469#include <vector>
mfoltzb4ba3722016-03-18 17:13:4410
imchengf3e5a012015-11-20 04:08:3711#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"
mfoltzbdabddf2016-04-27 06:10:4616#include "chrome/browser/media/router/media_route.h"
imchengf3e5a012015-11-20 04:08:3717#include "chrome/browser/media/router/media_router.h"
mfoltzbdabddf2016-04-27 06:10:4618#include "chrome/browser/media/router/media_routes_observer.h"
mfoltzb4ba3722016-03-18 17:13:4419
imchengf3e5a012015-11-20 04:08:3720namespace media_router {
21
22class MediaRouterBase : public MediaRouter {
23 public:
imchengf3e5a012015-11-20 04:08:3724 ~MediaRouterBase() override;
25
dchengc16dc8092016-04-08 23:12:5626 std::unique_ptr<PresentationConnectionStateSubscription>
imchengf3e5a012015-11-20 04:08:3727 AddPresentationConnectionStateChangedCallback(
28 const MediaRoute::Id& route_id,
29 const content::PresentationConnectionStateChangedCallback& callback)
30 override;
31
mfoltzb4ba3722016-03-18 17:13:4432 // 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
imchengf3e5a012015-11-20 04:08:3736 protected:
37 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
38 PresentationConnectionStateChangedCallback);
imchenged10e962016-02-23 06:34:4439 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoImplTest,
40 PresentationConnectionStateChangedCallbackRemoved);
imchengf3e5a012015-11-20 04:08:3741
mfoltzbdabddf2016-04-27 06:10:4642 MediaRouterBase();
43
avayvodca198012016-04-18 17:21:1844 // Generates a unique presentation id. Shared between Android and desktop.
45 static std::string CreatePresentationId();
46
imchengf3e5a012015-11-20 04:08:3747 void NotifyPresentationConnectionStateChange(
48 const MediaRoute::Id& route_id,
49 content::PresentationConnectionState state);
imchenged10e962016-02-23 06:34:4450 void NotifyPresentationConnectionClose(
51 const MediaRoute::Id& route_id,
52 content::PresentationConnectionCloseReason reason,
53 const std::string& message);
imchengf3e5a012015-11-20 04:08:3754
mfoltzbdabddf2016-04-27 06:10:4655 // Returns true when there is at least one MediaRoute with is_local = true.
56 bool HasLocalRoute() const;
mfoltzb4ba3722016-03-18 17:13:4457
imchenged10e962016-02-23 06:34:4458 using PresentationConnectionStateChangedCallbacks = base::CallbackList<void(
59 const content::PresentationConnectionStateChangeInfo&)>;
mfoltzbdabddf2016-04-27 06:10:4660
imchengf3e5a012015-11-20 04:08:3761 base::ScopedPtrHashMap<
62 MediaRoute::Id,
dchengc16dc8092016-04-08 23:12:5663 std::unique_ptr<PresentationConnectionStateChangedCallbacks>>
imchengf3e5a012015-11-20 04:08:3764 presentation_connection_state_callbacks_;
65
66 base::ThreadChecker thread_checker_;
67
68 private:
mfoltzbdabddf2016-04-27 06:10:4669 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
imchengf3e5a012015-11-20 04:08:3777 // 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
mfoltzbdabddf2016-04-27 06:10:4682 // KeyedService
83 void Shutdown() override;
84
85 std::unique_ptr<InternalMediaRoutesObserver> internal_routes_observer_;
86 bool initialized_;
mfoltzb4ba3722016-03-18 17:13:4487
imchengf3e5a012015-11-20 04:08:3788 DISALLOW_COPY_AND_ASSIGN(MediaRouterBase);
89};
90
91} // namespace media_router
92
93#endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_BASE_H_