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

Side by Side Diff: chrome/browser/in_process_webkit/webkit_thread.cc

Issue 155845: DOM Storage: Add browser-process IPC code + tweak the WebKit Thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months 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 | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/in_process_webkit/webkit_thread.h" 5 #include "chrome/browser/in_process_webkit/webkit_thread.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/in_process_webkit/browser_webkitclient_impl.h" 8 #include "chrome/browser/in_process_webkit/browser_webkitclient_impl.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "webkit/api/public/WebKit.h" 10 #include "webkit/api/public/WebKit.h"
11 11
12 // This happens on the UI thread before the IO thread has been shut down. 12 // This happens on the UI thread before the IO thread has been shut down.
13 WebKitThread::WebKitThread() { 13 WebKitThread::WebKitThread()
14 : io_message_loop_(ChromeThread::GetMessageLoop(ChromeThread::IO)) {
14 // The thread is started lazily by InitializeThread() on the IO thread. 15 // The thread is started lazily by InitializeThread() on the IO thread.
15 } 16 }
16 17
17 // This happens on the UI thread after the IO thread has been shut down. 18 // This happens on the UI thread after the IO thread has been shut down.
18 WebKitThread::~WebKitThread() { 19 WebKitThread::~WebKitThread() {
20 // There's no good way to see if we're on the UI thread.
19 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 21 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
22 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::IO));
23 DCHECK(!io_message_loop_);
24 }
25
26 void WebKitThread::Shutdown() {
27 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
28 DCHECK(io_message_loop_);
29
30 // TODO(jorlow): Start flushing LocalStorage?
31
32 AutoLock lock(io_message_loop_lock_);
33 io_message_loop_ = NULL;
34 }
35
36 bool WebKitThread::PostIOThreadTask(
37 const tracked_objects::Location& from_here, Task* task) {
38 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
39 {
40 AutoLock lock(io_message_loop_lock_);
41 if (io_message_loop_) {
42 io_message_loop_->PostTask(from_here, task);
43 return true;
44 }
45 }
46 delete task;
47 return false;
20 } 48 }
21 49
22 WebKitThread::InternalWebKitThread::InternalWebKitThread() 50 WebKitThread::InternalWebKitThread::InternalWebKitThread()
23 : ChromeThread(ChromeThread::WEBKIT), 51 : ChromeThread(ChromeThread::WEBKIT),
24 webkit_client_(NULL) { 52 webkit_client_(NULL) {
25 } 53 }
26 54
27 void WebKitThread::InternalWebKitThread::Init() { 55 void WebKitThread::InternalWebKitThread::Init() {
28 DCHECK(!webkit_client_); 56 DCHECK(!webkit_client_);
29 webkit_client_ = new BrowserWebKitClientImpl; 57 webkit_client_ = new BrowserWebKitClientImpl;
30 DCHECK(webkit_client_); 58 DCHECK(webkit_client_);
31 WebKit::initialize(webkit_client_); 59 WebKit::initialize(webkit_client_);
32 // Don't do anything heavyweight here since this can block the IO thread from 60 // If possible, post initialization tasks to this thread (rather than doing
33 // executing (since InitializeThread() is called on the IO thread). 61 // them now) so we don't block the IO thread any longer than we have to.
34 } 62 }
35 63
36 void WebKitThread::InternalWebKitThread::CleanUp() { 64 void WebKitThread::InternalWebKitThread::CleanUp() {
37 // Don't do anything heavyweight here since this can block the IO thread from 65 // TODO(jorlow): Block on LocalStorage being 100% shut down.
38 // executing (since the thread is shutdown from the IO thread).
39 DCHECK(webkit_client_); 66 DCHECK(webkit_client_);
40 WebKit::shutdown(); 67 WebKit::shutdown();
41 delete webkit_client_; 68 delete webkit_client_;
42 } 69 }
43 70
44 MessageLoop* WebKitThread::InitializeThread() { 71 MessageLoop* WebKitThread::InitializeThread() {
45 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 72 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
46 return NULL; 73 return NULL;
47 74
75 DCHECK(io_message_loop_);
48 DCHECK(!webkit_thread_.get()); 76 DCHECK(!webkit_thread_.get());
49 webkit_thread_.reset(new InternalWebKitThread); 77 webkit_thread_.reset(new InternalWebKitThread);
50 bool started = webkit_thread_->Start(); 78 bool started = webkit_thread_->Start();
51 DCHECK(started); 79 DCHECK(started);
52 return webkit_thread_->message_loop(); 80 return webkit_thread_->message_loop();
53 } 81 }
OLDNEW
« no previous file with comments | « chrome/browser/in_process_webkit/webkit_thread.h ('k') | chrome/browser/renderer_host/resource_dispatcher_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698