Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: content/public/test/test_utils.h

Issue 2686873003: Make MessageLoopRunner be RefCountedThreadSafe (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CONTENT_PUBLIC_TEST_TEST_UTILS_H_ 5 #ifndef CONTENT_PUBLIC_TEST_TEST_UTILS_H_
6 #define CONTENT_PUBLIC_TEST_TEST_UTILS_H_ 6 #define CONTENT_PUBLIC_TEST_TEST_UTILS_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // once per instance. Make a new instance for each use. Calling Quit after Run 93 // once per instance. Make a new instance for each use. Calling Quit after Run
94 // has returned is safe and has no effect. 94 // has returned is safe and has no effect.
95 // Note that by default Quit does not quit immediately. If that is not what you 95 // Note that by default Quit does not quit immediately. If that is not what you
96 // really need, pass QuitMode::IMMEDIATE in the constructor. 96 // really need, pass QuitMode::IMMEDIATE in the constructor.
97 // 97 //
98 // DEPRECATED. Consider using base::RunLoop, in most cases MessageLoopRunner is 98 // DEPRECATED. Consider using base::RunLoop, in most cases MessageLoopRunner is
99 // not needed. If you need to defer quitting the loop, use 99 // not needed. If you need to defer quitting the loop, use
100 // GetDeferredQuitTaskForRunLoop directly. 100 // GetDeferredQuitTaskForRunLoop directly.
101 // If you found a case where base::RunLoop is inconvenient or can not be used at 101 // If you found a case where base::RunLoop is inconvenient or can not be used at
102 // all, please post details in a comment on https://crbug.com/668707. 102 // all, please post details in a comment on https://crbug.com/668707.
103 class MessageLoopRunner : public base::RefCounted<MessageLoopRunner> { 103 class MessageLoopRunner : public base::RefCountedThreadSafe<MessageLoopRunner> {
104 public: 104 public:
105 enum class QuitMode { 105 enum class QuitMode {
106 // Message loop stops after finishing the current task. 106 // Message loop stops after finishing the current task.
107 IMMEDIATE, 107 IMMEDIATE,
108 108
109 // Several generations of posted tasks are executed before stopping. 109 // Several generations of posted tasks are executed before stopping.
110 DEFERRED, 110 DEFERRED,
111 }; 111 };
112 112
113 MessageLoopRunner(QuitMode mode = QuitMode::DEFERRED); 113 MessageLoopRunner(QuitMode mode = QuitMode::DEFERRED);
114 114
115 // Run the current MessageLoop unless the quit closure 115 // Run the current MessageLoop unless the quit closure
116 // has already been called. 116 // has already been called.
117 void Run(); 117 void Run();
118 118
119 // Quit the matching call to Run (nested MessageLoops are unaffected). 119 // Quit the matching call to Run (nested MessageLoops are unaffected).
120 void Quit(); 120 void Quit();
121 121
122 // Hand this closure off to code that uses callbacks to notify completion. 122 // Hand this closure off to code that uses callbacks to notify completion.
123 // Example: 123 // Example:
124 // scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; 124 // scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner;
125 // kick_off_some_api(runner->QuitClosure()); 125 // kick_off_some_api(runner->QuitClosure());
126 // runner->Run(); 126 // runner->Run();
127 base::Closure QuitClosure(); 127 base::Closure QuitClosure();
128 128
129 bool loop_running() const { return loop_running_; } 129 bool loop_running() const { return loop_running_; }
130 130
131 private: 131 private:
132 friend class base::RefCounted<MessageLoopRunner>; 132 friend class base::RefCountedThreadSafe<MessageLoopRunner>;
133 ~MessageLoopRunner(); 133 ~MessageLoopRunner();
134 134
135 QuitMode quit_mode_; 135 QuitMode quit_mode_;
136 136
137 // True when the message loop is running. 137 // True when the message loop is running.
138 bool loop_running_; 138 bool loop_running_;
139 139
140 // True after closure returned by |QuitClosure| has been called. 140 // True after closure returned by |QuitClosure| has been called.
141 bool quit_closure_called_; 141 bool quit_closure_called_;
142 142
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 void WebContentsDestroyed() override; 304 void WebContentsDestroyed() override;
305 305
306 base::RunLoop run_loop_; 306 base::RunLoop run_loop_;
307 307
308 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); 308 DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher);
309 }; 309 };
310 310
311 } // namespace content 311 } // namespace content
312 312
313 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ 313 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698