OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_SYSTEM_CAST_TRAY_CAST_H_ | 5 #ifndef ASH_SYSTEM_CAST_TRAY_CAST_H_ |
6 #define ASH_SYSTEM_CAST_TRAY_CAST_H_ | 6 #define ASH_SYSTEM_CAST_TRAY_CAST_H_ |
7 | 7 |
8 #include "ash/cast_config_delegate.h" | 8 #include "ash/cast_config_delegate.h" |
9 #include "ash/shell_observer.h" | 9 #include "ash/shell_observer.h" |
10 #include "ash/system/tray/system_tray_item.h" | 10 #include "ash/system/tray/system_tray_item.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | |
13 | 12 |
14 namespace ash { | 13 namespace ash { |
15 namespace tray { | 14 namespace tray { |
16 class CastTrayView; | 15 class CastTrayView; |
17 class CastSelectDefaultView; | 16 class CastSelectDefaultView; |
18 class CastDetailedView; | 17 class CastDetailedView; |
19 class CastDuplexView; | 18 class CastDuplexView; |
20 } // namespace tray | 19 } // namespace tray |
21 | 20 |
22 class ASH_EXPORT TrayCast : public SystemTrayItem, public ShellObserver { | 21 class ASH_EXPORT TrayCast : public SystemTrayItem, |
| 22 public ShellObserver, |
| 23 public CastConfigDelegate::Observer { |
23 public: | 24 public: |
24 explicit TrayCast(SystemTray* system_tray); | 25 explicit TrayCast(SystemTray* system_tray); |
25 ~TrayCast() override; | 26 ~TrayCast() override; |
26 | 27 |
27 private: | 28 private: |
28 // Helper/utility methods for testing. | 29 // Helper/utility methods for testing. |
29 friend class TrayCastTestAPI; | 30 friend class TrayCastTestAPI; |
30 void StartCastForTest(const std::string& receiver_id); | 31 void StartCastForTest(const std::string& receiver_id); |
31 void StopCastForTest(); | 32 void StopCastForTest(); |
32 // Returns the id of the item we are currently displaying in the cast view. | 33 // Returns the id of the item we are currently displaying in the cast view. |
33 // This assumes that the cast view is active. | 34 // This assumes that the cast view is active. |
34 const std::string& GetDisplayedCastId(); | 35 const std::string& GetDisplayedCastId(); |
35 const views::View* GetDefaultView() const; | 36 const views::View* GetDefaultView() const; |
36 enum ChildViewId { TRAY_VIEW = 1, SELECT_VIEW, CAST_VIEW }; | 37 enum ChildViewId { TRAY_VIEW = 1, SELECT_VIEW, CAST_VIEW }; |
37 | 38 |
38 // Overridden from SystemTrayItem. | 39 // Overridden from SystemTrayItem. |
39 views::View* CreateTrayView(user::LoginStatus status) override; | 40 views::View* CreateTrayView(user::LoginStatus status) override; |
40 views::View* CreateDefaultView(user::LoginStatus status) override; | 41 views::View* CreateDefaultView(user::LoginStatus status) override; |
41 views::View* CreateDetailedView(user::LoginStatus status) override; | 42 views::View* CreateDetailedView(user::LoginStatus status) override; |
42 void DestroyTrayView() override; | 43 void DestroyTrayView() override; |
43 void DestroyDefaultView() override; | 44 void DestroyDefaultView() override; |
44 void DestroyDetailedView() override; | 45 void DestroyDetailedView() override; |
45 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) override; | 46 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) override; |
46 | 47 |
47 // Overridden from ShellObserver. | 48 // Overridden from ShellObserver. |
48 void OnCastingSessionStartedOrStopped(bool started) override; | 49 void OnCastingSessionStartedOrStopped(bool started) override; |
49 | 50 |
| 51 // Overridden from CastConfigDelegate::Observer. |
| 52 void OnDevicesUpdated( |
| 53 const CastConfigDelegate::ReceiversAndActivities& devices) override; |
| 54 |
50 // Returns true if the cast extension was detected. | 55 // Returns true if the cast extension was detected. |
51 bool HasCastExtension(); | 56 bool HasCastExtension(); |
52 | 57 |
53 // Callback used to enable/disable the begin casting view depending on | |
54 // if we have any cast receivers. | |
55 void OnReceiversUpdated( | |
56 const CastConfigDelegate::ReceiversAndActivities& receivers_activities); | |
57 | |
58 // This makes sure that the current view displayed in the tray is the correct | 58 // This makes sure that the current view displayed in the tray is the correct |
59 // one, depending on if we are currently casting. If we're casting, then a | 59 // one, depending on if we are currently casting. If we're casting, then a |
60 // view with a stop button is displayed; otherwise, a view that links to a | 60 // view with a stop button is displayed; otherwise, a view that links to a |
61 // detail view is displayed instead that allows the user to easily begin a | 61 // detail view is displayed instead that allows the user to easily begin a |
62 // casting session. | 62 // casting session. |
63 void UpdatePrimaryView(); | 63 void UpdatePrimaryView(); |
64 | 64 |
65 CastConfigDelegate::ReceiversAndActivities receivers_and_activities_; | 65 CastConfigDelegate::ReceiversAndActivities receivers_and_activities_; |
66 CastConfigDelegate::DeviceUpdateSubscription device_update_subscription_; | |
67 bool is_casting_ = false; | 66 bool is_casting_ = false; |
68 | 67 |
| 68 bool added_observer_ = false; |
| 69 |
69 // Not owned. | 70 // Not owned. |
70 tray::CastTrayView* tray_ = nullptr; | 71 tray::CastTrayView* tray_ = nullptr; |
71 tray::CastDuplexView* default_ = nullptr; | 72 tray::CastDuplexView* default_ = nullptr; |
72 tray::CastDetailedView* detailed_ = nullptr; | 73 tray::CastDetailedView* detailed_ = nullptr; |
73 | 74 |
74 base::WeakPtrFactory<TrayCast> weak_ptr_factory_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(TrayCast); | 75 DISALLOW_COPY_AND_ASSIGN(TrayCast); |
77 }; | 76 }; |
78 | 77 |
79 } // namespace ash | 78 } // namespace ash |
80 | 79 |
81 #endif // ASH_SYSTEM_CAST_TRAY_CAST_H_ | 80 #endif // ASH_SYSTEM_CAST_TRAY_CAST_H_ |
OLD | NEW |