OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/synchronization/waitable_event.h" | |
9 #include "base/task.h" | |
8 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
10 | 12 |
13 namespace { | |
14 | |
15 template<typename T> | |
16 class DeletionTask : public Task { | |
17 public: | |
18 DeletionTask(T* object, base::WaitableEvent& event) | |
19 : object_(object), | |
20 event_(event) {} | |
21 | |
22 // From Task. | |
23 virtual void Run() { | |
24 delete object_; | |
25 event_.Signal(); | |
26 }; | |
27 | |
28 private: | |
29 T* object_; | |
30 base::WaitableEvent& event_; | |
jorlow
2011/01/12 17:08:21
Why not a pointer? That seems more typical.
| |
31 }; | |
32 | |
33 template <typename T> | |
34 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
| |
35 base::WaitableEvent event(true, false); | |
36 Task* delete_task = new DeletionTask<T>(object, event); | |
37 | |
38 if (BrowserThread::PostTask(thread_id, FROM_HERE, delete_task)) { | |
jorlow
2011/01/12 17:08:21
no {}'s
| |
39 event.Wait(); | |
40 } else { | |
41 delete object; | |
42 } | |
43 } | |
44 | |
45 } // namespace | |
46 | |
11 WebKitContext::WebKitContext(Profile* profile, bool clear_local_state_on_exit) | 47 WebKitContext::WebKitContext(Profile* profile, bool clear_local_state_on_exit) |
12 : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()), | 48 : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()), |
13 is_incognito_(profile->IsOffTheRecord()), | 49 is_incognito_(profile->IsOffTheRecord()), |
14 clear_local_state_on_exit_(clear_local_state_on_exit), | 50 clear_local_state_on_exit_(clear_local_state_on_exit), |
15 ALLOW_THIS_IN_INITIALIZER_LIST( | 51 ALLOW_THIS_IN_INITIALIZER_LIST( |
16 dom_storage_context_(new DOMStorageContext(this))), | 52 dom_storage_context_(new DOMStorageContext(this))), |
17 ALLOW_THIS_IN_INITIALIZER_LIST( | 53 ALLOW_THIS_IN_INITIALIZER_LIST( |
18 indexed_db_context_(new IndexedDBContext(this))) { | 54 indexed_db_context_(new IndexedDBContext(this))) { |
19 } | 55 } |
20 | 56 |
21 WebKitContext::~WebKitContext() { | 57 WebKitContext::~WebKitContext() { |
22 // If the WebKit thread was ever spun up, delete the object there. The task | 58 // If the WebKit thread was ever spun up, delete the object there. The task |
23 // will just get deleted if the WebKit thread isn't created (which only | 59 // will just get deleted if the WebKit thread isn't created (which only |
24 // happens during testing). | 60 // happens during testing). |
25 dom_storage_context_->set_clear_local_state_on_exit_( | 61 dom_storage_context_->set_clear_local_state_on_exit_( |
26 clear_local_state_on_exit_); | 62 clear_local_state_on_exit_); |
27 DOMStorageContext* dom_storage_context = dom_storage_context_.release(); | 63 DOMStorageContext* dom_storage_context = dom_storage_context_.release(); |
28 if (!BrowserThread::DeleteSoon( | 64 if (!BrowserThread::DeleteSoon( |
29 BrowserThread::WEBKIT, FROM_HERE, dom_storage_context)) { | 65 BrowserThread::WEBKIT, FROM_HERE, dom_storage_context)) { |
30 // The WebKit thread wasn't created, and the task got deleted without | 66 // The WebKit thread wasn't created, and the task got deleted without |
31 // freeing the DOMStorageContext, so delete it manually. | 67 // freeing the DOMStorageContext, so delete it manually. |
32 delete dom_storage_context; | 68 delete dom_storage_context; |
33 } | 69 } |
34 | 70 |
35 indexed_db_context_->set_clear_local_state_on_exit( | 71 indexed_db_context_->set_clear_local_state_on_exit( |
36 clear_local_state_on_exit_); | 72 clear_local_state_on_exit_); |
37 IndexedDBContext* indexed_db_context = indexed_db_context_.release(); | 73 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
| |
38 if (!BrowserThread::DeleteSoon( | |
39 BrowserThread::WEBKIT, FROM_HERE, indexed_db_context)) { | |
40 delete indexed_db_context; | |
41 } | |
42 } | 74 } |
43 | 75 |
44 void WebKitContext::PurgeMemory() { | 76 void WebKitContext::PurgeMemory() { |
45 if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) { | 77 if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) { |
46 BrowserThread::PostTask( | 78 BrowserThread::PostTask( |
47 BrowserThread::WEBKIT, FROM_HERE, | 79 BrowserThread::WEBKIT, FROM_HERE, |
48 NewRunnableMethod(this, &WebKitContext::PurgeMemory)); | 80 NewRunnableMethod(this, &WebKitContext::PurgeMemory)); |
49 return; | 81 return; |
50 } | 82 } |
51 | 83 |
(...skipping 23 matching lines...) Expand all Loading... | |
75 BrowserThread::PostTask( | 107 BrowserThread::PostTask( |
76 BrowserThread::WEBKIT, FROM_HERE, | 108 BrowserThread::WEBKIT, FROM_HERE, |
77 NewRunnableMethod(this, &WebKitContext::DeleteSessionStorageNamespace, | 109 NewRunnableMethod(this, &WebKitContext::DeleteSessionStorageNamespace, |
78 session_storage_namespace_id)); | 110 session_storage_namespace_id)); |
79 return; | 111 return; |
80 } | 112 } |
81 | 113 |
82 dom_storage_context_->DeleteSessionStorageNamespace( | 114 dom_storage_context_->DeleteSessionStorageNamespace( |
83 session_storage_namespace_id); | 115 session_storage_namespace_id); |
84 } | 116 } |
OLD | NEW |