• 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   // Called on the UI thread after object creation and before any other object
22   // methods are executed on the UI thread.
23   void Initialize(const CefBrowserContext::Getter& browser_context_getter,
24                   CefRefPtr<CefCompletionCallback> callback);
25 
26   // CefMediaRouter methods.
27   CefRefPtr<CefRegistration> AddObserver(
28       CefRefPtr<CefMediaObserver> observer) override;
29   CefRefPtr<CefMediaSource> GetSource(const CefString& urn) override;
30   void NotifyCurrentSinks() override;
31   void CreateRoute(CefRefPtr<CefMediaSource> source,
32                    CefRefPtr<CefMediaSink> sink,
33                    CefRefPtr<CefMediaRouteCreateCallback> callback) override;
34   void NotifyCurrentRoutes() override;
35 
36  private:
37   void InitializeRegistrationInternal(
38       CefRefPtr<CefRegistrationImpl> registration);
39   void NotifyCurrentSinksInternal();
40   void CreateRouteInternal(CefRefPtr<CefMediaSource> source,
41                            CefRefPtr<CefMediaSink> sink,
42                            CefRefPtr<CefMediaRouteCreateCallback> callback);
43   void NotifyCurrentRoutesInternal();
44 
45   void CreateRouteCallback(CefRefPtr<CefMediaRouteCreateCallback> callback,
46                            const media_router::RouteRequestResult& result);
47 
48   // If the context is fully initialized execute |callback|, otherwise
49   // store it until the context is fully initialized.
50   void StoreOrTriggerInitCallback(base::OnceClosure callback);
51 
52   bool ValidContext() const;
53 
54   // Only accessed on the UI thread. Will be non-null after Initialize().
55   CefBrowserContext::Getter browser_context_getter_;
56 
57   bool initialized_ = false;
58   std::vector<base::OnceClosure> init_callbacks_;
59 
60   IMPLEMENT_REFCOUNTING(CefMediaRouterImpl);
61   DISALLOW_COPY_AND_ASSIGN(CefMediaRouterImpl);
62 };
63 
64 #endif  // CEF_LIBCEF_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_IMPL_H_
65