OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/dom_storage/dom_storage_context_impl_new.h" | 5 #include "content/browser/dom_storage/dom_storage_context_impl_new.h" |
6 | 6 |
7 #ifdef ENABLE_NEW_DOM_STORAGE_BACKEND | 7 #ifdef ENABLE_NEW_DOM_STORAGE_BACKEND |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
14 #include "webkit/database/database_util.h" | 14 #include "webkit/database/database_util.h" |
15 #include "webkit/dom_storage/dom_storage_area.h" | 15 #include "webkit/dom_storage/dom_storage_area.h" |
16 #include "webkit/dom_storage/dom_storage_context.h" | 16 #include "webkit/dom_storage/dom_storage_context.h" |
17 #include "webkit/dom_storage/dom_storage_task_runner.h" | 17 #include "webkit/dom_storage/dom_storage_task_runner.h" |
18 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
19 | 19 |
20 using content::BrowserThread; | 20 using content::BrowserThread; |
21 using content::DOMStorageContext; | 21 using content::DOMStorageContext; |
22 using dom_storage::DomStorageArea; | 22 using dom_storage::DomStorageArea; |
23 using dom_storage::DomStorageContext; | 23 using dom_storage::DomStorageContext; |
| 24 using dom_storage::DomStorageTaskRunner; |
24 using dom_storage::DomStorageWorkerPoolTaskRunner; | 25 using dom_storage::DomStorageWorkerPoolTaskRunner; |
25 using webkit_database::DatabaseUtil; | 26 using webkit_database::DatabaseUtil; |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 const char kLocalStorageDirectory[] = "Local Storage"; | 30 const char kLocalStorageDirectory[] = "Local Storage"; |
30 | 31 |
31 // TODO(michaeln): Fix the content layer api, FilePaths and | 32 // TODO(michaeln): Fix the content layer api, FilePaths and |
32 // string16 origin_ids are just wrong. Then get rid of | 33 // string16 origin_ids are just wrong. Then get rid of |
33 // this conversion non-sense. Most of the includes are just | 34 // this conversion non-sense. Most of the includes are just |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 DOMStorageContextImpl::DOMStorageContextImpl( | 79 DOMStorageContextImpl::DOMStorageContextImpl( |
79 const FilePath& data_path, | 80 const FilePath& data_path, |
80 quota::SpecialStoragePolicy* special_storage_policy) { | 81 quota::SpecialStoragePolicy* special_storage_policy) { |
81 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); | 82 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); |
82 context_ = new dom_storage::DomStorageContext( | 83 context_ = new dom_storage::DomStorageContext( |
83 data_path.empty() ? | 84 data_path.empty() ? |
84 data_path : data_path.AppendASCII(kLocalStorageDirectory), | 85 data_path : data_path.AppendASCII(kLocalStorageDirectory), |
85 special_storage_policy, | 86 special_storage_policy, |
86 new DomStorageWorkerPoolTaskRunner( | 87 new DomStorageWorkerPoolTaskRunner( |
87 worker_pool, | 88 worker_pool, |
88 worker_pool->GetNamedSequenceToken("dom_storage"), | 89 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
| 90 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
89 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 91 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
90 } | 92 } |
91 | 93 |
92 DOMStorageContextImpl::~DOMStorageContextImpl() { | 94 DOMStorageContextImpl::~DOMStorageContextImpl() { |
93 } | 95 } |
94 | 96 |
95 void DOMStorageContextImpl::GetAllStorageFiles( | 97 void DOMStorageContextImpl::GetAllStorageFiles( |
96 const GetAllStorageFilesCallback& callback) { | 98 const GetAllStorageFilesCallback& callback) { |
97 DCHECK(context_); | 99 DCHECK(context_); |
98 context_->task_runner()->PostTask( | 100 context_->task_runner()->PostShutdownBlockingTask( |
99 FROM_HERE, | 101 FROM_HERE, |
| 102 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
100 base::Bind(&GetAllStorageFilesHelper, | 103 base::Bind(&GetAllStorageFilesHelper, |
101 base::MessageLoopProxy::current(), | 104 base::MessageLoopProxy::current(), |
102 context_, callback)); | 105 context_, callback)); |
103 } | 106 } |
104 | 107 |
105 FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const { | 108 FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const { |
106 DCHECK(context_); | 109 DCHECK(context_); |
107 return OriginToFullFilePath(context_->directory(), OriginIdToGURL(origin_id)); | 110 return OriginToFullFilePath(context_->directory(), OriginIdToGURL(origin_id)); |
108 } | 111 } |
109 | 112 |
110 void DOMStorageContextImpl::DeleteForOrigin(const string16& origin_id) { | 113 void DOMStorageContextImpl::DeleteForOrigin(const string16& origin_id) { |
111 DCHECK(context_); | 114 DCHECK(context_); |
112 context_->task_runner()->PostTask( | 115 context_->task_runner()->PostShutdownBlockingTask( |
113 FROM_HERE, | 116 FROM_HERE, |
| 117 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
114 base::Bind(&DomStorageContext::DeleteOrigin, context_, | 118 base::Bind(&DomStorageContext::DeleteOrigin, context_, |
115 OriginIdToGURL(origin_id))); | 119 OriginIdToGURL(origin_id))); |
116 } | 120 } |
117 | 121 |
118 void DOMStorageContextImpl::DeleteLocalStorageFile(const FilePath& file_path) { | 122 void DOMStorageContextImpl::DeleteLocalStorageFile(const FilePath& file_path) { |
119 DCHECK(context_); | 123 DCHECK(context_); |
120 context_->task_runner()->PostTask( | 124 context_->task_runner()->PostShutdownBlockingTask( |
121 FROM_HERE, | 125 FROM_HERE, |
| 126 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
122 base::Bind(&DomStorageContext::DeleteOrigin, context_, | 127 base::Bind(&DomStorageContext::DeleteOrigin, context_, |
123 FilePathToOrigin(file_path))); | 128 FilePathToOrigin(file_path))); |
124 } | 129 } |
125 | 130 |
126 void DOMStorageContextImpl::DeleteDataModifiedSince(const base::Time& cutoff) { | 131 void DOMStorageContextImpl::DeleteDataModifiedSince(const base::Time& cutoff) { |
127 DCHECK(context_); | 132 DCHECK(context_); |
128 context_->task_runner()->PostTask( | 133 context_->task_runner()->PostShutdownBlockingTask( |
129 FROM_HERE, | 134 FROM_HERE, |
| 135 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
130 base::Bind(&DomStorageContext::DeleteDataModifiedSince, context_, | 136 base::Bind(&DomStorageContext::DeleteDataModifiedSince, context_, |
131 cutoff)); | 137 cutoff)); |
132 } | 138 } |
133 | 139 |
134 void DOMStorageContextImpl::PurgeMemory() { | 140 void DOMStorageContextImpl::PurgeMemory() { |
135 DCHECK(context_); | 141 DCHECK(context_); |
136 context_->task_runner()->PostTask( | 142 context_->task_runner()->PostShutdownBlockingTask( |
137 FROM_HERE, | 143 FROM_HERE, |
| 144 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
138 base::Bind(&DomStorageContext::PurgeMemory, context_)); | 145 base::Bind(&DomStorageContext::PurgeMemory, context_)); |
139 } | 146 } |
140 | 147 |
141 void DOMStorageContextImpl::SetClearLocalState(bool clear_local_state) { | 148 void DOMStorageContextImpl::SetClearLocalState(bool clear_local_state) { |
142 DCHECK(context_); | 149 DCHECK(context_); |
143 context_->task_runner()->PostTask( | 150 context_->task_runner()->PostShutdownBlockingTask( |
144 FROM_HERE, | 151 FROM_HERE, |
| 152 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
145 base::Bind(&DomStorageContext::SetClearLocalState, context_, | 153 base::Bind(&DomStorageContext::SetClearLocalState, context_, |
146 clear_local_state)); | 154 clear_local_state)); |
147 } | 155 } |
148 | 156 |
149 void DOMStorageContextImpl::SaveSessionState() { | 157 void DOMStorageContextImpl::SaveSessionState() { |
150 DCHECK(context_); | 158 DCHECK(context_); |
151 context_->task_runner()->PostTask( | 159 context_->task_runner()->PostShutdownBlockingTask( |
152 FROM_HERE, | 160 FROM_HERE, |
| 161 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
153 base::Bind(&DomStorageContext::SaveSessionState, context_)); | 162 base::Bind(&DomStorageContext::SaveSessionState, context_)); |
154 } | 163 } |
155 | 164 |
156 void DOMStorageContextImpl::Shutdown() { | 165 void DOMStorageContextImpl::Shutdown() { |
157 DCHECK(context_); | 166 DCHECK(context_); |
158 context_->task_runner()->PostTask( | 167 context_->task_runner()->PostShutdownBlockingTask( |
159 FROM_HERE, | 168 FROM_HERE, |
| 169 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
160 base::Bind(&DomStorageContext::Shutdown, context_)); | 170 base::Bind(&DomStorageContext::Shutdown, context_)); |
161 } | 171 } |
162 | 172 |
163 int64 DOMStorageContextImpl::LeakyCloneSessionStorage( | 173 int64 DOMStorageContextImpl::LeakyCloneSessionStorage( |
164 int64 existing_namespace_id) { | 174 int64 existing_namespace_id) { |
165 DCHECK(context_); | 175 DCHECK(context_); |
166 int64 clone_id = context_->AllocateSessionId(); | 176 int64 clone_id = context_->AllocateSessionId(); |
167 context_->task_runner()->PostTask( | 177 context_->task_runner()->PostTask( |
168 FROM_HERE, | 178 FROM_HERE, |
169 base::Bind(&DomStorageContext::CloneSessionNamespace, context_, | 179 base::Bind(&DomStorageContext::CloneSessionNamespace, context_, |
170 existing_namespace_id, clone_id)); | 180 existing_namespace_id, clone_id)); |
171 return clone_id; | 181 return clone_id; |
172 } | 182 } |
173 | 183 |
174 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND | 184 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND |
OLD | NEW |