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/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
12 #include "webkit/database/database_util.h" | 13 #include "webkit/database/database_util.h" |
13 #include "webkit/dom_storage/dom_storage_area.h" | 14 #include "webkit/dom_storage/dom_storage_area.h" |
14 #include "webkit/dom_storage/dom_storage_context.h" | 15 #include "webkit/dom_storage/dom_storage_context.h" |
15 #include "webkit/dom_storage/dom_storage_task_runner.h" | 16 #include "webkit/dom_storage/dom_storage_task_runner.h" |
16 #include "webkit/glue/webkit_glue.h" | 17 #include "webkit/glue/webkit_glue.h" |
17 | 18 |
18 using content::BrowserThread; | 19 using content::BrowserThread; |
19 using content::DOMStorageContext; | 20 using content::DOMStorageContext; |
20 using dom_storage::DomStorageArea; | 21 using dom_storage::DomStorageArea; |
21 using dom_storage::DomStorageContext; | 22 using dom_storage::DomStorageContext; |
22 using dom_storage::DomStorageTaskRunner; | 23 using dom_storage::DomStorageTaskRunner; |
23 using dom_storage::DomStorageWorkerPoolTaskRunner; | 24 using dom_storage::DomStorageWorkerPoolTaskRunner; |
24 using webkit_database::DatabaseUtil; | 25 using webkit_database::DatabaseUtil; |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 const char kLocalStorageDirectory[] = "Local Storage"; | 29 const char kLocalStorageDirectory[] = "Local Storage"; |
| 30 const char kSessionStorageDirectory[] = "Session Storage"; |
29 | 31 |
30 // TODO(michaeln): Fix the content layer api, FilePaths and | 32 // TODO(michaeln): Fix the content layer api, FilePaths and |
31 // string16 origin_ids are just wrong. Then get rid of | 33 // string16 origin_ids are just wrong. Then get rid of |
32 // this conversion non-sense. Most of the includes are just | 34 // this conversion non-sense. Most of the includes are just |
33 // to support that non-sense. | 35 // to support that non-sense. |
34 | 36 |
35 GURL OriginIdToGURL(const string16& origin_id) { | 37 GURL OriginIdToGURL(const string16& origin_id) { |
36 return DatabaseUtil::GetOriginFromIdentifier(origin_id); | 38 return DatabaseUtil::GetOriginFromIdentifier(origin_id); |
37 } | 39 } |
38 | 40 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 reply_loop->PostTask( | 74 reply_loop->PostTask( |
73 FROM_HERE, | 75 FROM_HERE, |
74 base::Bind(&InvokeAllStorageFilesCallbackHelper, | 76 base::Bind(&InvokeAllStorageFilesCallbackHelper, |
75 callback, paths)); | 77 callback, paths)); |
76 } | 78 } |
77 | 79 |
78 } // namespace | 80 } // namespace |
79 | 81 |
80 DOMStorageContextImpl::DOMStorageContextImpl( | 82 DOMStorageContextImpl::DOMStorageContextImpl( |
81 const FilePath& data_path, | 83 const FilePath& data_path, |
82 quota::SpecialStoragePolicy* special_storage_policy) { | 84 quota::SpecialStoragePolicy* special_storage_policy, |
| 85 bool session_storage_on_disk) { |
83 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); | 86 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); |
84 // TODO(marja): Pass a nonempty session storage directory when session storage | |
85 // is backed on disk. | |
86 context_ = new dom_storage::DomStorageContext( | 87 context_ = new dom_storage::DomStorageContext( |
87 data_path.empty() ? | 88 data_path.empty() ? |
88 data_path : data_path.AppendASCII(kLocalStorageDirectory), | 89 data_path : data_path.AppendASCII(kLocalStorageDirectory), |
89 FilePath(), // Empty session storage directory. | 90 (data_path.empty() || !session_storage_on_disk) ? |
| 91 data_path : data_path.AppendASCII(kSessionStorageDirectory), |
90 special_storage_policy, | 92 special_storage_policy, |
91 new DomStorageWorkerPoolTaskRunner( | 93 new DomStorageWorkerPoolTaskRunner( |
92 worker_pool, | 94 worker_pool, |
93 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | 95 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
94 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | 96 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 97 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
96 } | 98 } |
97 | 99 |
98 DOMStorageContextImpl::~DOMStorageContextImpl() { | 100 DOMStorageContextImpl::~DOMStorageContextImpl() { |
99 } | 101 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 137 |
136 void DOMStorageContextImpl::DeleteDataModifiedSince(const base::Time& cutoff) { | 138 void DOMStorageContextImpl::DeleteDataModifiedSince(const base::Time& cutoff) { |
137 DCHECK(context_); | 139 DCHECK(context_); |
138 context_->task_runner()->PostShutdownBlockingTask( | 140 context_->task_runner()->PostShutdownBlockingTask( |
139 FROM_HERE, | 141 FROM_HERE, |
140 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 142 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
141 base::Bind(&DomStorageContext::DeleteDataModifiedSince, context_, | 143 base::Bind(&DomStorageContext::DeleteDataModifiedSince, context_, |
142 cutoff)); | 144 cutoff)); |
143 } | 145 } |
144 | 146 |
| 147 void DOMStorageContextImpl::DoomSessionStorage(int64 namespace_id) { |
| 148 DCHECK(context_); |
| 149 context_->task_runner()->PostShutdownBlockingTask( |
| 150 FROM_HERE, |
| 151 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 152 base::Bind(&DomStorageContext::DoomSessionStorage, context_, |
| 153 namespace_id)); |
| 154 } |
| 155 |
| 156 content::SessionStorageNamespace* DOMStorageContextImpl::CreateSessionStorage( |
| 157 const std::string& persistent_id) { |
| 158 return new SessionStorageNamespaceImpl(this, persistent_id); |
| 159 } |
| 160 |
145 void DOMStorageContextImpl::PurgeMemory() { | 161 void DOMStorageContextImpl::PurgeMemory() { |
146 DCHECK(context_); | 162 DCHECK(context_); |
147 context_->task_runner()->PostShutdownBlockingTask( | 163 context_->task_runner()->PostShutdownBlockingTask( |
148 FROM_HERE, | 164 FROM_HERE, |
149 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 165 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
150 base::Bind(&DomStorageContext::PurgeMemory, context_)); | 166 base::Bind(&DomStorageContext::PurgeMemory, context_)); |
151 } | 167 } |
152 | 168 |
153 void DOMStorageContextImpl::SetClearLocalState(bool clear_local_state) { | 169 void DOMStorageContextImpl::SetClearLocalState(bool clear_local_state) { |
154 DCHECK(context_); | 170 DCHECK(context_); |
(...skipping 17 matching lines...) Expand all Loading... |
172 context_->task_runner()->PostShutdownBlockingTask( | 188 context_->task_runner()->PostShutdownBlockingTask( |
173 FROM_HERE, | 189 FROM_HERE, |
174 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 190 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
175 base::Bind(&DomStorageContext::Shutdown, context_)); | 191 base::Bind(&DomStorageContext::Shutdown, context_)); |
176 } | 192 } |
177 | 193 |
178 int64 DOMStorageContextImpl::LeakyCloneSessionStorage( | 194 int64 DOMStorageContextImpl::LeakyCloneSessionStorage( |
179 int64 existing_namespace_id) { | 195 int64 existing_namespace_id) { |
180 DCHECK(context_); | 196 DCHECK(context_); |
181 int64 clone_id = context_->AllocateSessionId(); | 197 int64 clone_id = context_->AllocateSessionId(); |
| 198 std::string clone_persistent_id = context_->AllocatePersistentSessionId(); |
182 context_->task_runner()->PostTask( | 199 context_->task_runner()->PostTask( |
183 FROM_HERE, | 200 FROM_HERE, |
184 base::Bind(&DomStorageContext::CloneSessionNamespace, context_, | 201 base::Bind(&DomStorageContext::CloneSessionNamespace, context_, |
185 existing_namespace_id, clone_id)); | 202 existing_namespace_id, clone_id, clone_persistent_id)); |
186 return clone_id; | 203 return clone_id; |
187 } | 204 } |
OLD | NEW |