OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_TOAST_TOAST_MANAGER_H_ | 5 #ifndef ASH_SYSTEM_TOAST_TOAST_MANAGER_H_ |
6 #define ASH_SYSTEM_TOAST_TOAST_MANAGER_H_ | 6 #define ASH_SYSTEM_TOAST_TOAST_MANAGER_H_ |
7 | 7 |
| 8 #include <list> |
8 #include <memory> | 9 #include <memory> |
9 #include <queue> | |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "ash/ash_export.h" | 12 #include "ash/ash_export.h" |
13 #include "ash/shell_observer.h" | 13 #include "ash/shell_observer.h" |
| 14 #include "ash/system/toast/toast_data.h" |
14 #include "ash/system/toast/toast_overlay.h" | 15 #include "ash/system/toast/toast_overlay.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
17 | 18 |
18 namespace ash { | 19 namespace ash { |
19 | 20 |
20 // Class managing toast requests. | 21 // Class managing toast requests. |
21 class ASH_EXPORT ToastManager : public ToastOverlay::Delegate { | 22 class ASH_EXPORT ToastManager : public ToastOverlay::Delegate { |
22 public: | 23 public: |
23 ToastManager(); | 24 ToastManager(); |
24 ~ToastManager() override; | 25 ~ToastManager() override; |
25 | 26 |
26 // Show a toast. If there are queued toasts, succeeding toasts are queued as | 27 // Show a toast. If there are queued toasts, succeeding toasts are queued as |
27 // well, and are shown one by one. | 28 // well, and are shown one by one. |
28 void Show(const std::string& text, uint64_t duration_ms); | 29 void Show(const ToastData& data); |
| 30 |
| 31 void Cancel(const std::string& id); |
29 | 32 |
30 // ToastOverlay::Delegate overrides: | 33 // ToastOverlay::Delegate overrides: |
31 void OnClosed() override; | 34 void OnClosed() override; |
32 | 35 |
33 private: | 36 private: |
34 friend class ToastManagerTest; | 37 friend class ToastManagerTest; |
35 | 38 |
36 void ShowLatest(); | 39 void ShowLatest(); |
37 void OnDurationPassed(int toast_id); | 40 void OnDurationPassed(int toast_number); |
38 | 41 |
39 int toast_id_for_testing() const { return toast_id_; } | |
40 ToastOverlay* GetCurrentOverlayForTesting() { return overlay_.get(); } | 42 ToastOverlay* GetCurrentOverlayForTesting() { return overlay_.get(); } |
41 void ResetToastIdForTesting() { toast_id_ = 0; } | 43 int serial_for_testing() const { return serial_; } |
| 44 void ResetSerialForTesting() { serial_ = 0; } |
42 | 45 |
43 int toast_id_ = 0; | 46 // ID of the toast which is currently shown. Empty if no toast is visible. |
44 std::queue<std::pair<std::string, uint64_t>> queue_; | 47 std::string current_toast_id_; |
| 48 |
| 49 int serial_ = 0; |
| 50 std::list<ToastData> queue_; |
45 std::unique_ptr<ToastOverlay> overlay_; | 51 std::unique_ptr<ToastOverlay> overlay_; |
46 | 52 |
47 base::WeakPtrFactory<ToastManager> weak_ptr_factory_; | 53 base::WeakPtrFactory<ToastManager> weak_ptr_factory_; |
48 | 54 |
49 DISALLOW_COPY_AND_ASSIGN(ToastManager); | 55 DISALLOW_COPY_AND_ASSIGN(ToastManager); |
50 }; | 56 }; |
51 | 57 |
52 } // namespace ash | 58 } // namespace ash |
53 | 59 |
54 #endif // ASH_SYSTEM_TOAST_TOAST_MANAGER_H_ | 60 #endif // ASH_SYSTEM_TOAST_TOAST_MANAGER_H_ |
OLD | NEW |