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; |
38 using Queue = std::list<ToastData>; | |
oshima
2016/05/18 16:59:44
std::vector is usually faster:
http://baptiste-wi
yoshiki
2016/05/19 09:14:12
Thank you for giving information. I use vector.
yoshiki
2016/05/20 06:57:30
Let me use std::list, since the vector doesn't hav
| |
35 | 39 |
36 void ShowLatest(); | 40 void ShowLatest(); |
37 void OnDurationPassed(int toast_id); | 41 void OnDurationPassed(int toast_number); |
38 | 42 |
39 int toast_id_for_testing() const { return toast_id_; } | |
40 ToastOverlay* GetCurrentOverlayForTesting() { return overlay_.get(); } | 43 ToastOverlay* GetCurrentOverlayForTesting() { return overlay_.get(); } |
41 void ResetToastIdForTesting() { toast_id_ = 0; } | 44 int serial_for_testing() const { return serial_; } |
45 void ResetSerialForTesting() { serial_ = 0; } | |
42 | 46 |
43 int toast_id_ = 0; | 47 // ID of the toast which is currently shown. Empty if no toast is visible. |
44 std::queue<std::pair<std::string, uint64_t>> queue_; | 48 std::string current_toast_id_; |
49 | |
50 int serial_ = 0; | |
51 Queue queue_; | |
45 std::unique_ptr<ToastOverlay> overlay_; | 52 std::unique_ptr<ToastOverlay> overlay_; |
46 | 53 |
47 base::WeakPtrFactory<ToastManager> weak_ptr_factory_; | 54 base::WeakPtrFactory<ToastManager> weak_ptr_factory_; |
48 | 55 |
49 DISALLOW_COPY_AND_ASSIGN(ToastManager); | 56 DISALLOW_COPY_AND_ASSIGN(ToastManager); |
50 }; | 57 }; |
51 | 58 |
52 } // namespace ash | 59 } // namespace ash |
53 | 60 |
54 #endif // ASH_SYSTEM_TOAST_TOAST_MANAGER_H_ | 61 #endif // ASH_SYSTEM_TOAST_TOAST_MANAGER_H_ |
OLD | NEW |