OLD | NEW |
| (Empty) |
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_PRESENTATION_SESSION_STATE_OBSERVER_H_ | |
6 #define CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SESSION_STATE_OBSERVER_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/gtest_prod_util.h" | |
11 #include "chrome/browser/media/router/media_route.h" | |
12 #include "chrome/browser/media/router/media_routes_observer.h" | |
13 #include "content/public/browser/presentation_service_delegate.h" | |
14 | |
15 namespace media_router { | |
16 | |
17 class MediaRouter; | |
18 | |
19 // TODO(imcheng): Remove this class and use PresentationConnectionStateObserver | |
20 // instead (crbug.com/529893). | |
21 // MediaRoutesObserver implementation that allows tracking state changes from | |
22 // multiple presentation sessions and notifying the client via | |
23 // |state_changed_callback|. | |
24 // Clients provide the callback on construction, and incrementally add route | |
25 // IDs to track by calling |OnPresentationSessionConnected| as they are created, | |
26 // which also has the effect of invoking the callback that the session has | |
27 // become connected. | |
28 // When a presentation is disconnected, the callback will be invoked and it | |
29 // will be removed from the tracked set. | |
30 // When the routes no longer need to tracked, |Reset| can be called. | |
31 class PresentationSessionStateObserver : public MediaRoutesObserver { | |
32 public: | |
33 PresentationSessionStateObserver( | |
34 const content::SessionStateChangedCallback& state_changed_callback, | |
35 const MediaRouteIdToPresentationSessionMapping* route_id_to_presentation, | |
36 MediaRouter* router); | |
37 ~PresentationSessionStateObserver() override; | |
38 | |
39 // Called when a presentation with |route_id| has been created in connected | |
40 // state and invoke the callback. | |
41 void OnPresentationSessionConnected(const MediaRoute::Id& route_id); | |
42 | |
43 // Clears the set of presentations being tracked. | |
44 void Reset(); | |
45 | |
46 private: | |
47 FRIEND_TEST_ALL_PREFIXES(PresentationSessionStateObserverTest, | |
48 InvokeCallbackWithDisconnected); | |
49 FRIEND_TEST_ALL_PREFIXES(PresentationSessionStateObserverTest, Reset); | |
50 | |
51 // MediaRoutesObserver override | |
52 void OnRoutesUpdated(const std::vector<MediaRoute>& routes) override; | |
53 | |
54 // Invokes |state_changed_callback_| with PresentationSessionInfo derived from | |
55 // |route_id| and |new_state|, if |route_id| is valid. | |
56 void InvokeCallback(const MediaRoute::Id& route_id, | |
57 content::PresentationConnectionState new_state); | |
58 | |
59 // Route IDs of presentations that are being tracked for state changes. | |
60 // It is built by adding entries when a presentation is started, | |
61 // and removing entries when the presentation is no longer in subsequent | |
62 // route list updates. | |
63 std::vector<MediaRoute::Id> tracked_route_ids_; | |
64 | |
65 // Stores previous list of routes observed from MediaRouter. | |
66 // It is compared against the new observed list of routes for disconnected | |
67 // routes that are in |tracked_route_ids_|. | |
68 // TODO(imcheng): A more explicit set of MediaRoutesObserver APIs (e.g., | |
69 // OnRoutesClosed) would be helpful here. (crbug.com/508751) | |
70 std::vector<MediaRoute::Id> previous_route_ids_; | |
71 | |
72 // Callback to invoke when state change occurs. | |
73 content::SessionStateChangedCallback state_changed_callback_; | |
74 | |
75 // Note that while it is declared const to prevent this class from modifying | |
76 // it, its contents can be changed by the PresentationFrame that owns it. | |
77 const MediaRouteIdToPresentationSessionMapping* const | |
78 route_id_to_presentation_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(PresentationSessionStateObserver); | |
81 }; | |
82 | |
83 } // namespace media_router | |
84 | |
85 #endif // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SESSION_STATE_OBSERVER_H_ | |
OLD | NEW |