| 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 { | 26 namespace { |
| 27 | 27 |
| 28 const char kLocalStorageDirectory[] = "Local Storage"; | 28 const char kLocalStorageDirectory[] = "Local Storage"; |
| 29 | 29 |
| 30 void InvokeUsageInfoCallbackHelper( |
| 31 const DOMStorageContext::GetUsageInfoCallback& callback, |
| 32 const std::vector<DomStorageContext::UsageInfo>* infos) { |
| 33 callback.Run(*infos); |
| 34 } |
| 35 |
| 36 void GetUsageInfoHelper( |
| 37 base::MessageLoopProxy* reply_loop, |
| 38 DomStorageContext* context, |
| 39 const DOMStorageContext::GetUsageInfoCallback& callback) { |
| 40 std::vector<DomStorageContext::UsageInfo>* infos = |
| 41 new std::vector<DomStorageContext::UsageInfo>; |
| 42 context->GetUsageInfo(infos, true); |
| 43 reply_loop->PostTask( |
| 44 FROM_HERE, |
| 45 base::Bind(&InvokeUsageInfoCallbackHelper, |
| 46 callback, base::Owned(infos))); |
| 47 } |
| 48 |
| 30 // TODO(michaeln): Fix the content layer api, FilePaths and | 49 // TODO(michaeln): Fix the content layer api, FilePaths and |
| 31 // string16 origin_ids are just wrong. Then get rid of | 50 // string16 origin_ids are just wrong. Then get rid of |
| 32 // this conversion non-sense. Most of the includes are just | 51 // this conversion non-sense. Most of the includes are just |
| 33 // to support that non-sense. | 52 // to support that non-sense. |
| 34 | 53 |
| 35 GURL OriginIdToGURL(const string16& origin_id) { | 54 GURL OriginIdToGURL(const string16& origin_id) { |
| 36 return DatabaseUtil::GetOriginFromIdentifier(origin_id); | 55 return DatabaseUtil::GetOriginFromIdentifier(origin_id); |
| 37 } | 56 } |
| 38 | 57 |
| 39 FilePath OriginToFullFilePath(const FilePath& directory, | 58 FilePath OriginToFullFilePath(const FilePath& directory, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 new DomStorageWorkerPoolTaskRunner( | 110 new DomStorageWorkerPoolTaskRunner( |
| 92 worker_pool, | 111 worker_pool, |
| 93 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | 112 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
| 94 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | 113 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
| 95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 114 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
| 96 } | 115 } |
| 97 | 116 |
| 98 DOMStorageContextImpl::~DOMStorageContextImpl() { | 117 DOMStorageContextImpl::~DOMStorageContextImpl() { |
| 99 } | 118 } |
| 100 | 119 |
| 120 void DOMStorageContextImpl::GetUsageInfo(const GetUsageInfoCallback& callback) { |
| 121 DCHECK(context_); |
| 122 context_->task_runner()->PostShutdownBlockingTask( |
| 123 FROM_HERE, |
| 124 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 125 base::Bind(&GetUsageInfoHelper, |
| 126 base::MessageLoopProxy::current(), |
| 127 context_, callback)); |
| 128 } |
| 129 |
| 130 void DOMStorageContextImpl::DeleteOrigin(const GURL& origin) { |
| 131 DCHECK(context_); |
| 132 context_->task_runner()->PostShutdownBlockingTask( |
| 133 FROM_HERE, |
| 134 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 135 base::Bind(&DomStorageContext::DeleteOrigin, context_, origin)); |
| 136 } |
| 137 |
| 101 void DOMStorageContextImpl::GetAllStorageFiles( | 138 void DOMStorageContextImpl::GetAllStorageFiles( |
| 102 const GetAllStorageFilesCallback& callback) { | 139 const GetAllStorageFilesCallback& callback) { |
| 103 DCHECK(context_); | 140 DCHECK(context_); |
| 104 context_->task_runner()->PostShutdownBlockingTask( | 141 context_->task_runner()->PostShutdownBlockingTask( |
| 105 FROM_HERE, | 142 FROM_HERE, |
| 106 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 143 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
| 107 base::Bind(&GetAllStorageFilesHelper, | 144 base::Bind(&GetAllStorageFilesHelper, |
| 108 base::MessageLoopProxy::current(), | 145 base::MessageLoopProxy::current(), |
| 109 context_, callback)); | 146 context_, callback)); |
| 110 } | 147 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 int64 DOMStorageContextImpl::LeakyCloneSessionStorage( | 215 int64 DOMStorageContextImpl::LeakyCloneSessionStorage( |
| 179 int64 existing_namespace_id) { | 216 int64 existing_namespace_id) { |
| 180 DCHECK(context_); | 217 DCHECK(context_); |
| 181 int64 clone_id = context_->AllocateSessionId(); | 218 int64 clone_id = context_->AllocateSessionId(); |
| 182 context_->task_runner()->PostTask( | 219 context_->task_runner()->PostTask( |
| 183 FROM_HERE, | 220 FROM_HERE, |
| 184 base::Bind(&DomStorageContext::CloneSessionNamespace, context_, | 221 base::Bind(&DomStorageContext::CloneSessionNamespace, context_, |
| 185 existing_namespace_id, clone_id)); | 222 existing_namespace_id, clone_id)); |
| 186 return clone_id; | 223 return clone_id; |
| 187 } | 224 } |
| OLD | NEW |