blob: 828277c37ea0d5ba65b5177f8b27f2895122161e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
#ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_THREAD_H_
#define CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_THREAD_H_
#include "base/lazy_instance.h"
#include "base/lock.h"
#include "base/logging.h"
#include "base/ref_counted.h"
#include "base/thread.h"
#include "chrome/browser/chrome_thread.h"
class BrowserWebKitClientImpl;
// This is an object that represents WebKit's "main" thread within the browser
// process. It should be instantiated and destroyed on the UI thread
// before/after the IO thread is created/destroyed. All other usage should be
// on the IO thread. If the browser is being run in --single-process mode, a
// thread will never be spun up, and GetMessageLoop() will always return NULL.
class WebKitThread {
public:
// Called from the UI thread.
WebKitThread();
~WebKitThread();
// Returns the message loop for the WebKit thread unless we're in
// --single-processuntil mode, in which case it'll return NULL. Only call
// from the IO thread. Only do fast-path work here.
MessageLoop* GetMessageLoop() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (!webkit_thread_.get())
return InitializeThread();
return webkit_thread_->message_loop();
}
// Called from the IO thread. Notifies us that it's no longer safe to post
// tasks to the IO thread.
void Shutdown();
// Post a task to the IO thread if we haven't yet been told to shut down.
// Only call from the WebKit thread.
bool PostIOThreadTask(const tracked_objects::Location& from_here,
Task* task);
private:
// Must be private so that we can carefully control its lifetime.
class InternalWebKitThread : public ChromeThread {
public:
InternalWebKitThread();
virtual ~InternalWebKitThread();
// Does the actual initialization and shutdown of WebKit. Called at the
// beginning and end of the thread's lifetime.
virtual void Init();
virtual void CleanUp();
private:
// The WebKitClient implementation. Only access on WebKit thread.
scoped_ptr<BrowserWebKitClientImpl> webkit_client_;
};
// Returns the WebKit thread's message loop or NULL if we're in
// --single-process mode. Do slow-path initialization work here.
MessageLoop* InitializeThread();
// Pointer to the actual WebKitThread. NULL if not yet started. Only modify
// from the IO thread while the WebKit thread is not running.
scoped_ptr<InternalWebKitThread> webkit_thread_;
// A pointer to the IO message loop. This is nulled out when Shutdown() is
// called. Only access under the io_message_loop_lock_.
MessageLoop* io_message_loop_;
Lock io_message_loop_lock_;
DISALLOW_COPY_AND_ASSIGN(WebKitThread);
};
#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_THREAD_H_
|