• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2020 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #ifndef CEF_LIBCEF_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_IMPL_H_
6 #define CEF_LIBCEF_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_IMPL_H_
7 #pragma once
8 
9 #include "include/cef_media_router.h"
10 #include "libcef/browser/browser_context.h"
11 
12 #include "components/media_router/common/mojom/media_router.mojom.h"
13 
14 class CefRegistrationImpl;
15 
16 // Implementation of the CefMediaRouter interface. May be created on any thread.
17 class CefMediaRouterImpl : public CefMediaRouter {
18  public:
19   CefMediaRouterImpl();
20 
21   CefMediaRouterImpl(const CefMediaRouterImpl&) = delete;
22   CefMediaRouterImpl& operator=(const CefMediaRouterImpl&) = delete;
23 
24   // Called on the UI thread after object creation and before any other object
25   // methods are executed on the UI thread.
26   void Initialize(const CefBrowserContext::Getter& browser_context_getter,
27                   CefRefPtr<CefCompletionCallback> callback);
28 
29   // CefMediaRouter methods.
30   CefRefPtr<CefRegistration> AddObserver(
31       CefRefPtr<CefMediaObserver> observer) override;
32   CefRefPtr<CefMediaSource> GetSource(const CefString& urn) override;
33   void NotifyCurrentSinks() override;
34   void CreateRoute(CefRefPtr<CefMediaSource> source,
35                    CefRefPtr<CefMediaSink> sink,
36                    CefRefPtr<CefMediaRouteCreateCallback> callback) override;
37   void NotifyCurrentRoutes() override;
38 
39  private:
40   void InitializeRegistrationInternal(
41       CefRefPtr<CefRegistrationImpl> registration);
42   void NotifyCurrentSinksInternal();
43   void CreateRouteInternal(CefRefPtr<CefMediaSource> source,
44                            CefRefPtr<CefMediaSink> sink,
45                            CefRefPtr<CefMediaRouteCreateCallback> callback);
46   void NotifyCurrentRoutesInternal();
47 
48   void CreateRouteCallback(CefRefPtr<CefMediaRouteCreateCallback> callback,
49                            const media_router::RouteRequestResult& result);
50 
51   // If the context is fully initialized execute |callback|, otherwise
52   // store it until the context is fully initialized.
53   void StoreOrTriggerInitCallback(base::OnceClosure callback);
54 
55   bool ValidContext() const;
56 
57   // Only accessed on the UI thread. Will be non-null after Initialize().
58   CefBrowserContext::Getter browser_context_getter_;
59 
60   bool initialized_ = false;
61   std::vector<base::OnceClosure> init_callbacks_;
62 
63   IMPLEMENT_REFCOUNTING(CefMediaRouterImpl);
64 };
65 
66 #endif  // CEF_LIBCEF_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_IMPL_H_
67