| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_THREAD_H_ | 5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_THREAD_H_ |
| 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_THREAD_H_ | 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_THREAD_H_ |
| 7 | 7 |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/lock.h" | 9 #include "base/lock.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "base/thread.h" | 12 #include "base/thread.h" |
| 13 #include "chrome/browser/chrome_thread.h" | 13 #include "chrome/browser/chrome_thread.h" |
| 14 | 14 |
| 15 class BrowserWebKitClientImpl; | 15 class BrowserWebKitClientImpl; |
| 16 | 16 |
| 17 // This is an object that represents WebKit's "main" thread within the browser | 17 // This creates a WebKit main thread on instantiation (if not in |
| 18 // process. It should be instantiated and destroyed on the UI thread | 18 // --single-process mode) on construction and kills it on deletion. |
| 19 // before/after the IO thread is created/destroyed. All other usage should be | |
| 20 // on the IO thread. If the browser is being run in --single-process mode, a | |
| 21 // thread will never be spun up. | |
| 22 class WebKitThread { | 19 class WebKitThread { |
| 23 public: | 20 public: |
| 24 // Called from the UI thread. | 21 // Called from the UI thread. |
| 25 WebKitThread(); | 22 WebKitThread(); |
| 26 ~WebKitThread(); | 23 ~WebKitThread(); |
| 27 | 24 void Initialize(); |
| 28 // Creates the WebKit thread if it hasn't been already created. Only call | |
| 29 // from the IO thread. Only do fast-path work here. | |
| 30 void EnsureInitialized(); | |
| 31 | 25 |
| 32 private: | 26 private: |
| 33 // Must be private so that we can carefully control its lifetime. | 27 // Must be private so that we can carefully control its lifetime. |
| 34 class InternalWebKitThread : public ChromeThread { | 28 class InternalWebKitThread : public ChromeThread { |
| 35 public: | 29 public: |
| 36 InternalWebKitThread(); | 30 InternalWebKitThread(); |
| 37 virtual ~InternalWebKitThread(); | 31 virtual ~InternalWebKitThread(); |
| 38 // Does the actual initialization and shutdown of WebKit. Called at the | 32 // Does the actual initialization and shutdown of WebKit. Called at the |
| 39 // beginning and end of the thread's lifetime. | 33 // beginning and end of the thread's lifetime. |
| 40 virtual void Init(); | 34 virtual void Init(); |
| 41 virtual void CleanUp(); | 35 virtual void CleanUp(); |
| 42 | 36 |
| 43 private: | 37 private: |
| 44 // The WebKitClient implementation. Only access on WebKit thread. | 38 // The WebKitClient implementation. Only access on WebKit thread. |
| 45 scoped_ptr<BrowserWebKitClientImpl> webkit_client_; | 39 scoped_ptr<BrowserWebKitClientImpl> webkit_client_; |
| 46 }; | 40 }; |
| 47 | 41 |
| 48 // Returns the WebKit thread's message loop or NULL if we're in | 42 // Pointer to the actual WebKitThread. |
| 49 // --single-process mode. Do slow-path initialization work here. | |
| 50 MessageLoop* InitializeThread(); | |
| 51 | |
| 52 // Pointer to the actual WebKitThread. NULL if not yet started. Only modify | |
| 53 // from the IO thread while the WebKit thread is not running. | |
| 54 scoped_ptr<InternalWebKitThread> webkit_thread_; | 43 scoped_ptr<InternalWebKitThread> webkit_thread_; |
| 55 | 44 |
| 56 DISALLOW_COPY_AND_ASSIGN(WebKitThread); | 45 DISALLOW_COPY_AND_ASSIGN(WebKitThread); |
| 57 }; | 46 }; |
| 58 | 47 |
| 59 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_THREAD_H_ | 48 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_THREAD_H_ |
| OLD | NEW |