| 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/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 11 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "webkit/dom_storage/dom_storage_area.h" | 13 #include "webkit/dom_storage/dom_storage_area.h" |
| 14 #include "webkit/dom_storage/dom_storage_context.h" | 14 #include "webkit/dom_storage/dom_storage_context.h" |
| 15 #include "webkit/dom_storage/dom_storage_task_runner.h" | 15 #include "webkit/dom_storage/dom_storage_task_runner.h" |
| 16 | 16 |
| 17 using content::BrowserThread; | 17 using content::BrowserThread; |
| 18 using content::DOMStorageContext; | 18 using content::DOMStorageContext; |
| 19 using dom_storage::DomStorageArea; | 19 using dom_storage::DomStorageArea; |
| 20 using dom_storage::DomStorageContext; | 20 using dom_storage::DomStorageContext; |
| 21 using dom_storage::DomStorageTaskRunner; | 21 using dom_storage::DomStorageTaskRunner; |
| 22 using dom_storage::DomStorageWorkerPoolTaskRunner; | 22 using dom_storage::DomStorageWorkerPoolTaskRunner; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const char kLocalStorageDirectory[] = "Local Storage"; | 26 const char kLocalStorageDirectory[] = "Local Storage"; |
| 27 const char kSessionStorageDirectory[] = "Session Storage"; |
| 27 | 28 |
| 28 void InvokeUsageInfoCallbackHelper( | 29 void InvokeUsageInfoCallbackHelper( |
| 29 const DOMStorageContext::GetUsageInfoCallback& callback, | 30 const DOMStorageContext::GetUsageInfoCallback& callback, |
| 30 const std::vector<DomStorageContext::UsageInfo>* infos) { | 31 const std::vector<DomStorageContext::UsageInfo>* infos) { |
| 31 callback.Run(*infos); | 32 callback.Run(*infos); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void GetUsageInfoHelper( | 35 void GetUsageInfoHelper( |
| 35 base::MessageLoopProxy* reply_loop, | 36 base::MessageLoopProxy* reply_loop, |
| 36 DomStorageContext* context, | 37 DomStorageContext* context, |
| 37 const DOMStorageContext::GetUsageInfoCallback& callback) { | 38 const DOMStorageContext::GetUsageInfoCallback& callback) { |
| 38 std::vector<DomStorageContext::UsageInfo>* infos = | 39 std::vector<DomStorageContext::UsageInfo>* infos = |
| 39 new std::vector<DomStorageContext::UsageInfo>; | 40 new std::vector<DomStorageContext::UsageInfo>; |
| 40 context->GetUsageInfo(infos, true); | 41 context->GetUsageInfo(infos, true); |
| 41 reply_loop->PostTask( | 42 reply_loop->PostTask( |
| 42 FROM_HERE, | 43 FROM_HERE, |
| 43 base::Bind(&InvokeUsageInfoCallbackHelper, | 44 base::Bind(&InvokeUsageInfoCallbackHelper, |
| 44 callback, base::Owned(infos))); | 45 callback, base::Owned(infos))); |
| 45 } | 46 } |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 DOMStorageContextImpl::DOMStorageContextImpl( | 50 DOMStorageContextImpl::DOMStorageContextImpl( |
| 50 const FilePath& data_path, | 51 const FilePath& data_path, |
| 51 quota::SpecialStoragePolicy* special_storage_policy) { | 52 quota::SpecialStoragePolicy* special_storage_policy, |
| 53 bool save_session_storage_on_disk) { |
| 52 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); | 54 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); |
| 53 // TODO(marja): Pass a nonempty session storage directory when session storage | |
| 54 // is backed on disk. | |
| 55 context_ = new dom_storage::DomStorageContext( | 55 context_ = new dom_storage::DomStorageContext( |
| 56 data_path.empty() ? | 56 data_path.empty() ? |
| 57 data_path : data_path.AppendASCII(kLocalStorageDirectory), | 57 data_path : data_path.AppendASCII(kLocalStorageDirectory), |
| 58 FilePath(), // Empty session storage directory. | 58 (data_path.empty() || !save_session_storage_on_disk) ? |
| 59 FilePath() : data_path.AppendASCII(kSessionStorageDirectory), |
| 59 special_storage_policy, | 60 special_storage_policy, |
| 60 new DomStorageWorkerPoolTaskRunner( | 61 new DomStorageWorkerPoolTaskRunner( |
| 61 worker_pool, | 62 worker_pool, |
| 62 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | 63 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
| 63 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | 64 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
| 64 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 65 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
| 65 } | 66 } |
| 66 | 67 |
| 67 DOMStorageContextImpl::~DOMStorageContextImpl() { | 68 DOMStorageContextImpl::~DOMStorageContextImpl() { |
| 68 } | 69 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 base::Bind(&DomStorageContext::DeleteOrigin, context_, origin)); | 86 base::Bind(&DomStorageContext::DeleteOrigin, context_, origin)); |
| 86 } | 87 } |
| 87 | 88 |
| 88 scoped_refptr<content::SessionStorageNamespace> | 89 scoped_refptr<content::SessionStorageNamespace> |
| 89 DOMStorageContextImpl::RecreateSessionStorage( | 90 DOMStorageContextImpl::RecreateSessionStorage( |
| 90 const std::string& persistent_id) { | 91 const std::string& persistent_id) { |
| 91 return scoped_refptr<content::SessionStorageNamespace>( | 92 return scoped_refptr<content::SessionStorageNamespace>( |
| 92 new SessionStorageNamespaceImpl(this, persistent_id)); | 93 new SessionStorageNamespaceImpl(this, persistent_id)); |
| 93 } | 94 } |
| 94 | 95 |
| 96 void DOMStorageContextImpl::StartScavengingUnusedSessionStorage() { |
| 97 DCHECK(context_); |
| 98 context_->task_runner()->PostShutdownBlockingTask( |
| 99 FROM_HERE, |
| 100 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 101 base::Bind(&DomStorageContext::StartScavengingUnusedSessionStorage, |
| 102 context_)); |
| 103 } |
| 104 |
| 95 void DOMStorageContextImpl::PurgeMemory() { | 105 void DOMStorageContextImpl::PurgeMemory() { |
| 96 DCHECK(context_); | 106 DCHECK(context_); |
| 97 context_->task_runner()->PostShutdownBlockingTask( | 107 context_->task_runner()->PostShutdownBlockingTask( |
| 98 FROM_HERE, | 108 FROM_HERE, |
| 99 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 109 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 100 base::Bind(&DomStorageContext::PurgeMemory, context_)); | 110 base::Bind(&DomStorageContext::PurgeMemory, context_)); |
| 101 } | 111 } |
| 102 | 112 |
| 103 void DOMStorageContextImpl::SetForceKeepSessionState() { | 113 void DOMStorageContextImpl::SetForceKeepSessionState() { |
| 104 DCHECK(context_); | 114 DCHECK(context_); |
| 105 context_->task_runner()->PostShutdownBlockingTask( | 115 context_->task_runner()->PostShutdownBlockingTask( |
| 106 FROM_HERE, | 116 FROM_HERE, |
| 107 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 117 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 108 base::Bind(&DomStorageContext::SetForceKeepSessionState, context_)); | 118 base::Bind(&DomStorageContext::SetForceKeepSessionState, context_)); |
| 109 } | 119 } |
| 110 | 120 |
| 111 void DOMStorageContextImpl::Shutdown() { | 121 void DOMStorageContextImpl::Shutdown() { |
| 112 DCHECK(context_); | 122 DCHECK(context_); |
| 113 context_->task_runner()->PostShutdownBlockingTask( | 123 context_->task_runner()->PostShutdownBlockingTask( |
| 114 FROM_HERE, | 124 FROM_HERE, |
| 115 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 125 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 116 base::Bind(&DomStorageContext::Shutdown, context_)); | 126 base::Bind(&DomStorageContext::Shutdown, context_)); |
| 117 } | 127 } |
| OLD | NEW |