| 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 #include "chrome/browser/in_process_webkit/webkit_context.h" | 5 #include "chrome/browser/in_process_webkit/webkit_context.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_thread.h" | 7 #include "chrome/browser/chrome_thread.h" |
| 8 #include "chrome/browser/in_process_webkit/dom_storage_context.h" | 8 #include "chrome/browser/in_process_webkit/dom_storage_context.h" |
| 9 | 9 |
| 10 WebKitContext::WebKitContext(const FilePath& data_path, bool is_incognito) | 10 WebKitContext::WebKitContext(const FilePath& data_path, bool is_incognito) |
| 11 : data_path_(data_path), | 11 : data_path_(data_path), |
| 12 is_incognito_(is_incognito) { | 12 is_incognito_(is_incognito), |
| 13 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 14 dom_storage_context_(new DOMStorageContext(this))) { |
| 13 } | 15 } |
| 14 | 16 |
| 15 WebKitContext::~WebKitContext() { | 17 WebKitContext::~WebKitContext() { |
| 16 // If a dom storage context was ever created, we need to destroy it on the | 18 // If the WebKit thread was ever spun up, delete the object there. If we're |
| 17 // WebKit thread. Luckily we're guaranteed that the WebKit thread is still | 19 // on the IO thread, this is safe because the WebKit thread goes away after |
| 18 // alive since the ResourceDispatcherHost (which owns the WebKit thread) goes | 20 // the IO. If we're on the UI thread, we're safe because the UI thread kills |
| 19 // away after all the ResourceMessageFilters and the profiles (i.e. all the | 21 // the WebKit thread. |
| 20 // objects with a reference to us). | 22 MessageLoop* webkit_loop = ChromeThread::GetMessageLoop(ChromeThread::WEBKIT); |
| 21 if (dom_storage_context_.get()) { | 23 if (webkit_loop) |
| 22 MessageLoop* loop = ChromeThread::GetMessageLoop(ChromeThread::WEBKIT); | 24 webkit_loop->DeleteSoon(FROM_HERE, dom_storage_context_.release()); |
| 23 loop->DeleteSoon(FROM_HERE, dom_storage_context_.release()); | |
| 24 } | |
| 25 } | 25 } |
| 26 | |
| 27 DOMStorageContext* WebKitContext::GetDOMStorageContext() { | |
| 28 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | |
| 29 if (!dom_storage_context_.get()) | |
| 30 dom_storage_context_.reset(new DOMStorageContext(this)); | |
| 31 return dom_storage_context_.get(); | |
| 32 } | |
| OLD | NEW |