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 UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_ | 5 #ifndef UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_ |
6 #define UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_ | 6 #define UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_ |
7 | 7 |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 class ACCELERATED_WIDGET_MAC_EXPORT WindowResizeHelperMac { | 46 class ACCELERATED_WIDGET_MAC_EXPORT WindowResizeHelperMac { |
47 public: | 47 public: |
48 static WindowResizeHelperMac* Get(); | 48 static WindowResizeHelperMac* Get(); |
49 | 49 |
50 // Initializes the pumpable task_runner(), providing it with the task runner | 50 // Initializes the pumpable task_runner(), providing it with the task runner |
51 // for UI thread tasks. task_runner() will be null before Init() is called, | 51 // for UI thread tasks. task_runner() will be null before Init() is called, |
52 // and WaitForSingleTaskToRun() will immediately return false. | 52 // and WaitForSingleTaskToRun() will immediately return false. |
53 void Init( | 53 void Init( |
54 const scoped_refptr<base::SingleThreadTaskRunner>& target_task_runner); | 54 const scoped_refptr<base::SingleThreadTaskRunner>& target_task_runner); |
55 | 55 |
56 // Because this class is global, many tests may want to do this setup | |
57 // repeatedly, so need some way to uninitialize as well. | |
58 void ShutdownForTests(); | |
59 | |
60 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const; | 56 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const; |
61 | 57 |
62 // UI THREAD ONLY ----------------------------------------------------------- | 58 // UI THREAD ONLY ----------------------------------------------------------- |
63 | 59 |
64 // Waits at most |max_delay| for a task to run. Returns true if a task ran, | 60 // Waits at most |max_delay| for a task to run. Returns true if a task ran, |
65 // false if no task ran. | 61 // false if no task ran. |
66 bool WaitForSingleTaskToRun(const base::TimeDelta& max_delay); | 62 bool WaitForSingleTaskToRun(const base::TimeDelta& max_delay); |
67 | 63 |
68 private: | 64 private: |
69 friend struct base::DefaultLazyInstanceTraits<WindowResizeHelperMac>; | 65 friend struct base::DefaultLazyInstanceTraits<WindowResizeHelperMac>; |
70 WindowResizeHelperMac(); | 66 WindowResizeHelperMac(); |
71 ~WindowResizeHelperMac(); | 67 ~WindowResizeHelperMac(); |
72 | 68 |
73 // This helper is needed to create a ScopedAllowWait inside the scope of a | 69 // This helper is needed to create a ScopedAllowWait inside the scope of a |
74 // class where it is allowed. | 70 // class where it is allowed. |
75 static void EventTimedWait(base::WaitableEvent* event, base::TimeDelta delay); | 71 static void EventTimedWait(base::WaitableEvent* event, base::TimeDelta delay); |
76 | 72 |
77 // The task runner to which the helper will post tasks. This also maintains | 73 // The task runner to which the helper will post tasks. This also maintains |
78 // the task queue and does the actual work for WaitForSingleTaskToRun. | 74 // the task queue and does the actual work for WaitForSingleTaskToRun. |
79 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 75 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
80 | 76 |
81 DISALLOW_COPY_AND_ASSIGN(WindowResizeHelperMac); | 77 DISALLOW_COPY_AND_ASSIGN(WindowResizeHelperMac); |
82 }; | 78 }; |
83 | 79 |
84 } // namespace ui | 80 } // namespace ui |
85 | 81 |
86 #endif // UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_ | 82 #endif // UI_ACCELERATED_WIDGET_MAC_WINDOW_RESIZE_HELPER_MAC_H_ |
OLD | NEW |