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

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

Issue 2727123002: [Media Router] Custom Controls 1 - Add MediaStatus, MediaRouteController, and mojo interfaces (Closed)
Patch Set: Add OnControllerBound() Created 3 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_
7
8 #include <memory>
9
10 #include "base/observer_list.h"
11 #include "chrome/browser/media/router/media_route.h"
12 #include "chrome/browser/media/router/mojo/media_controller.mojom.h"
13 #include "mojo/public/cpp/bindings/binding.h"
14
15 namespace media_router {
16
17 // A controller for a MediaRoute. Forwards commands for controlling the route to
18 // an out-of-process controller. Notifies its observers whenever there is a
19 // change in the route's MediaStatus. It is owned by its observers, each of
imcheng 2017/03/16 20:00:43 I think it would be nice to document the life cycl
takumif 2017/03/17 21:48:01 Adding comments/usage.
20 // which holds a scoped_refptr.
21 class MediaRouteController : public mojom::MediaStatusObserver,
22 public base::RefCounted<MediaRouteController> {
23 public:
24 // Observes MediaRouteController for MediaStatus updates. The ownership of a
25 // MediaRouteController is shared by its observers.
26 class Observer {
27 public:
28 // Adds itself as an observer to |controller|.
29 explicit Observer(scoped_refptr<MediaRouteController> controller);
imcheng 2017/03/16 20:00:43 const scoped_refptr<MediaRouteController>&
dcheng 2017/03/17 06:15:14 Note that it is considered OK to pass by value (an
30
31 // Removes itself as an observer if |controller_| is still valid.
32 virtual ~Observer();
33
34 virtual void OnMediaStatusUpdated(const MediaStatus& status) = 0;
35
36 // Disposes the reference to the controller.
37 virtual void OnControllerInvalidated();
imcheng 2017/03/16 20:00:43 Why make this virtual? Seems like you should enfor
takumif 2017/03/17 21:48:02 Yes, the behavior should be enforced, but I also w
imcheng 2017/03/18 00:11:32 A pattern I've seen is to make this non-virtual, a
takumif 2017/03/20 22:10:45 Done.
38
39 MediaRouteController* controller() { return controller_.get(); }
40
41 private:
42 scoped_refptr<MediaRouteController> controller_;
43
44 DISALLOW_COPY_AND_ASSIGN(Observer);
45 };
46
47 // |this| will forward media commands to |media_controller|.
48 // |destructor_callback| will be called in the dtor of |this|.
49 MediaRouteController(MediaRoute::Id route_id,
imcheng 2017/03/16 20:00:43 const ref
takumif 2017/03/17 21:48:02 Done.
50 mojom::MediaControllerPtr media_controller,
51 base::Closure destructor_callback);
imcheng 2017/03/16 20:00:43 const ref
takumif 2017/03/17 21:48:02 Done.
52
53 // Media controller methods for forwarding commands to |media_controller_|.
54 void Play();
55 void Pause();
56 void Seek(base::TimeDelta time);
57 void SetMute(bool mute);
58 void SetVolume(float volume);
59
60 // mojom::MediaStatusObserver:
61 // Notifies |observers_| of a status update.
62 void OnMediaStatusUpdated(const MediaStatus& status) override;
63
64 // Called when the connection between |this| and |media_controller_| is no
65 // longer valid. Notifies |observers_| to dispose their references to |this|.
66 void OnControllerInvalidated();
67
68 // Called when |media_controller_| is bound.
69 void OnControllerBound();
70
71 // Returns a mojo pointer bound to |this| by |binding_|. If |binding_| is
72 // already set, then the previous binding gets invalidated.
73 mojom::MediaStatusObserverPtr GetObserverPtr();
imcheng 2017/03/16 20:00:43 Suggest naming this BindObserverPtr() or similar s
takumif 2017/03/17 21:48:01 Got it. Also moving this method to CL #2.
74
75 const MediaRoute::Id& route_id() const { return route_id_; }
imcheng 2017/03/16 20:00:43 Return by value
takumif 2017/03/17 21:48:02 Done.
76
77 private:
78 friend class base::RefCounted<MediaRouteController>;
79
80 ~MediaRouteController() override;
81
82 void AddObserver(Observer* observer);
83 void RemoveObserver(Observer* observer);
84
85 // Gets called in the dtor.
86 base::Closure destructor_callback_;
87
88 // The out-of-process controller that |this| forwards commands to.
89 mojom::MediaControllerPtr media_controller_;
90
91 // The binding to observe the out-of-process provider of status updates.
92 mojo::Binding<mojom::MediaStatusObserver> binding_;
93
94 // Observers that |this| notifies of status updates. The observers share the
95 // ownership of |this| through scoped_refptr.
96 base::ObserverList<Observer> observers_;
97
98 // The ID of the Media Route that |this| controls.
99 const MediaRoute::Id route_id_;
100
101 DISALLOW_COPY_AND_ASSIGN(MediaRouteController);
102 };
103
104 } // namespace media_router
105
106 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698