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

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

Issue 2874283002: [Media Router] Notify MRUI of a media status update when it starts observing (Closed)
Patch Set: Address Mark's comments 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_ROUTE_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 virtual ~Observer(); 45 virtual ~Observer();
46 46
47 virtual void OnMediaStatusUpdated(const MediaStatus& status) = 0; 47 virtual void OnMediaStatusUpdated(const MediaStatus& status) = 0;
48 48
49 // Returns a reference to the observed MediaRouteController. The reference 49 // Returns a reference to the observed MediaRouteController. The reference
50 // should not be stored by any object that does not subclass ::Observer. 50 // should not be stored by any object that does not subclass ::Observer.
51 scoped_refptr<MediaRouteController> controller() const { 51 scoped_refptr<MediaRouteController> controller() const {
52 return controller_; 52 return controller_;
53 } 53 }
54 54
55 protected:
56 scoped_refptr<MediaRouteController> controller_;
57
55 private: 58 private:
56 friend class MediaRouteController; 59 friend class MediaRouteController;
57 60
58 // Disposes the reference to the controller. 61 // Disposes the reference to the controller.
59 void InvalidateController(); 62 void InvalidateController();
60 63
61 // Called by InvalidateController() after the reference to the controller is 64 // Called by InvalidateController() after the reference to the controller is
62 // disposed. Overridden by subclasses to do custom cleanup. 65 // disposed. Overridden by subclasses to do custom cleanup.
63 virtual void OnControllerInvalidated(); 66 virtual void OnControllerInvalidated();
64 67
65 scoped_refptr<MediaRouteController> controller_;
66
67 DISALLOW_COPY_AND_ASSIGN(Observer); 68 DISALLOW_COPY_AND_ASSIGN(Observer);
68 }; 69 };
69 70
70 // Constructs a MediaRouteController that forwards media commands to 71 // Constructs a MediaRouteController that forwards media commands to
71 // |mojo_media_controller|. |media_router| will be notified when the 72 // |mojo_media_controller|. |media_router| will be notified when the
72 // MediaRouteController is destroyed via DetachRouteController(). 73 // MediaRouteController is destroyed via DetachRouteController().
73 MediaRouteController(const MediaRoute::Id& route_id, 74 MediaRouteController(const MediaRoute::Id& route_id,
74 mojom::MediaControllerPtr mojo_media_controller, 75 mojom::MediaControllerPtr mojo_media_controller,
75 MediaRouter* media_router); 76 MediaRouter* media_router);
76 77
(...skipping 12 matching lines...) Expand all
89 // Notifies |observers_| to dispose their references to the controller. The 90 // Notifies |observers_| to dispose their references to the controller. The
90 // controller gets destroyed when all the references are disposed. 91 // controller gets destroyed when all the references are disposed.
91 void Invalidate(); 92 void Invalidate();
92 93
93 // Returns a mojo pointer bound to |this| by |binding_|. This must only be 94 // Returns a mojo pointer bound to |this| by |binding_|. This must only be
94 // called at most once in the lifetime of the controller. 95 // called at most once in the lifetime of the controller.
95 mojom::MediaStatusObserverPtr BindObserverPtr(); 96 mojom::MediaStatusObserverPtr BindObserverPtr();
96 97
97 MediaRoute::Id route_id() const { return route_id_; } 98 MediaRoute::Id route_id() const { return route_id_; }
98 99
100 const base::Optional<MediaStatus>& current_media_status() const {
mark a. foltz 2017/05/12 23:06:18 Document this method
takumif 2017/05/15 17:57:29 Done.
101 return current_media_status_;
102 }
103
99 protected: 104 protected:
100 ~MediaRouteController() override; 105 ~MediaRouteController() override;
101 106
102 private: 107 private:
103 friend class base::RefCounted<MediaRouteController>; 108 friend class base::RefCounted<MediaRouteController>;
104 109
105 void AddObserver(Observer* observer); 110 void AddObserver(Observer* observer);
106 void RemoveObserver(Observer* observer); 111 void RemoveObserver(Observer* observer);
107 112
108 // Called when the connection between |this| and the MediaControllerPtr or 113 // Called when the connection between |this| and the MediaControllerPtr or
(...skipping 13 matching lines...) Expand all
122 // The binding to observe the out-of-process provider of status updates. 127 // The binding to observe the out-of-process provider of status updates.
123 mojo::Binding<mojom::MediaStatusObserver> binding_; 128 mojo::Binding<mojom::MediaStatusObserver> binding_;
124 129
125 // Observers that are notified of status updates. The observers share the 130 // Observers that are notified of status updates. The observers share the
126 // ownership of the controller through scoped_refptr. 131 // ownership of the controller through scoped_refptr.
127 base::ObserverList<Observer> observers_; 132 base::ObserverList<Observer> observers_;
128 133
129 // This becomes false when the controller is invalidated. 134 // This becomes false when the controller is invalidated.
130 bool is_valid_ = true; 135 bool is_valid_ = true;
131 136
137 // The latest media status that the controller has been notified with.
138 base::Optional<MediaStatus> current_media_status_;
139
132 DISALLOW_COPY_AND_ASSIGN(MediaRouteController); 140 DISALLOW_COPY_AND_ASSIGN(MediaRouteController);
133 }; 141 };
134 142
135 } // namespace media_router 143 } // namespace media_router
136 144
137 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ 145 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698