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) { |
52 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); | 53 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( | 54 context_ = new dom_storage::DomStorageContext( |
56 data_path.empty() ? | 55 data_path.empty() ? |
57 data_path : data_path.AppendASCII(kLocalStorageDirectory), | 56 data_path : data_path.AppendASCII(kLocalStorageDirectory), |
58 FilePath(), // Empty session storage directory. | 57 data_path.empty() ? |
58 data_path : data_path.AppendASCII(kSessionStorageDirectory), | |
jam
2012/07/12 18:27:38
nit: indent
marja
2012/07/13 09:05:17
Done.
| |
59 special_storage_policy, | 59 special_storage_policy, |
60 new DomStorageWorkerPoolTaskRunner( | 60 new DomStorageWorkerPoolTaskRunner( |
61 worker_pool, | 61 worker_pool, |
62 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | 62 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
63 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | 63 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
64 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 64 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
65 } | 65 } |
66 | 66 |
67 DOMStorageContextImpl::~DOMStorageContextImpl() { | 67 DOMStorageContextImpl::~DOMStorageContextImpl() { |
68 } | 68 } |
69 | 69 |
70 void DOMStorageContextImpl::GetUsageInfo(const GetUsageInfoCallback& callback) { | 70 void DOMStorageContextImpl::GetUsageInfo(const GetUsageInfoCallback& callback) { |
71 DCHECK(context_); | 71 DCHECK(context_); |
72 context_->task_runner()->PostShutdownBlockingTask( | 72 context_->task_runner()->PostShutdownBlockingTask( |
73 FROM_HERE, | 73 FROM_HERE, |
74 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 74 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
75 base::Bind(&GetUsageInfoHelper, | 75 base::Bind(&GetUsageInfoHelper, |
76 base::MessageLoopProxy::current(), | 76 base::MessageLoopProxy::current(), |
77 context_, callback)); | 77 context_, callback)); |
78 } | 78 } |
79 | 79 |
80 void DOMStorageContextImpl::DeleteOrigin(const GURL& origin) { | 80 void DOMStorageContextImpl::DeleteOrigin(const GURL& origin) { |
81 DCHECK(context_); | 81 DCHECK(context_); |
82 context_->task_runner()->PostShutdownBlockingTask( | 82 context_->task_runner()->PostShutdownBlockingTask( |
83 FROM_HERE, | 83 FROM_HERE, |
84 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 84 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
85 base::Bind(&DomStorageContext::DeleteOrigin, context_, origin)); | 85 base::Bind(&DomStorageContext::DeleteOrigin, context_, origin)); |
86 } | 86 } |
87 | 87 |
88 void DOMStorageContextImpl::SetSaveSessionStorageOnDisk() { | |
89 DCHECK(context_); | |
90 context_->SetSaveSessionStorageOnDisk(); | |
91 } | |
92 | |
88 scoped_refptr<content::SessionStorageNamespace> | 93 scoped_refptr<content::SessionStorageNamespace> |
89 DOMStorageContextImpl::RecreateSessionStorage( | 94 DOMStorageContextImpl::RecreateSessionStorage( |
90 const std::string& persistent_id) { | 95 const std::string& persistent_id) { |
91 return scoped_refptr<content::SessionStorageNamespace>( | 96 return scoped_refptr<content::SessionStorageNamespace>( |
92 new SessionStorageNamespaceImpl(this, persistent_id)); | 97 new SessionStorageNamespaceImpl(this, persistent_id)); |
93 } | 98 } |
94 | 99 |
100 void DOMStorageContextImpl::StartScavengingUnusedSessionStorage() { | |
101 DCHECK(context_); | |
102 context_->task_runner()->PostShutdownBlockingTask( | |
103 FROM_HERE, | |
104 DomStorageTaskRunner::PRIMARY_SEQUENCE, | |
105 base::Bind(&DomStorageContext::StartScavengingUnusedSessionStorage, | |
106 context_)); | |
107 } | |
108 | |
95 void DOMStorageContextImpl::PurgeMemory() { | 109 void DOMStorageContextImpl::PurgeMemory() { |
96 DCHECK(context_); | 110 DCHECK(context_); |
97 context_->task_runner()->PostShutdownBlockingTask( | 111 context_->task_runner()->PostShutdownBlockingTask( |
98 FROM_HERE, | 112 FROM_HERE, |
99 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 113 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
100 base::Bind(&DomStorageContext::PurgeMemory, context_)); | 114 base::Bind(&DomStorageContext::PurgeMemory, context_)); |
101 } | 115 } |
102 | 116 |
103 void DOMStorageContextImpl::SetForceKeepSessionState() { | 117 void DOMStorageContextImpl::SetForceKeepSessionState() { |
104 DCHECK(context_); | 118 DCHECK(context_); |
105 context_->task_runner()->PostShutdownBlockingTask( | 119 context_->task_runner()->PostShutdownBlockingTask( |
106 FROM_HERE, | 120 FROM_HERE, |
107 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 121 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
108 base::Bind(&DomStorageContext::SetForceKeepSessionState, context_)); | 122 base::Bind(&DomStorageContext::SetForceKeepSessionState, context_)); |
109 } | 123 } |
110 | 124 |
111 void DOMStorageContextImpl::Shutdown() { | 125 void DOMStorageContextImpl::Shutdown() { |
112 DCHECK(context_); | 126 DCHECK(context_); |
113 context_->task_runner()->PostShutdownBlockingTask( | 127 context_->task_runner()->PostShutdownBlockingTask( |
114 FROM_HERE, | 128 FROM_HERE, |
115 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 129 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
116 base::Bind(&DomStorageContext::Shutdown, context_)); | 130 base::Bind(&DomStorageContext::Shutdown, context_)); |
117 } | 131 } |
OLD | NEW |