| 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/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 12 #include "webkit/database/database_util.h" | 12 #include "webkit/database/database_util.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 #include "webkit/glue/webkit_glue.h" | 16 #include "webkit/glue/webkit_glue.h" |
| 17 | 17 |
| 18 using content::BrowserThread; | 18 using content::BrowserThread; |
| 19 using content::DOMStorageContext; | 19 using content::DOMStorageContext; |
| 20 using dom_storage::DomStorageArea; | 20 using dom_storage::DomStorageArea; |
| 21 using dom_storage::DomStorageContext; | 21 using dom_storage::DomStorageContext; |
| 22 using dom_storage::DomStorageTaskRunner; | 22 using dom_storage::DomStorageTaskRunner; |
| 23 using dom_storage::DomStorageWorkerPoolTaskRunner; | 23 using dom_storage::DomStorageWorkerPoolTaskRunner; |
| 24 using webkit_database::DatabaseUtil; | 24 using webkit_database::DatabaseUtil; |
| 25 | 25 |
| 26 namespace content { |
| 27 DOMStorageContext::UsageInfo::UsageInfo() : data_size(0) {} |
| 28 DOMStorageContext::UsageInfo::~UsageInfo() {} |
| 29 } |
| 30 |
| 26 namespace { | 31 namespace { |
| 27 | 32 |
| 28 const char kLocalStorageDirectory[] = "Local Storage"; | 33 const char kLocalStorageDirectory[] = "Local Storage"; |
| 29 | 34 |
| 35 void InvokeUsageInfoCallbackHelper( |
| 36 const DOMStorageContext::GetUsageInfoCallback& callback, |
| 37 const std::vector<DOMStorageContext::UsageInfo>* infos) { |
| 38 callback.Run(*infos); |
| 39 } |
| 40 |
| 41 void GetUsageInfoHelper( |
| 42 base::MessageLoopProxy* reply_loop, |
| 43 DomStorageContext* context, |
| 44 const DOMStorageContext::GetUsageInfoCallback& callback) { |
| 45 std::vector<DomStorageContext::UsageInfo> infos; |
| 46 const bool kIncludeFileInfo = true; |
| 47 context->GetUsageInfo(&infos, kIncludeFileInfo); |
| 48 |
| 49 std::vector<DOMStorageContext::UsageInfo>* public_infos = |
| 50 new std::vector<DOMStorageContext::UsageInfo>(infos.size()); |
| 51 for (size_t i = 0; i < infos.size(); ++i) { |
| 52 (*public_infos)[i].origin = infos[i].origin; |
| 53 (*public_infos)[i].data_size = infos[i].data_size; |
| 54 (*public_infos)[i].last_modified = infos[i].last_modified; |
| 55 } |
| 56 |
| 57 reply_loop->PostTask( |
| 58 FROM_HERE, |
| 59 base::Bind(&InvokeUsageInfoCallbackHelper, |
| 60 callback, base::Owned(public_infos))); |
| 61 } |
| 62 |
| 30 // TODO(michaeln): Fix the content layer api, FilePaths and | 63 // TODO(michaeln): Fix the content layer api, FilePaths and |
| 31 // string16 origin_ids are just wrong. Then get rid of | 64 // string16 origin_ids are just wrong. Then get rid of |
| 32 // this conversion non-sense. Most of the includes are just | 65 // this conversion non-sense. Most of the includes are just |
| 33 // to support that non-sense. | 66 // to support that non-sense. |
| 34 | 67 |
| 35 GURL OriginIdToGURL(const string16& origin_id) { | 68 GURL OriginIdToGURL(const string16& origin_id) { |
| 36 return DatabaseUtil::GetOriginFromIdentifier(origin_id); | 69 return DatabaseUtil::GetOriginFromIdentifier(origin_id); |
| 37 } | 70 } |
| 38 | 71 |
| 39 FilePath OriginToFullFilePath(const FilePath& directory, | 72 FilePath OriginToFullFilePath(const FilePath& directory, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 new DomStorageWorkerPoolTaskRunner( | 124 new DomStorageWorkerPoolTaskRunner( |
| 92 worker_pool, | 125 worker_pool, |
| 93 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | 126 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
| 94 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | 127 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
| 95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 128 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
| 96 } | 129 } |
| 97 | 130 |
| 98 DOMStorageContextImpl::~DOMStorageContextImpl() { | 131 DOMStorageContextImpl::~DOMStorageContextImpl() { |
| 99 } | 132 } |
| 100 | 133 |
| 134 void DOMStorageContextImpl::GetUsageInfo(const GetUsageInfoCallback& callback) { |
| 135 DCHECK(context_); |
| 136 context_->task_runner()->PostShutdownBlockingTask( |
| 137 FROM_HERE, |
| 138 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 139 base::Bind(&GetUsageInfoHelper, |
| 140 base::MessageLoopProxy::current(), |
| 141 context_, callback)); |
| 142 } |
| 143 |
| 144 void DOMStorageContextImpl::DeleteOrigin(const GURL& origin) { |
| 145 DCHECK(context_); |
| 146 context_->task_runner()->PostShutdownBlockingTask( |
| 147 FROM_HERE, |
| 148 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 149 base::Bind(&DomStorageContext::DeleteOrigin, context_, origin)); |
| 150 } |
| 151 |
| 101 void DOMStorageContextImpl::GetAllStorageFiles( | 152 void DOMStorageContextImpl::GetAllStorageFiles( |
| 102 const GetAllStorageFilesCallback& callback) { | 153 const GetAllStorageFilesCallback& callback) { |
| 103 DCHECK(context_); | 154 DCHECK(context_); |
| 104 context_->task_runner()->PostShutdownBlockingTask( | 155 context_->task_runner()->PostShutdownBlockingTask( |
| 105 FROM_HERE, | 156 FROM_HERE, |
| 106 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 157 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 107 base::Bind(&GetAllStorageFilesHelper, | 158 base::Bind(&GetAllStorageFilesHelper, |
| 108 base::MessageLoopProxy::current(), | 159 base::MessageLoopProxy::current(), |
| 109 context_, callback)); | 160 context_, callback)); |
| 110 } | 161 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 int64 DOMStorageContextImpl::LeakyCloneSessionStorage( | 229 int64 DOMStorageContextImpl::LeakyCloneSessionStorage( |
| 179 int64 existing_namespace_id) { | 230 int64 existing_namespace_id) { |
| 180 DCHECK(context_); | 231 DCHECK(context_); |
| 181 int64 clone_id = context_->AllocateSessionId(); | 232 int64 clone_id = context_->AllocateSessionId(); |
| 182 context_->task_runner()->PostTask( | 233 context_->task_runner()->PostTask( |
| 183 FROM_HERE, | 234 FROM_HERE, |
| 184 base::Bind(&DomStorageContext::CloneSessionNamespace, context_, | 235 base::Bind(&DomStorageContext::CloneSessionNamespace, context_, |
| 185 existing_namespace_id, clone_id)); | 236 existing_namespace_id, clone_id)); |
| 186 return clone_id; | 237 return clone_id; |
| 187 } | 238 } |
| OLD | NEW |