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.h" | 5 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" |
9 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
10 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
12 #include "webkit/database/database_util.h" | 14 #include "webkit/database/database_util.h" |
13 #include "webkit/dom_storage/dom_storage_area.h" | 15 #include "webkit/dom_storage/dom_storage_area.h" |
14 #include "webkit/dom_storage/dom_storage_context.h" | 16 #include "webkit/dom_storage/dom_storage_context.h" |
15 #include "webkit/dom_storage/dom_storage_task_runner.h" | 17 #include "webkit/dom_storage/dom_storage_task_runner.h" |
16 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
17 | 19 |
18 using content::BrowserThread; | 20 using content::BrowserThread; |
19 using content::DOMStorageContext; | 21 using content::DOMStorageContext; |
20 using dom_storage::DomStorageArea; | 22 using dom_storage::DomStorageArea; |
21 using dom_storage::DomStorageContext; | 23 using dom_storage::DomStorageContext; |
22 using dom_storage::DomStorageTaskRunner; | 24 using dom_storage::DomStorageTaskRunner; |
23 using dom_storage::DomStorageWorkerPoolTaskRunner; | 25 using dom_storage::DomStorageWorkerPoolTaskRunner; |
24 using webkit_database::DatabaseUtil; | 26 using webkit_database::DatabaseUtil; |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 const char kLocalStorageDirectory[] = "Local Storage"; | 30 const char kLocalStorageDirectory[] = "Local Storage"; |
| 31 const char kSessionStorageDirectory[] = "Session Storage"; |
29 | 32 |
30 void InvokeUsageInfoCallbackHelper( | 33 void InvokeUsageInfoCallbackHelper( |
31 const DOMStorageContext::GetUsageInfoCallback& callback, | 34 const DOMStorageContext::GetUsageInfoCallback& callback, |
32 const std::vector<DomStorageContext::UsageInfo>* infos) { | 35 const std::vector<DomStorageContext::UsageInfo>* infos) { |
33 callback.Run(*infos); | 36 callback.Run(*infos); |
34 } | 37 } |
35 | 38 |
36 void GetUsageInfoHelper( | 39 void GetUsageInfoHelper( |
37 base::MessageLoopProxy* reply_loop, | 40 base::MessageLoopProxy* reply_loop, |
38 DomStorageContext* context, | 41 DomStorageContext* context, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 base::Bind(&InvokeAllStorageFilesCallbackHelper, | 96 base::Bind(&InvokeAllStorageFilesCallbackHelper, |
94 callback, paths)); | 97 callback, paths)); |
95 } | 98 } |
96 | 99 |
97 } // namespace | 100 } // namespace |
98 | 101 |
99 DOMStorageContextImpl::DOMStorageContextImpl( | 102 DOMStorageContextImpl::DOMStorageContextImpl( |
100 const FilePath& data_path, | 103 const FilePath& data_path, |
101 quota::SpecialStoragePolicy* special_storage_policy) { | 104 quota::SpecialStoragePolicy* special_storage_policy) { |
102 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); | 105 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); |
103 // TODO(marja): Pass a nonempty session storage directory when session storage | 106 // TODO(marja): Remove this as soon as the sessionStorage on disk |
104 // is backed on disk. | 107 // implementation is on by default. |
| 108 const char kEnableRestoreSessionState[] = "enable-restore-session-state"; |
| 109 bool session_storage_on_disk = |
| 110 CommandLine::ForCurrentProcess()->HasSwitch(kEnableRestoreSessionState); |
105 context_ = new dom_storage::DomStorageContext( | 111 context_ = new dom_storage::DomStorageContext( |
106 data_path.empty() ? | 112 data_path.empty() ? |
107 data_path : data_path.AppendASCII(kLocalStorageDirectory), | 113 data_path : data_path.AppendASCII(kLocalStorageDirectory), |
108 FilePath(), // Empty session storage directory. | 114 (data_path.empty() || !session_storage_on_disk) ? |
| 115 data_path : data_path.AppendASCII(kSessionStorageDirectory), |
109 special_storage_policy, | 116 special_storage_policy, |
110 new DomStorageWorkerPoolTaskRunner( | 117 new DomStorageWorkerPoolTaskRunner( |
111 worker_pool, | 118 worker_pool, |
112 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | 119 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
113 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | 120 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
114 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 121 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
115 } | 122 } |
116 | 123 |
117 DOMStorageContextImpl::~DOMStorageContextImpl() { | 124 DOMStorageContextImpl::~DOMStorageContextImpl() { |
118 } | 125 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 170 |
164 void DOMStorageContextImpl::DeleteLocalStorageFile(const FilePath& file_path) { | 171 void DOMStorageContextImpl::DeleteLocalStorageFile(const FilePath& file_path) { |
165 DCHECK(context_); | 172 DCHECK(context_); |
166 context_->task_runner()->PostShutdownBlockingTask( | 173 context_->task_runner()->PostShutdownBlockingTask( |
167 FROM_HERE, | 174 FROM_HERE, |
168 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 175 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
169 base::Bind(&DomStorageContext::DeleteOrigin, context_, | 176 base::Bind(&DomStorageContext::DeleteOrigin, context_, |
170 FilePathToOrigin(file_path))); | 177 FilePathToOrigin(file_path))); |
171 } | 178 } |
172 | 179 |
| 180 void DOMStorageContextImpl::DoomSessionStorage( |
| 181 const std::string& persistent_namespace_id) { |
| 182 DCHECK(context_); |
| 183 context_->task_runner()->PostShutdownBlockingTask( |
| 184 FROM_HERE, |
| 185 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 186 base::Bind(&DomStorageContext::DoomSessionStorage, context_, |
| 187 persistent_namespace_id)); |
| 188 } |
| 189 |
| 190 scoped_refptr<content::SessionStorageNamespace> |
| 191 DOMStorageContextImpl::RecreateSessionStorage( |
| 192 const std::string& persistent_id) { |
| 193 return scoped_refptr<content::SessionStorageNamespace>( |
| 194 new SessionStorageNamespaceImpl(this, persistent_id)); |
| 195 } |
| 196 |
173 void DOMStorageContextImpl::PurgeMemory() { | 197 void DOMStorageContextImpl::PurgeMemory() { |
174 DCHECK(context_); | 198 DCHECK(context_); |
175 context_->task_runner()->PostShutdownBlockingTask( | 199 context_->task_runner()->PostShutdownBlockingTask( |
176 FROM_HERE, | 200 FROM_HERE, |
177 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 201 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
178 base::Bind(&DomStorageContext::PurgeMemory, context_)); | 202 base::Bind(&DomStorageContext::PurgeMemory, context_)); |
179 } | 203 } |
180 | 204 |
181 void DOMStorageContextImpl::SetForceKeepSessionState() { | 205 void DOMStorageContextImpl::SetForceKeepSessionState() { |
182 DCHECK(context_); | 206 DCHECK(context_); |
183 context_->task_runner()->PostShutdownBlockingTask( | 207 context_->task_runner()->PostShutdownBlockingTask( |
184 FROM_HERE, | 208 FROM_HERE, |
185 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 209 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
186 base::Bind(&DomStorageContext::SetForceKeepSessionState, context_)); | 210 base::Bind(&DomStorageContext::SetForceKeepSessionState, context_)); |
187 } | 211 } |
188 | 212 |
189 void DOMStorageContextImpl::Shutdown() { | 213 void DOMStorageContextImpl::Shutdown() { |
190 DCHECK(context_); | 214 DCHECK(context_); |
191 context_->task_runner()->PostShutdownBlockingTask( | 215 context_->task_runner()->PostShutdownBlockingTask( |
192 FROM_HERE, | 216 FROM_HERE, |
193 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 217 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
194 base::Bind(&DomStorageContext::Shutdown, context_)); | 218 base::Bind(&DomStorageContext::Shutdown, context_)); |
195 } | 219 } |
OLD | NEW |