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

Side by Side Diff: content/browser/browser_thread_impl.h

Issue 2464233002: Experiment with redirecting all BrowserThreads (but UI/IO) to TaskScheduler (Closed)
Patch Set: Add ResetGlobalsForTesting() and fix shutdown state in unittests Created 4 years, 1 month 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
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_BROWSER_BROWSER_THREAD_IMPL_H_ 5 #ifndef CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_
6 #define CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ 6 #define CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_
7 7
8 #include "base/threading/platform_thread.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/single_thread_task_runner.h"
9 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
10 #include "content/common/content_export.h" 11 #include "content/common/content_export.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 13
13 namespace content { 14 namespace content {
14 15
15 class CONTENT_EXPORT BrowserThreadImpl : public BrowserThread, 16 class CONTENT_EXPORT BrowserThreadImpl : public BrowserThread,
16 public base::Thread { 17 public base::Thread {
17 public: 18 public:
18 // Construct a BrowserThreadImpl with the supplied identifier. It is an error 19 // Construct a BrowserThreadImpl with the supplied identifier. It is an error
19 // to construct a BrowserThreadImpl that already exists. 20 // to construct a BrowserThreadImpl that already exists.
20 explicit BrowserThreadImpl(BrowserThread::ID identifier); 21 explicit BrowserThreadImpl(BrowserThread::ID identifier);
21 22
22 // Special constructor for the main (UI) thread and unittests. If a 23 // Special constructor for the main (UI) thread and unittests. If a
23 // |message_loop| is provied, we use a dummy thread here since the main 24 // |message_loop| is provied, we use a dummy thread here since the main
24 // thread already exists. 25 // thread already exists.
25 BrowserThreadImpl(BrowserThread::ID identifier, 26 BrowserThreadImpl(BrowserThread::ID identifier,
26 base::MessageLoop* message_loop); 27 base::MessageLoop* message_loop);
27 ~BrowserThreadImpl() override; 28 ~BrowserThreadImpl() override;
28 29
29 bool Start(); 30 // Redirects tasks posted to |identifier| to |task_runner|. |task_runner| may
30 bool StartWithOptions(const Options& options); 31 // be null to cancel the redirection and have |identifier| enter its
31 bool StartAndWaitForTesting(); 32 // "shutdown" phase.
33 static void RedirectThreadIDToTaskRunner(
34 BrowserThread::ID identifier,
35 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
32 36
33 static void ShutdownThreadPool(); 37 static void ShutdownThreadPool();
34 38
39 // Resets globals for |identifier|. Used in tests to clear global state that
40 // would otherwise leak to the next test. Globals are not otherwise fully
41 // cleaned up in ~BrowserThreadImpl() as there are subtle differences between
42 // UNINITIALIZED and SHUTDOWN state (e.g. globals.task_runners are kept around
43 // on shutdown). Must be called after ~BrowserThreadImpl() for the given
44 // |identifier|.
45 static void ResetGlobalsForTesting(BrowserThread::ID identifier);
46
35 protected: 47 protected:
36 void Init() override; 48 void Init() override;
37 void Run(base::RunLoop* run_loop) override; 49 void Run(base::RunLoop* run_loop) override;
38 void CleanUp() override; 50 void CleanUp() override;
39 51
40 private: 52 private:
41 // We implement all the functionality of the public BrowserThread 53 // We implement all the functionality of the public BrowserThread
42 // functions, but state is stored in the BrowserThreadImpl to keep 54 // functions, but state is stored in the BrowserThreadImpl to keep
43 // the API cleaner. Therefore make BrowserThread a friend class. 55 // the API cleaner. Therefore make BrowserThread a friend class.
44 friend class BrowserThread; 56 friend class BrowserThread;
(...skipping 24 matching lines...) Expand all
69 static void FlushThreadPoolHelperForTesting(); 81 static void FlushThreadPoolHelperForTesting();
70 82
71 // The identifier of this thread. Only one thread can exist with a given 83 // The identifier of this thread. Only one thread can exist with a given
72 // identifier at a given time. 84 // identifier at a given time.
73 ID identifier_; 85 ID identifier_;
74 }; 86 };
75 87
76 } // namespace content 88 } // namespace content
77 89
78 #endif // CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ 90 #endif // CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698