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_new.h" | 5 #include "content/browser/dom_storage/dom_storage_context_impl_new.h" |
6 | 6 |
7 #ifdef ENABLE_NEW_DOM_STORAGE_BACKEND | 7 #ifdef ENABLE_NEW_DOM_STORAGE_BACKEND |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
14 #include "webkit/database/database_util.h" | 14 #include "webkit/database/database_util.h" |
15 #include "webkit/dom_storage/dom_storage_area.h" | 15 #include "webkit/dom_storage/dom_storage_area.h" |
16 #include "webkit/dom_storage/dom_storage_context.h" | 16 #include "webkit/dom_storage/dom_storage_context.h" |
17 #include "webkit/dom_storage/dom_storage_task_runner.h" | 17 #include "webkit/dom_storage/dom_storage_task_runner.h" |
18 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
19 | 19 |
20 using content::BrowserThread; | 20 using content::BrowserThread; |
21 using content::DOMStorageContext; | 21 using content::DOMStorageContext; |
22 using dom_storage::DomStorageArea; | 22 using dom_storage::DomStorageArea; |
23 using dom_storage::DomStorageContext; | 23 using dom_storage::DomStorageContext; |
24 using dom_storage::DomStorageTaskRunner; | 24 using dom_storage::DomStorageTaskRunner; |
25 using dom_storage::DomStorageWorkerPoolTaskRunner; | 25 using dom_storage::DomStorageWorkerPoolTaskRunner; |
26 using webkit_database::DatabaseUtil; | 26 using webkit_database::DatabaseUtil; |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 const char kLocalStorageDirectory[] = "Local Storage"; | |
31 | |
32 // TODO(michaeln): Fix the content layer api, FilePaths and | 30 // TODO(michaeln): Fix the content layer api, FilePaths and |
33 // string16 origin_ids are just wrong. Then get rid of | 31 // string16 origin_ids are just wrong. Then get rid of |
34 // this conversion non-sense. Most of the includes are just | 32 // this conversion non-sense. Most of the includes are just |
35 // to support that non-sense. | 33 // to support that non-sense. |
36 | 34 |
37 GURL OriginIdToGURL(const string16& origin_id) { | 35 GURL OriginIdToGURL(const string16& origin_id) { |
38 return DatabaseUtil::GetOriginFromIdentifier(origin_id); | 36 return DatabaseUtil::GetOriginFromIdentifier(origin_id); |
39 } | 37 } |
40 | 38 |
41 FilePath OriginToFullFilePath(const FilePath& directory, | 39 FilePath OriginToFullFilePath(const FilePath& directory, |
(...skipping 18 matching lines...) Expand all Loading... | |
60 const DOMStorageContext::GetAllStorageFilesCallback& callback) { | 58 const DOMStorageContext::GetAllStorageFilesCallback& callback) { |
61 std::vector<DomStorageContext::UsageInfo> infos; | 59 std::vector<DomStorageContext::UsageInfo> infos; |
62 // TODO(michaeln): Actually include the file info too when the | 60 // TODO(michaeln): Actually include the file info too when the |
63 // content layer api is fixed. | 61 // content layer api is fixed. |
64 const bool kDontIncludeFileInfo = false; | 62 const bool kDontIncludeFileInfo = false; |
65 context->GetUsageInfo(&infos, kDontIncludeFileInfo); | 63 context->GetUsageInfo(&infos, kDontIncludeFileInfo); |
66 | 64 |
67 std::vector<FilePath> paths; | 65 std::vector<FilePath> paths; |
68 for (size_t i = 0; i < infos.size(); ++i) { | 66 for (size_t i = 0; i < infos.size(); ++i) { |
69 paths.push_back( | 67 paths.push_back( |
70 OriginToFullFilePath(context->directory(), infos[i].origin)); | 68 OriginToFullFilePath(context->GetLocalStorageDirectory(), |
69 infos[i].origin)); | |
71 } | 70 } |
72 | 71 |
73 reply_loop->PostTask( | 72 reply_loop->PostTask( |
74 FROM_HERE, | 73 FROM_HERE, |
75 base::Bind(&InvokeAllStorageFilesCallbackHelper, | 74 base::Bind(&InvokeAllStorageFilesCallbackHelper, |
76 callback, paths)); | 75 callback, paths)); |
77 } | 76 } |
78 | 77 |
79 } // namespace | 78 } // namespace |
80 | 79 |
81 DOMStorageContextImpl::DOMStorageContextImpl( | 80 DOMStorageContextImpl::DOMStorageContextImpl( |
82 const FilePath& data_path, | 81 const FilePath& data_path, |
83 quota::SpecialStoragePolicy* special_storage_policy) { | 82 quota::SpecialStoragePolicy* special_storage_policy) { |
84 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); | 83 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); |
85 context_ = new dom_storage::DomStorageContext( | 84 context_ = new dom_storage::DomStorageContext( |
86 data_path.empty() ? | 85 data_path, |
michaeln
2012/04/11 20:35:53
Another option is to give the dom_storage class tw
marja
2012/04/12 14:58:11
Alright! Done.
| |
87 data_path : data_path.AppendASCII(kLocalStorageDirectory), | |
88 special_storage_policy, | 86 special_storage_policy, |
89 new DomStorageWorkerPoolTaskRunner( | 87 new DomStorageWorkerPoolTaskRunner( |
90 worker_pool, | 88 worker_pool, |
91 worker_pool->GetNamedSequenceToken("dom_storage_primary"), | 89 worker_pool->GetNamedSequenceToken("dom_storage_primary"), |
92 worker_pool->GetNamedSequenceToken("dom_storage_commit"), | 90 worker_pool->GetNamedSequenceToken("dom_storage_commit"), |
93 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 91 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
94 } | 92 } |
95 | 93 |
96 DOMStorageContextImpl::~DOMStorageContextImpl() { | 94 DOMStorageContextImpl::~DOMStorageContextImpl() { |
97 } | 95 } |
98 | 96 |
99 void DOMStorageContextImpl::GetAllStorageFiles( | 97 void DOMStorageContextImpl::GetAllStorageFiles( |
100 const GetAllStorageFilesCallback& callback) { | 98 const GetAllStorageFilesCallback& callback) { |
101 DCHECK(context_); | 99 DCHECK(context_); |
102 context_->task_runner()->PostShutdownBlockingTask( | 100 context_->task_runner()->PostShutdownBlockingTask( |
103 FROM_HERE, | 101 FROM_HERE, |
104 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 102 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
105 base::Bind(&GetAllStorageFilesHelper, | 103 base::Bind(&GetAllStorageFilesHelper, |
106 base::MessageLoopProxy::current(), | 104 base::MessageLoopProxy::current(), |
107 context_, callback)); | 105 context_, callback)); |
108 } | 106 } |
109 | 107 |
110 FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const { | 108 FilePath DOMStorageContextImpl::GetFilePath(const string16& origin_id) const { |
111 DCHECK(context_); | 109 DCHECK(context_); |
112 return OriginToFullFilePath(context_->directory(), OriginIdToGURL(origin_id)); | 110 return OriginToFullFilePath(context_->GetLocalStorageDirectory(), |
111 OriginIdToGURL(origin_id)); | |
113 } | 112 } |
114 | 113 |
115 void DOMStorageContextImpl::DeleteForOrigin(const string16& origin_id) { | 114 void DOMStorageContextImpl::DeleteForOrigin(const string16& origin_id) { |
116 DCHECK(context_); | 115 DCHECK(context_); |
117 context_->task_runner()->PostShutdownBlockingTask( | 116 context_->task_runner()->PostShutdownBlockingTask( |
118 FROM_HERE, | 117 FROM_HERE, |
119 DomStorageTaskRunner::PRIMARY_SEQUENCE, | 118 DomStorageTaskRunner::PRIMARY_SEQUENCE, |
120 base::Bind(&DomStorageContext::DeleteOrigin, context_, | 119 base::Bind(&DomStorageContext::DeleteOrigin, context_, |
121 OriginIdToGURL(origin_id))); | 120 OriginIdToGURL(origin_id))); |
122 } | 121 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 DCHECK(context_); | 176 DCHECK(context_); |
178 int64 clone_id = context_->AllocateSessionId(); | 177 int64 clone_id = context_->AllocateSessionId(); |
179 context_->task_runner()->PostTask( | 178 context_->task_runner()->PostTask( |
180 FROM_HERE, | 179 FROM_HERE, |
181 base::Bind(&DomStorageContext::CloneSessionNamespace, context_, | 180 base::Bind(&DomStorageContext::CloneSessionNamespace, context_, |
182 existing_namespace_id, clone_id)); | 181 existing_namespace_id, clone_id)); |
183 return clone_id; | 182 return clone_id; |
184 } | 183 } |
185 | 184 |
186 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND | 185 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND |
OLD | NEW |