| OLD | NEW |
| 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 |
| 35 protected: | 39 protected: |
| 36 void Init() override; | 40 void Init() override; |
| 37 void Run(base::RunLoop* run_loop) override; | 41 void Run(base::RunLoop* run_loop) override; |
| 38 void CleanUp() override; | 42 void CleanUp() override; |
| 39 | 43 |
| 40 private: | 44 private: |
| 41 // We implement all the functionality of the public BrowserThread | 45 // We implement all the functionality of the public BrowserThread |
| (...skipping 27 matching lines...) Expand all Loading... |
| 69 static void FlushThreadPoolHelperForTesting(); | 73 static void FlushThreadPoolHelperForTesting(); |
| 70 | 74 |
| 71 // The identifier of this thread. Only one thread can exist with a given | 75 // The identifier of this thread. Only one thread can exist with a given |
| 72 // identifier at a given time. | 76 // identifier at a given time. |
| 73 ID identifier_; | 77 ID identifier_; |
| 74 }; | 78 }; |
| 75 | 79 |
| 76 } // namespace content | 80 } // namespace content |
| 77 | 81 |
| 78 #endif // CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ | 82 #endif // CONTENT_BROWSER_BROWSER_THREAD_IMPL_H_ |
| OLD | NEW |