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 CHROME_BROWSER_UI_GLOBAL_MEDIA_CONTROLS_CAST_MEDIA_NOTIFICATION_PROVIDER_H_
6 #define CHROME_BROWSER_UI_GLOBAL_MEDIA_CONTROLS_CAST_MEDIA_NOTIFICATION_PROVIDER_H_
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 #include "base/callback_forward.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/ui/global_media_controls/cast_media_notification_item.h"
15 #include "components/media_router/browser/media_routes_observer.h"
16 
17 class Profile;
18 
19 namespace media_message_center {
20 class MediaNotificationController;
21 }  // namespace media_message_center
22 
23 // Manages media notifications shown in the Global Media Controls dialog for
24 // active Cast sessions.
25 class CastMediaNotificationProvider : public media_router::MediaRoutesObserver {
26  public:
27   CastMediaNotificationProvider(
28       Profile* profile,
29       media_message_center::MediaNotificationController*
30           notification_controller,
31       base::RepeatingClosure items_changed_callback);
32   CastMediaNotificationProvider(
33       Profile* profile,
34       media_router::MediaRouter* router,
35       media_message_center::MediaNotificationController*
36           notification_controller,
37       base::RepeatingClosure items_changed_callback_);
38   CastMediaNotificationProvider(const CastMediaNotificationProvider&) = delete;
39   CastMediaNotificationProvider& operator=(
40       const CastMediaNotificationProvider&) = delete;
41   ~CastMediaNotificationProvider() override;
42 
43   // media_router::MediaRoutesObserver:
44   void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes,
45                        const std::vector<media_router::MediaRoute::Id>&
46                            joinable_route_ids) override;
47 
48   base::WeakPtr<media_message_center::MediaNotificationItem>
49   GetNotificationItem(const std::string& id);
50 
51   virtual bool HasItems() const;
52   size_t GetItemCount() const;
53 
54  private:
55   Profile* const profile_;
56   media_router::MediaRouter* const router_;
57   media_message_center::MediaNotificationController* const
58       notification_controller_;
59 
60   // Maps from notification item IDs to items.
61   std::map<std::string, CastMediaNotificationItem> items_;
62 
63   // Called when the number of items changes from zero to positive or vice
64   // versa.
65   base::RepeatingClosure items_changed_callback_;
66 };
67 
68 #endif  // CHROME_BROWSER_UI_GLOBAL_MEDIA_CONTROLS_CAST_MEDIA_NOTIFICATION_PROVIDER_H_
69