| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 IOS_WEB_WEB_THREAD_IMPL_H_ | 5 #ifndef IOS_WEB_WEB_THREAD_IMPL_H_ |
| 6 #define IOS_WEB_WEB_THREAD_IMPL_H_ | 6 #define IOS_WEB_WEB_THREAD_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "ios/web/public/web_thread.h" | 9 #include "ios/web/public/web_thread.h" |
| 10 | 10 |
| 11 namespace web { | 11 namespace web { |
| 12 | 12 |
| 13 class WebThreadDelegate; | 13 class WebTestSuiteListener; |
| 14 | 14 |
| 15 class WebThreadImpl : public WebThread, public base::Thread { | 15 class WebThreadImpl : public WebThread, public base::Thread { |
| 16 public: | 16 public: |
| 17 // Construct a WebThreadImpl with the supplied identifier. It is an error | 17 // Construct a WebThreadImpl with the supplied identifier. It is an error |
| 18 // to construct a WebThreadImpl that already exists. | 18 // to construct a WebThreadImpl that already exists. |
| 19 explicit WebThreadImpl(WebThread::ID identifier); | 19 explicit WebThreadImpl(WebThread::ID identifier); |
| 20 | 20 |
| 21 // Special constructor for the main (UI) thread and unittests. If a | 21 // Special constructor for the main (UI) thread and unittests. If a |
| 22 // |message_loop| is provied, we use a dummy thread here since the main | 22 // |message_loop| is provied, we use a dummy thread here since the main |
| 23 // thread already exists. | 23 // thread already exists. |
| 24 WebThreadImpl(WebThread::ID identifier, base::MessageLoop* message_loop); | 24 WebThreadImpl(WebThread::ID identifier, base::MessageLoop* message_loop); |
| 25 ~WebThreadImpl() override; | 25 ~WebThreadImpl() override; |
| 26 | 26 |
| 27 static void ShutdownThreadPool(); | 27 static void ShutdownThreadPool(); |
| 28 | 28 |
| 29 // TODO(stuartmorgan): Move this to WebThread (where it belongs) once | |
| 30 // the alternate BrowserThread-backed-WebThread implementation goes away. See | |
| 31 // the note in web_thread_delegate.h. | |
| 32 // | |
| 33 // Sets the delegate for the specified WebThread. | |
| 34 // | |
| 35 // Only one delegate may be registered at a time. Delegates may be | |
| 36 // unregistered by providing a nullptr pointer. | |
| 37 // | |
| 38 // If the caller unregisters a delegate before CleanUp has been | |
| 39 // called, it must perform its own locking to ensure the delegate is | |
| 40 // not deleted while unregistering. | |
| 41 static void SetDelegate(ID identifier, WebThreadDelegate* delegate); | |
| 42 | |
| 43 protected: | 29 protected: |
| 44 void Init() override; | 30 void Init() override; |
| 45 void Run(base::MessageLoop* message_loop) override; | 31 void Run(base::MessageLoop* message_loop) override; |
| 46 void CleanUp() override; | 32 void CleanUp() override; |
| 47 | 33 |
| 48 private: | 34 private: |
| 49 // This class implements all the functionality of the public WebThread | 35 // This class implements all the functionality of the public WebThread |
| 50 // functions, but state is stored in the WebThreadImpl to keep | 36 // functions, but state is stored in the WebThreadImpl to keep |
| 51 // the API cleaner. Therefore make WebThread a friend class. | 37 // the API cleaner. Therefore make WebThread a friend class. |
| 52 friend class WebThread; | 38 friend class WebThread; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 69 // Common initialization code for the constructors. | 55 // Common initialization code for the constructors. |
| 70 void Initialize(); | 56 void Initialize(); |
| 71 | 57 |
| 72 // Performs cleanup that needs to happen on the IO thread before calling the | 58 // Performs cleanup that needs to happen on the IO thread before calling the |
| 73 // embedder's CleanUp function. | 59 // embedder's CleanUp function. |
| 74 void IOThreadPreCleanUp(); | 60 void IOThreadPreCleanUp(); |
| 75 | 61 |
| 76 // For testing. | 62 // For testing. |
| 77 friend class TestWebThreadBundle; | 63 friend class TestWebThreadBundle; |
| 78 friend class TestWebThreadBundleImpl; | 64 friend class TestWebThreadBundleImpl; |
| 65 friend class WebTestSuiteListener; |
| 79 static void FlushThreadPoolHelperForTesting(); | 66 static void FlushThreadPoolHelperForTesting(); |
| 80 | 67 |
| 81 // The identifier of this thread. Only one thread can exist with a given | 68 // The identifier of this thread. Only one thread can exist with a given |
| 82 // identifier at a given time. | 69 // identifier at a given time. |
| 83 ID identifier_; | 70 ID identifier_; |
| 84 }; | 71 }; |
| 85 | 72 |
| 86 } // namespace web | 73 } // namespace web |
| 87 | 74 |
| 88 #endif // IOS_WEB_WEB_THREAD_IMPL_H_ | 75 #endif // IOS_WEB_WEB_THREAD_IMPL_H_ |
| OLD | NEW |