Fix broken path in extensions/common/PRESUBMIT.py
[chromium-blink-merge.git] / content / browser / dom_storage / dom_storage_context_wrapper.cc
blobfef44e8eff3a91bbc45b2a0e4a24e67ac125ea27
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
7 #include <string>
8 #include <vector>
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/files/file_path.h"
13 #include "base/message_loop/message_loop_proxy.h"
14 #include "content/browser/dom_storage/dom_storage_area.h"
15 #include "content/browser/dom_storage/dom_storage_context_impl.h"
16 #include "content/browser/dom_storage/dom_storage_task_runner.h"
17 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/local_storage_usage_info.h"
20 #include "content/public/browser/session_storage_usage_info.h"
22 namespace content {
23 namespace {
25 const char kLocalStorageDirectory[] = "Local Storage";
26 const char kSessionStorageDirectory[] = "Session Storage";
28 void InvokeLocalStorageUsageCallbackHelper(
29 const DOMStorageContext::GetLocalStorageUsageCallback& callback,
30 const std::vector<LocalStorageUsageInfo>* infos) {
31 callback.Run(*infos);
34 void GetLocalStorageUsageHelper(
35 base::MessageLoopProxy* reply_loop,
36 DOMStorageContextImpl* context,
37 const DOMStorageContext::GetLocalStorageUsageCallback& callback) {
38 std::vector<LocalStorageUsageInfo>* infos =
39 new std::vector<LocalStorageUsageInfo>;
40 context->GetLocalStorageUsage(infos, true);
41 reply_loop->PostTask(
42 FROM_HERE,
43 base::Bind(&InvokeLocalStorageUsageCallbackHelper,
44 callback, base::Owned(infos)));
47 void InvokeSessionStorageUsageCallbackHelper(
48 const DOMStorageContext::GetSessionStorageUsageCallback& callback,
49 const std::vector<SessionStorageUsageInfo>* infos) {
50 callback.Run(*infos);
53 void GetSessionStorageUsageHelper(
54 base::MessageLoopProxy* reply_loop,
55 DOMStorageContextImpl* context,
56 const DOMStorageContext::GetSessionStorageUsageCallback& callback) {
57 std::vector<SessionStorageUsageInfo>* infos =
58 new std::vector<SessionStorageUsageInfo>;
59 context->GetSessionStorageUsage(infos);
60 reply_loop->PostTask(
61 FROM_HERE,
62 base::Bind(&InvokeSessionStorageUsageCallbackHelper,
63 callback, base::Owned(infos)));
66 } // namespace
68 DOMStorageContextWrapper::DOMStorageContextWrapper(
69 const base::FilePath& data_path,
70 storage::SpecialStoragePolicy* special_storage_policy) {
71 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool();
72 context_ = new DOMStorageContextImpl(
73 data_path.empty() ? data_path
74 : data_path.AppendASCII(kLocalStorageDirectory),
75 data_path.empty() ? data_path
76 : data_path.AppendASCII(kSessionStorageDirectory),
77 special_storage_policy,
78 new DOMStorageWorkerPoolTaskRunner(
79 worker_pool,
80 worker_pool->GetNamedSequenceToken("dom_storage_primary"),
81 worker_pool->GetNamedSequenceToken("dom_storage_commit"),
82 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)
83 .get()));
86 DOMStorageContextWrapper::~DOMStorageContextWrapper() {
89 void DOMStorageContextWrapper::GetLocalStorageUsage(
90 const GetLocalStorageUsageCallback& callback) {
91 DCHECK(context_.get());
92 context_->task_runner()
93 ->PostShutdownBlockingTask(FROM_HERE,
94 DOMStorageTaskRunner::PRIMARY_SEQUENCE,
95 base::Bind(&GetLocalStorageUsageHelper,
96 base::MessageLoopProxy::current(),
97 context_,
98 callback));
101 void DOMStorageContextWrapper::GetSessionStorageUsage(
102 const GetSessionStorageUsageCallback& callback) {
103 DCHECK(context_.get());
104 context_->task_runner()
105 ->PostShutdownBlockingTask(FROM_HERE,
106 DOMStorageTaskRunner::PRIMARY_SEQUENCE,
107 base::Bind(&GetSessionStorageUsageHelper,
108 base::MessageLoopProxy::current(),
109 context_,
110 callback));
113 void DOMStorageContextWrapper::DeleteLocalStorage(const GURL& origin) {
114 DCHECK(context_.get());
115 context_->task_runner()->PostShutdownBlockingTask(
116 FROM_HERE,
117 DOMStorageTaskRunner::PRIMARY_SEQUENCE,
118 base::Bind(&DOMStorageContextImpl::DeleteLocalStorage, context_, origin));
121 void DOMStorageContextWrapper::DeleteSessionStorage(
122 const SessionStorageUsageInfo& usage_info) {
123 DCHECK(context_.get());
124 context_->task_runner()->PostShutdownBlockingTask(
125 FROM_HERE,
126 DOMStorageTaskRunner::PRIMARY_SEQUENCE,
127 base::Bind(&DOMStorageContextImpl::DeleteSessionStorage,
128 context_, usage_info));
131 void DOMStorageContextWrapper::SetSaveSessionStorageOnDisk() {
132 DCHECK(context_.get());
133 context_->SetSaveSessionStorageOnDisk();
136 scoped_refptr<SessionStorageNamespace>
137 DOMStorageContextWrapper::RecreateSessionStorage(
138 const std::string& persistent_id) {
139 return scoped_refptr<SessionStorageNamespace>(
140 new SessionStorageNamespaceImpl(this, persistent_id));
143 void DOMStorageContextWrapper::StartScavengingUnusedSessionStorage() {
144 DCHECK(context_.get());
145 context_->task_runner()->PostShutdownBlockingTask(
146 FROM_HERE,
147 DOMStorageTaskRunner::PRIMARY_SEQUENCE,
148 base::Bind(&DOMStorageContextImpl::StartScavengingUnusedSessionStorage,
149 context_));
152 void DOMStorageContextWrapper::SetForceKeepSessionState() {
153 DCHECK(context_.get());
154 context_->task_runner()->PostShutdownBlockingTask(
155 FROM_HERE,
156 DOMStorageTaskRunner::PRIMARY_SEQUENCE,
157 base::Bind(&DOMStorageContextImpl::SetForceKeepSessionState, context_));
160 void DOMStorageContextWrapper::Shutdown() {
161 DCHECK(context_.get());
162 context_->task_runner()->PostShutdownBlockingTask(
163 FROM_HERE,
164 DOMStorageTaskRunner::PRIMARY_SEQUENCE,
165 base::Bind(&DOMStorageContextImpl::Shutdown, context_));
168 void DOMStorageContextWrapper::Flush() {
169 DCHECK(context_.get());
170 context_->task_runner()->PostShutdownBlockingTask(
171 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE,
172 base::Bind(&DOMStorageContextImpl::Flush, context_));
175 } // namespace content