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

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

Issue 1126923002: Add Media Router Mojo impl code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed code review feedback. Created 5 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
(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_MEDIA_ROUTER_MOJO_IMPL_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/containers/hash_tables.h"
13 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/message_loop/message_loop_proxy.h"
19 #include "base/observer_list.h"
20 #include "base/threading/thread_checker.h"
21 #include "chrome/browser/media/router/issue.h"
22 #include "chrome/browser/media/router/media_router.h"
23 #include "chrome/browser/media/router/media_router.mojom.h"
24 #include "components/keyed_service/core/keyed_service.h"
25
26 namespace content {
27 class BrowserContext;
28 } // namespace content
29
30 namespace extensions {
31 class EventPageTracker;
32 } // namespace extensions
33
34 namespace media_router {
35
36 class IssuesObserver;
imcheng (use chromium acct) 2015/05/14 23:00:44 these fwd declarations not needed?
Kevin Marshall 2015/05/14 23:04:57 Done.
37 class MediaRouterMojoTest;
38
39 // Implementation of the Mojo-based service which bridges the Media Router
40 // Provider Manager and the Media Router.
41 class MediaRouterMojoImpl : public MediaRouter,
42 public interfaces::MediaRouterObserver,
43 public mojo::ErrorHandler,
44 public KeyedService {
45 public:
46 ~MediaRouterMojoImpl() override;
47
48 // Binds the MediaRouterMojoImpl BrowserContext service to a Mojo request.
49 // Called by the Mojo module registry.
50 // |extension_id|: The ID of the component extension, used for querying
51 // suspension state.
52 // |context|: The BrowserContext which owns the extension process.
53 // |request|: The Mojo connection request used for binding.
54 static void BindToRequest(
55 const std::string& extension_id,
56 content::BrowserContext* context,
57 mojo::InterfaceRequest<interfaces::MediaRouterObserver> request);
58
59 // mojo::ErrorHandler
60 void OnConnectionError() override;
61
62 // interfaces::MediaRouter implementation.
63 // Registers a Mojo MediaRouter proxy object from the extension.
64 void ProvideMediaRouter(
65 interfaces::MediaRouterPtr media_router_ptr,
66 const interfaces::MediaRouterObserver::ProvideMediaRouterCallback&
67 callback) override;
68 void OnMessage(const mojo::String& route_id,
69 const mojo::String& message) override;
70 void OnIssue(interfaces::IssuePtr issue) override;
71 void OnSinksReceived(const mojo::String& media_source,
72 mojo::Array<interfaces::MediaSinkPtr> sinks) override;
73 void OnRoutesUpdated(mojo::Array<interfaces::MediaRoutePtr> routes) override;
74
75 // MediaRouter implementation.
76 // For messages sent to the extension.
77 // Execution of the requests is delegated to the Do* methods, which can be
78 // enqueued for later use if the extension is temporarily suspended.
79 void CreateRoute(const MediaSourceId& source_id,
80 const MediaSinkId& sink_id,
81 const MediaRouteResponseCallback& callback) override;
82 void CloseRoute(const MediaRouteId& route_id) override;
83 void PostMessage(const MediaRouteId& route_id,
84 const std::string& message) override;
85 void ClearIssue(const Issue::IssueId& issue_id) override;
86 // These methods send messages to the extension upon first registration
87 // and last unregistration.
88 bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override;
89 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override;
90 bool RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
91 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override;
92 void AddIssuesObserver(IssuesObserver* observer) override;
93 void RemoveIssuesObserver(IssuesObserver* observer) override;
94
95 private:
96 friend class MediaRouterMojoImplFactory;
97 friend class MediaRouterMojoTest;
98
99 FRIEND_TEST_ALL_PREFIXES(MediaRouterMojoExtensionTest,
100 DeferredBindingAndSuspension);
101
102 // New instances should be constructed through
103 // MediaRouterMojoImplFactory::GetApiForBrowserContext.
104 MediaRouterMojoImpl();
105
106 // Used for testing.
107 MediaRouterMojoImpl(
108 const std::string& mojo_media_router_ext_id,
109 extensions::EventPageTracker* event_page_tracker_for_test);
110
111 // Binds |this| to a Mojo interface request, so that clients can acquire a
112 // handle to a MediaRouterMojoImpl instance via the Mojo service connector.
113 void Bind(mojo::InterfaceRequest<interfaces::MediaRouterObserver> request);
114
115 // Enqueues a closure for later execution by ExecutePendingRequests().
116 void EnqueueTask(const base::Closure& closure);
117
118 // Starts monitoring the suspend state of |extension_id|.
119 void MonitorExtension(const std::string& extension_id,
120 content::BrowserContext* context);
121
122 // Runs a closure if the extension monitored by |extension_monitor_| is
123 // active, or defers it for later execution if the extension is suspended.
124 void RunOrDefer(const base::Closure& request_cb);
125
126 // Runs pending requests in |pending_requests_|.
127 inline void ExecutePendingRequests();
128
129 // These calls invoke methods in the MRPM via Mojo.
130 void DoCreateRoute(const MediaSourceId& source_id,
131 const MediaSinkId& sink_id,
132 const MediaRouteResponseCallback& callback);
133 void DoCloseRoute(const MediaRouteId& route_id);
134 void DoPostMessage(const MediaRouteId& route_id, const std::string& message);
135 void DoClearIssue(const Issue::IssueId& issue_id);
136 void DoStartObservingMediaSinks(const std::string& source_id);
137 void DoStopObservingMediaSinks(const std::string& source_id);
138 void DoStartObservingMediaRoutes();
139 void DoStopObservingMediaRoutes();
140 void DoStartObservingIssues();
141 void DoStopObservingIssues();
142
143 // Pending requests queued to be executed once MRPM becomes ready.
144 std::vector<base::Closure> pending_requests_;
145
146 // Multimap of sinks observer objects, keyed by media source ID.
147 base::ScopedPtrHashMap<MediaSourceId,
148 scoped_ptr<ObserverList<MediaSinksObserver>>>
149 sinks_observers_;
150
151 // List of route observer objects.
152 ObserverList<MediaRoutesObserver> routes_observers_;
153
154 // Binds |this| to a Mojo MediaRouterObserver interface.
155 // The binding is released when binding_ is deleted.
156 scoped_ptr<mojo::Binding<interfaces::MediaRouterObserver>> binding_;
157
158 // Mojo proxy object for the Provider Manager.
159 interfaces::MediaRouterPtr mojo_media_router_;
160
161 // ID of the component extension. Used for managing its suspend/wake state
162 // via event_page_tracker_.
163 std::string mojo_media_router_extension_id_;
164
165 // Provides querying and waking functionality for the component extension's
166 // suspend state.
167 extensions::EventPageTracker* event_page_tracker_;
168
169 // GUID of this object's instance.
170 // Used by the component extension to determine if its persistent cache
171 // is stale.
172 std::string instance_id_;
173
174 base::ThreadChecker thread_checker_;
175
176 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl);
177 };
178
179 } // namespace media_router
180
181 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_MOJO_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/media/router/media_router.gyp ('k') | chrome/browser/media/router/media_router_mojo_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698