1 // Copyright 2019 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 ASH_PUBLIC_CPP_CAST_CONFIG_CONTROLLER_H_
6 #define ASH_PUBLIC_CPP_CAST_CONFIG_CONTROLLER_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "ash/public/cpp/ash_public_export.h"
12 #include "base/observer_list_types.h"
13 
14 namespace ash {
15 
16 // The type of icon the sink is associated with. These values match
17 // media_router::SinkIconType.
18 enum class SinkIconType {
19   kCast = 0,
20   kCastAudioGroup = 1,
21   kCastAudio = 2,
22   kMeeting = 3,
23   kHangout = 4,
24   kEducation = 5,
25   kWiredDisplay = 6,
26   kGeneric = 7,
27 };
28 
29 struct ASH_PUBLIC_EXPORT CastSink {
30   CastSink();
31   CastSink(const CastSink& other);
32 
33   std::string id;
34   std::string name;
35   std::string domain;
36 
37   // Icon which describes the type of sink media is being routed to.
38   SinkIconType sink_icon_type = SinkIconType::kGeneric;
39 };
40 
41 enum class ContentSource {
42   kUnknown,
43   kTab,
44   kDesktop,
45 };
46 
47 struct ASH_PUBLIC_EXPORT CastRoute {
48   std::string id;
49   std::string title;
50 
51   // Is the activity source this computer? ie, are we mirroring the display?
52   bool is_local_source = false;
53 
54   // What is source of the content? For example, we could be DIAL casting a
55   // tab or mirroring the entire desktop.
56   ContentSource content_source = ContentSource::kUnknown;
57 };
58 
59 struct ASH_PUBLIC_EXPORT SinkAndRoute {
60   SinkAndRoute();
61   SinkAndRoute(const SinkAndRoute& other);
62   SinkAndRoute(SinkAndRoute&& other);
63 
64   CastSink sink;
65   CastRoute route;
66 };
67 
68 // This interface allows the UI code in ash, e.g. |TrayCastDetailedView|, to
69 // access the cast system. This is implemented in Chrome and is expected to
70 // outlive ash::Shell.
71 class ASH_PUBLIC_EXPORT CastConfigController {
72  public:
73   class Observer : public base::CheckedObserver {
74    public:
75     virtual void OnDevicesUpdated(const std::vector<SinkAndRoute>& devices) = 0;
76 
77    protected:
78     ~Observer() override = default;
79   };
80 
81   // Returns the singleton instance, which may be null in unit tests.
82   static CastConfigController* Get();
83 
84   virtual void AddObserver(Observer* observer) = 0;
85   virtual void RemoveObserver(Observer* observer) = 0;
86 
87   // Return true if there are available cast devices.
88   virtual bool HasSinksAndRoutes() const = 0;
89 
90   // Return true if casting is active. The route may be DIAL based, such as
91   // casting YouTube where the cast sink directly streams content from another
92   // server. In that case, this device is not actively transmitting information
93   // to the cast sink.
94   virtual bool HasActiveRoute() const = 0;
95 
96   // Request fresh data from the backend. When the data is available, all
97   // registered observers will get called.
98   virtual void RequestDeviceRefresh() = 0;
99 
100   virtual const std::vector<SinkAndRoute>& GetSinksAndRoutes() = 0;
101 
102   // Initiate a casting session to the sink identified by |sink_id|.
103   virtual void CastToSink(const std::string& sink_id) = 0;
104 
105   // A user-initiated request to stop the given cast session.
106   virtual void StopCasting(const std::string& route_id) = 0;
107 
108  protected:
109   CastConfigController();
110   virtual ~CastConfigController();
111 };
112 
113 }  // namespace ash
114 
115 #endif  // ASH_PUBLIC_CPP_CAST_CONFIG_CONTROLLER_H_
116