Chromium Code Reviews| Index: chrome/browser/in_process_webkit/webkit_context.cc |
| diff --git a/chrome/browser/in_process_webkit/webkit_context.cc b/chrome/browser/in_process_webkit/webkit_context.cc |
| index 0c72346822a10cccc5ea96eb1efdef5b7f3011e7..36a8d7e906e7f589c72044152d91f0cdf71c78cc 100644 |
| --- a/chrome/browser/in_process_webkit/webkit_context.cc |
| +++ b/chrome/browser/in_process_webkit/webkit_context.cc |
| @@ -5,9 +5,45 @@ |
| #include "chrome/browser/in_process_webkit/webkit_context.h" |
| #include "base/command_line.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/task.h" |
| #include "chrome/browser/browser_thread.h" |
| #include "chrome/browser/profiles/profile.h" |
| +namespace { |
| + |
| +template<typename T> |
| +class DeletionTask : public Task { |
| + public: |
| + DeletionTask(T* object, base::WaitableEvent& event) |
| + : object_(object), |
| + event_(event) {} |
| + |
| + // From Task. |
| + virtual void Run() { |
| + delete object_; |
| + event_.Signal(); |
| + }; |
| + |
| + private: |
| + T* object_; |
| + base::WaitableEvent& event_; |
|
jorlow
2011/01/12 17:08:21
Why not a pointer? That seems more typical.
|
| +}; |
| + |
| +template <typename T> |
| +void DeleteOnThread(BrowserThread::ID thread_id, T* object) { |
|
jorlow
2011/01/12 17:08:21
This is doing more than deleting on a particular t
|
| + base::WaitableEvent event(true, false); |
| + Task* delete_task = new DeletionTask<T>(object, event); |
| + |
| + if (BrowserThread::PostTask(thread_id, FROM_HERE, delete_task)) { |
|
jorlow
2011/01/12 17:08:21
no {}'s
|
| + event.Wait(); |
| + } else { |
| + delete object; |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| WebKitContext::WebKitContext(Profile* profile, bool clear_local_state_on_exit) |
| : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()), |
| is_incognito_(profile->IsOffTheRecord()), |
| @@ -34,11 +70,7 @@ WebKitContext::~WebKitContext() { |
| indexed_db_context_->set_clear_local_state_on_exit( |
| clear_local_state_on_exit_); |
| - IndexedDBContext* indexed_db_context = indexed_db_context_.release(); |
| - if (!BrowserThread::DeleteSoon( |
| - BrowserThread::WEBKIT, FROM_HERE, indexed_db_context)) { |
| - delete indexed_db_context; |
| - } |
| + DeleteOnThread(BrowserThread::WEBKIT, indexed_db_context_.release()); |
|
jorlow
2011/01/12 17:08:21
Hm...so we're going to block the io thread on the
|
| } |
| void WebKitContext::PurgeMemory() { |