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

Side by Side Diff: chrome/browser/media/router/media_route.h

Issue 949293004: Add media router common classes and unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chunkier CL Created 5 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 2014 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_ROUTE_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTE_H_
7
8 #include <string>
9
10 #include "base/logging.h"
11 #include "base/values.h"
12 #include "chrome/browser/media/router/media_route_id.h"
13 #include "chrome/browser/media/router/media_sink.h"
14 #include "chrome/browser/media/router/media_source.h"
15 #include "url/gurl.h"
16
17 namespace media_router {
18
19 typedef int64 RouteRequestId;
20
21 extern const RouteRequestId kInvalidRouteRequestId;
22
23 // For now, a simple transition graph: NEW -> CONNECTED -> CLOSED.
24 enum MediaRouteState {
25 // The route is new and not yet connected to a sink.
26 MEDIA_ROUTE_STATE_NEW,
27 // The route is active and connected to a sink.
28 MEDIA_ROUTE_STATE_CONNECTED,
29 // The route has been disconnected.
30 MEDIA_ROUTE_STATE_CLOSED
31 };
32
33 // TODO(mfoltz): Add errors as needed.
34 enum MediaRouteError {
35 MEDIA_ROUTE_ERROR_NONE
36 };
37
38 // A MediaRoute encapsulates an application's means of routing media from a
39 // source to a sink.
40 class MediaRoute {
41 public:
42 // Ctor. Do not call directly, use MediaRouteFactory instead.
43 // TODO(mfoltz): Make private and friend MRF
44 // |media_route_id|: Uniquely identifies the route among active
45 // instances.
46 // |type|: Type of media route.
47 // |media_source|: Description of source of the route.
48 // |sink_id|: ID of the MediaSink of the route.
49 // |description|: Description of the route to be displayed.
50 // |is_local|: true if the route was created initiated from this Chrome
51 // instance.
52 MediaRoute(const MediaRouteId& media_route_id,
53 const MediaSource& media_source,
54 const MediaSinkId& sink_id,
55 const std::string& description,
56 bool is_local);
57
58 ~MediaRoute();
59
60 // The media route identifier.
61 const MediaRouteId& media_route_id() const { return media_route_id_; }
62
63 // The state of the media route.
64 MediaRouteState state() const { return state_; }
65
66 // The media source being routed.
67 const MediaSource& media_source() const { return media_source_; }
68
69 // The sink being routed to.
70 const MediaSinkId& sink_id() const { return sink_id_; }
71
72 // The description of the media route activity.
73 const std::string& description() const { return description_; }
74
75 // Returns |true| if the route is initiated locally.
76 bool is_local() const { return is_local_; }
77
78 bool operator==(const MediaRoute& other) const;
79 bool operator!=(const MediaRoute& other) const;
80
81 private:
82 MediaRouteId media_route_id_;
83 MediaSource media_source_;
84 MediaSinkId sink_id_;
85 std::string description_;
86 bool is_local_;
87 MediaRouteState state_;
88 // TODO(imcheng): Add icon URL.
89 };
90
91 // Response to a media route request to the Media Route Provider.
92 class MediaRouteResponse {
93 public:
94 // Creates a MediaRouteResponse object that indicates success.
95 // |request_id|: ID of original request.
96 // |route|: Route created.
97 static scoped_ptr<MediaRouteResponse> Success(
98 const RouteRequestId& request_id, const MediaRoute& route);
99 // Creates a MediaRouteResponse object that indicates failure.
100 // |request_id|: ID of original request.
101 // |error|: Failure reason.
102 static scoped_ptr<MediaRouteResponse> Error(
103 const RouteRequestId& request_id, const std::string& error);
104
105 ~MediaRouteResponse();
106
107 const RouteRequestId& request_id() const { return request_id_; }
108 // Returns a pointer to the route created. Returns nullptr if response
109 // indicates error.
110 const MediaRoute* route() const { return route_.get(); }
111 const std::string& error() const { return error_; }
112
113 private:
114 MediaRouteResponse(
115 const RouteRequestId& request_id, const MediaRoute& route);
116 MediaRouteResponse(
117 const RouteRequestId& request_id, const std::string& error);
118 MediaRouteResponse(const MediaRouteResponse& other);
119
120 // ID of original request. Set in all MediaRouteResponse objects, regardless
121 // of success/failure.
122 RouteRequestId request_id_;
123 // The route created as a result of the request. Points to a valid MediaRoute
124 // iff the response indicates success, nullptr otherwise.
125 scoped_ptr<MediaRoute> route_;
126 // Set to empty string if response indicates success, otherwise set to the
127 // failure reason.
128 std::string error_;
129 };
130
131 } // namespace media_router
132
133 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698