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 #include "ash/system/toast/toast_manager.h" | 5 #include "ash/system/toast/toast_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 | 10 |
11 namespace ash { | 11 namespace ash { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Minimum duration for a toast to be visible (in millisecond). | 15 // Minimum duration for a toast to be visible (in millisecond). |
16 uint64_t kMinimumDurationMs = 200; | 16 int32_t kMinimumDurationMs = 200; |
17 | 17 |
18 } // anonymous namespace | 18 } // anonymous namespace |
19 | 19 |
20 ToastManager::ToastManager() : weak_ptr_factory_(this) {} | 20 ToastManager::ToastManager() : weak_ptr_factory_(this) {} |
21 | 21 |
22 ToastManager::~ToastManager() {} | 22 ToastManager::~ToastManager() {} |
23 | 23 |
24 void ToastManager::Show(const ToastData& data) { | 24 void ToastManager::Show(const ToastData& data) { |
25 const std::string& id = data.id; | 25 const std::string& id = data.id; |
26 DCHECK(!id.empty()); | 26 DCHECK(!id.empty()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 if (!queue_.empty()) | 65 if (!queue_.empty()) |
66 ShowLatest(); | 66 ShowLatest(); |
67 } | 67 } |
68 | 68 |
69 void ToastManager::ShowLatest() { | 69 void ToastManager::ShowLatest() { |
70 DCHECK(!overlay_); | 70 DCHECK(!overlay_); |
71 | 71 |
72 const ToastData data = std::move(queue_.front()); | 72 const ToastData data = std::move(queue_.front()); |
73 queue_.pop_front(); | 73 queue_.pop_front(); |
74 | 74 |
75 uint64_t duration_ms = std::max(data.duration_ms, kMinimumDurationMs); | 75 int32_t duration_ms = std::max(data.duration_ms, kMinimumDurationMs); |
76 | 76 |
77 current_toast_id_ = data.id; | 77 current_toast_id_ = data.id; |
78 serial_++; | 78 serial_++; |
79 | 79 |
80 overlay_.reset(new ToastOverlay(this, data.text)); | 80 overlay_.reset(new ToastOverlay(this, data.text)); |
81 overlay_->Show(true); | 81 overlay_->Show(true); |
82 | 82 |
83 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 83 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
84 FROM_HERE, base::Bind(&ToastManager::OnDurationPassed, | 84 FROM_HERE, base::Bind(&ToastManager::OnDurationPassed, |
85 weak_ptr_factory_.GetWeakPtr(), serial_), | 85 weak_ptr_factory_.GetWeakPtr(), serial_), |
86 base::TimeDelta::FromMilliseconds(duration_ms)); | 86 base::TimeDelta::FromMilliseconds(duration_ms)); |
87 } | 87 } |
88 | 88 |
89 void ToastManager::OnDurationPassed(int toast_number) { | 89 void ToastManager::OnDurationPassed(int toast_number) { |
90 if (overlay_ && serial_ == toast_number) | 90 if (overlay_ && serial_ == toast_number) |
91 overlay_->Show(false); | 91 overlay_->Show(false); |
92 } | 92 } |
93 | 93 |
94 } // namespace ash | 94 } // namespace ash |
OLD | NEW |