| 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/file_path.h" | 10 #include "base/file_path.h" |
| 10 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 11 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 12 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
| 12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.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 | 17 |
| 17 using content::BrowserThread; | 18 using content::BrowserThread; |
| 18 using content::DOMStorageContext; | 19 using content::DOMStorageContext; |
| 19 using dom_storage::DomStorageArea; | 20 using dom_storage::DomStorageArea; |
| 20 using dom_storage::DomStorageContext; | 21 using dom_storage::DomStorageContext; |
| 21 using dom_storage::DomStorageTaskRunner; | 22 using dom_storage::DomStorageTaskRunner; |
| 22 using dom_storage::DomStorageWorkerPoolTaskRunner; | 23 using dom_storage::DomStorageWorkerPoolTaskRunner; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const char kLocalStorageDirectory[] = "Local Storage"; | 27 const char kLocalStorageDirectory[] = "Local Storage"; |
| 28 const char kSessionStorageDirectory[] = "Session Storage"; |
| 27 | 29 |
| 28 void InvokeUsageInfoCallbackHelper( | 30 void InvokeUsageInfoCallbackHelper( |
| 29 const DOMStorageContext::GetUsageInfoCallback& callback, | 31 const DOMStorageContext::GetUsageInfoCallback& callback, |
| 30 const std::vector<DomStorageContext::UsageInfo>* infos) { | 32 const std::vector<DomStorageContext::UsageInfo>* infos) { |
| 31 callback.Run(*infos); | 33 callback.Run(*infos); |
| 32 } | 34 } |
| 33 | 35 |
| 34 void GetUsageInfoHelper( | 36 void GetUsageInfoHelper( |
| 35 base::MessageLoopProxy* reply_loop, | 37 base::MessageLoopProxy* reply_loop, |
| 36 DomStorageContext* context, | 38 DomStorageContext* context, |
| 37 const DOMStorageContext::GetUsageInfoCallback& callback) { | 39 const DOMStorageContext::GetUsageInfoCallback& callback) { |
| 38 std::vector<DomStorageContext::UsageInfo>* infos = | 40 std::vector<DomStorageContext::UsageInfo>* infos = |
| 39 new std::vector<DomStorageContext::UsageInfo>; | 41 new std::vector<DomStorageContext::UsageInfo>; |
| 40 context->GetUsageInfo(infos, true); | 42 context->GetUsageInfo(infos, true); |
| 41 reply_loop->PostTask( | 43 reply_loop->PostTask( |
| 42 FROM_HERE, | 44 FROM_HERE, |
| 43 base::Bind(&InvokeUsageInfoCallbackHelper, | 45 base::Bind(&InvokeUsageInfoCallbackHelper, |
| 44 callback, base::Owned(infos))); | 46 callback, base::Owned(infos))); |
| 45 } | 47 } |
| 46 | 48 |
| 47 } // namespace | 49 } // namespace |
| 48 | 50 |
| 49 DOMStorageContextImpl::DOMStorageContextImpl( | 51 DOMStorageContextImpl::DOMStorageContextImpl( |
| 50 const FilePath& data_path, | 52 const FilePath& data_path, |
| 51 quota::SpecialStoragePolicy* special_storage_policy) { | 53 quota::SpecialStoragePolicy* special_storage_policy) { |
| 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 | 55 // TODO(marja): Remove this as soon as the sessionStorage on disk |
| 54 // is backed on disk. | 56 // implementation is on by default. |
| 57 const char kEnableRestoreSessionState[] = "enable-restore-session-state"; |
| 58 bool session_storage_on_disk = |
| 59 CommandLine::ForCurrentProcess()->HasSwitch(kEnableRestoreSessionState); |
| 55 context_ = new dom_storage::DomStorageContext( | 60 context_ = new dom_storage::DomStorageContext( |
| 56 data_path.empty() ? | 61 data_path.empty() ? |
| 57 data_path : data_path.AppendASCII(kLocalStorageDirectory), | 62 data_path : data_path.AppendASCII(kLocalStorageDirectory), |
| 58 FilePath(), // Empty session storage directory. | 63 (data_path.empty() || !session_storage_on_disk) ? |
| 64 FilePath() : data_path.AppendASCII(kSessionStorageDirectory), |
| 59 special_storage_policy, | 65 special_storage_policy, |
| 60 new DomStorageWorkerPoolTaskRunner( | 66 new DomStorageWorkerPoolTaskRunner( |
| 61 worker_pool, | 67 worker_pool, |
| 62 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | 68 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
| 63 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | 69 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
| 64 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 70 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
| 65 } | 71 } |
| 66 | 72 |
| 67 DOMStorageContextImpl::~DOMStorageContextImpl() { | 73 DOMStorageContextImpl::~DOMStorageContextImpl() { |
| 68 } | 74 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 base::Bind(&DomStorageContext::DeleteOrigin, context_, origin)); | 91 base::Bind(&DomStorageContext::DeleteOrigin, context_, origin)); |
| 86 } | 92 } |
| 87 | 93 |
| 88 scoped_refptr<content::SessionStorageNamespace> | 94 scoped_refptr<content::SessionStorageNamespace> |
| 89 DOMStorageContextImpl::RecreateSessionStorage( | 95 DOMStorageContextImpl::RecreateSessionStorage( |
| 90 const std::string& persistent_id) { | 96 const std::string& persistent_id) { |
| 91 return scoped_refptr<content::SessionStorageNamespace>( | 97 return scoped_refptr<content::SessionStorageNamespace>( |
| 92 new SessionStorageNamespaceImpl(this, persistent_id)); | 98 new SessionStorageNamespaceImpl(this, persistent_id)); |
| 93 } | 99 } |
| 94 | 100 |
| 101 void DOMStorageContextImpl::StartScavengingUnusedSessionStorage() { |
| 102 context_->StartScavengingUnusedSessionStorage(); |
| 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 |