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

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: rm TODO Created 4 years 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 // Very few users should use this directly. To mock BrowserThreads, tests should 16 // Very few users should use this directly. To mock BrowserThreads, tests should
16 // use TestBrowserThreadBundle instead. 17 // use TestBrowserThreadBundle instead.
17 class CONTENT_EXPORT BrowserThreadImpl : public BrowserThread, 18 class CONTENT_EXPORT BrowserThreadImpl : public BrowserThread,
18 public base::Thread { 19 public base::Thread {
19 public: 20 public:
20 // Construct a BrowserThreadImpl with the supplied identifier. It is an error 21 // Construct a BrowserThreadImpl with the supplied identifier. It is an error
21 // to construct a BrowserThreadImpl that already exists. 22 // to construct a BrowserThreadImpl that already exists.
22 explicit BrowserThreadImpl(BrowserThread::ID identifier); 23 explicit BrowserThreadImpl(BrowserThread::ID identifier);
23 24
24 // Special constructor for the main (UI) thread and unittests. If a 25 // Special constructor for the main (UI) thread and unittests. If a
25 // |message_loop| is provied, we use a dummy thread here since the main 26 // |message_loop| is provied, we use a dummy thread here since the main
26 // thread already exists. 27 // thread already exists.
27 BrowserThreadImpl(BrowserThread::ID identifier, 28 BrowserThreadImpl(BrowserThread::ID identifier,
28 base::MessageLoop* message_loop); 29 base::MessageLoop* message_loop);
29 ~BrowserThreadImpl() override; 30 ~BrowserThreadImpl() override;
30 31
31 bool Start(); 32 bool Start();
32 bool StartWithOptions(const Options& options); 33 bool StartWithOptions(const Options& options);
33 bool StartAndWaitForTesting(); 34 bool StartAndWaitForTesting();
34 35
36 // Redirects tasks posted to |identifier| to |task_runner|. |task_runner| may
37 // be null to cancel the redirection and have |identifier| enter its
38 // "shutdown" phase.
39 static void RedirectThreadIDToTaskRunner(
40 BrowserThread::ID identifier,
41 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
42
35 static void ShutdownThreadPool(); 43 static void ShutdownThreadPool();
36 44
45 // Resets globals for |identifier|. Used in tests to clear global state that
46 // would otherwise leak to the next test. Globals are not otherwise fully
47 // cleaned up in ~BrowserThreadImpl() as there are subtle differences between
48 // UNINITIALIZED and SHUTDOWN state (e.g. globals.task_runners are kept around
49 // on shutdown). Must be called after ~BrowserThreadImpl() for the given
50 // |identifier|.
51 static void ResetGlobalsForTesting(BrowserThread::ID identifier);
52
37 protected: 53 protected:
38 void Init() override; 54 void Init() override;
39 void Run(base::RunLoop* run_loop) override; 55 void Run(base::RunLoop* run_loop) override;
40 void CleanUp() override; 56 void CleanUp() override;
41 57
42 private: 58 private:
43 // We implement all the functionality of the public BrowserThread 59 // We implement all the functionality of the public BrowserThread
44 // functions, but state is stored in the BrowserThreadImpl to keep 60 // functions, but state is stored in the BrowserThreadImpl to keep
45 // the API cleaner. Therefore make BrowserThread a friend class. 61 // the API cleaner. Therefore make BrowserThread a friend class.
46 friend class BrowserThread; 62 friend class BrowserThread;
(...skipping 24 matching lines...) Expand all
71 static void FlushThreadPoolHelperForTesting(); 87 static void FlushThreadPoolHelperForTesting();
72 88
73 // The identifier of this thread. Only one thread can exist with a given 89 // The identifier of this thread. Only one thread can exist with a given
74 // identifier at a given time. 90 // identifier at a given time.
75 ID identifier_; 91 ID identifier_;
76 }; 92 };
77 93
78 } // namespace content 94 } // namespace content
79 95
80 #endif // CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ 96 #endif // CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698