Chromium Code Reviews| 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 QueueElement = std::pair<std::string, ToastData>; | |
|
oshima
2016/05/16 22:37:25
toast data has id. Any particular reason to have a
yoshiki
2016/05/17 06:25:21
Done.
| |
| 39 using Queue = std::list<QueueElement>; | |
| 35 | 40 |
| 36 void ShowLatest(); | 41 void ShowLatest(); |
| 37 void OnDurationPassed(int toast_id); | 42 void OnDurationPassed(int toast_number); |
| 38 | 43 |
| 39 int toast_id_for_testing() const { return toast_id_; } | |
| 40 ToastOverlay* GetCurrentOverlayForTesting() { return overlay_.get(); } | 44 ToastOverlay* GetCurrentOverlayForTesting() { return overlay_.get(); } |
| 41 void ResetToastIdForTesting() { toast_id_ = 0; } | 45 int serial_for_testing() const { return serial_; } |
| 46 void ResetSerialForTesting() { serial_ = 0; } | |
| 42 | 47 |
| 43 int toast_id_ = 0; | 48 std::string toast_id_; |
|
dcheng
2016/05/17 02:57:25
Add a comment what this is: ID of the currently di
yoshiki
2016/05/17 06:25:21
Done.
| |
| 44 std::queue<std::pair<std::string, uint64_t>> queue_; | 49 int serial_ = 0; |
| 50 Queue 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 |