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 "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 16 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
17 #include "chrome/browser/profiles/profile.h" | |
18 #include "content/public/browser/browser_context.h" | |
17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/indexed_db_context.h" | 20 #include "content/public/browser/indexed_db_context.h" |
19 #include "webkit/browser/database/database_util.h" | 21 #include "content/public/browser/storage_partition.h" |
20 | 22 |
23 using content::BrowserContext; | |
21 using content::BrowserThread; | 24 using content::BrowserThread; |
22 using content::IndexedDBContext; | 25 using content::IndexedDBContext; |
23 using content::IndexedDBInfo; | 26 using content::IndexedDBInfo; |
24 using webkit_database::DatabaseUtil; | |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 class BrowsingDataIndexedDBHelperImpl : public BrowsingDataIndexedDBHelper { | 30 class BrowsingDataIndexedDBHelperImpl : public BrowsingDataIndexedDBHelper { |
29 public: | 31 public: |
30 explicit BrowsingDataIndexedDBHelperImpl( | 32 explicit BrowsingDataIndexedDBHelperImpl( |
31 IndexedDBContext* indexed_db_context); | 33 IndexedDBContext* indexed_db_context); |
32 | 34 |
33 virtual void StartFetching( | 35 virtual void StartFetching( |
34 const base::Callback<void(const std::list<IndexedDBInfo>&)>& | 36 const base::Callback<void(const std::list<IndexedDBInfo>&)>& |
35 callback) OVERRIDE; | 37 callback) OVERRIDE; |
36 virtual void DeleteIndexedDB(const GURL& origin) OVERRIDE; | 38 virtual void DeleteIndexedDB(const GURL& origin) OVERRIDE; |
37 | 39 |
38 private: | 40 private: |
39 virtual ~BrowsingDataIndexedDBHelperImpl(); | 41 virtual ~BrowsingDataIndexedDBHelperImpl(); |
40 | 42 |
41 // Enumerates all indexed database files in the WEBKIT thread. | 43 // Enumerates all indexed database files in the IndexedDB thread. |
42 void FetchIndexedDBInfoInWebKitThread(); | 44 void FetchIndexedDBInfoInIndexedDBThread(); |
43 // Notifies the completion callback in the UI thread. | 45 // Notifies the completion callback in the UI thread. |
44 void NotifyInUIThread(); | 46 void NotifyInUIThread(); |
45 // Delete a single indexed database in the WEBKIT thread. | 47 // Delete a single indexed database in the IndexedDB thread. |
46 void DeleteIndexedDBInWebKitThread(const GURL& origin); | 48 void DeleteIndexedDBInIndexedDBThread(const GURL& origin); |
47 | 49 |
48 scoped_refptr<IndexedDBContext> indexed_db_context_; | 50 scoped_refptr<IndexedDBContext> indexed_db_context_; |
49 | 51 |
50 // Access to |indexed_db_info_| is triggered indirectly via the UI thread and | 52 // Access to |indexed_db_info_| is triggered indirectly via the UI thread and |
51 // guarded by |is_fetching_|. This means |indexed_db_info_| is only accessed | 53 // guarded by |is_fetching_|. This means |indexed_db_info_| is only accessed |
52 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on | 54 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on |
53 // the UI thread. | 55 // the UI thread. |
54 // In the context of this class |indexed_db_info_| is only accessed on the | 56 // In the context of this class |indexed_db_info_| is only accessed on the |
55 // WEBKIT thread. | 57 // context's IndexedDB thread. |
56 std::list<IndexedDBInfo> indexed_db_info_; | 58 std::list<IndexedDBInfo> indexed_db_info_; |
57 | 59 |
58 // This only mutates on the UI thread. | 60 // This only mutates on the UI thread. |
59 base::Callback<void(const std::list<IndexedDBInfo>&)> completion_callback_; | 61 base::Callback<void(const std::list<IndexedDBInfo>&)> completion_callback_; |
60 | 62 |
61 // Indicates whether or not we're currently fetching information: | 63 // Indicates whether or not we're currently fetching information: |
62 // it's true when StartFetching() is called in the UI thread, and it's reset | 64 // it's true when StartFetching() is called in the UI thread, and it's reset |
63 // after we notified the callback in the UI thread. | 65 // after we notified the callback in the UI thread. |
64 // This only mutates on the UI thread. | 66 // This only mutates on the UI thread. |
65 bool is_fetching_; | 67 bool is_fetching_; |
(...skipping 12 matching lines...) Expand all Loading... | |
78 } | 80 } |
79 | 81 |
80 void BrowsingDataIndexedDBHelperImpl::StartFetching( | 82 void BrowsingDataIndexedDBHelperImpl::StartFetching( |
81 const base::Callback<void(const std::list<IndexedDBInfo>&)>& callback) { | 83 const base::Callback<void(const std::list<IndexedDBInfo>&)>& callback) { |
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
83 DCHECK(!is_fetching_); | 85 DCHECK(!is_fetching_); |
84 DCHECK_EQ(false, callback.is_null()); | 86 DCHECK_EQ(false, callback.is_null()); |
85 | 87 |
86 is_fetching_ = true; | 88 is_fetching_ = true; |
87 completion_callback_ = callback; | 89 completion_callback_ = callback; |
88 BrowserThread::PostTask( | 90 indexed_db_context_->TaskRunner()->PostTask( |
89 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 91 FROM_HERE, |
90 base::Bind( | 92 base::Bind( |
91 &BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread, | 93 &BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInIndexedDBThread, |
92 this)); | 94 this)); |
93 } | 95 } |
94 | 96 |
95 void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDB( | 97 void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDB( |
96 const GURL& origin) { | 98 const GURL& origin) { |
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
98 BrowserThread::PostTask( | 100 indexed_db_context_->TaskRunner()->PostTask( |
99 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 101 FROM_HERE, |
100 base::Bind( | 102 base::Bind( |
101 &BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBInWebKitThread, this, | 103 &BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBInIndexedDBThread, |
104 this, | |
102 origin)); | 105 origin)); |
103 } | 106 } |
104 | 107 |
105 void BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread() { | 108 void BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInIndexedDBThread() { |
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 109 DCHECK(indexed_db_context_->OnIndexedDBThread()); |
107 std::vector<IndexedDBInfo> origins = indexed_db_context_->GetAllOriginsInfo(); | 110 std::vector<IndexedDBInfo> origins = indexed_db_context_->GetAllOriginsInfo(); |
108 for (std::vector<IndexedDBInfo>::const_iterator iter = origins.begin(); | 111 for (std::vector<IndexedDBInfo>::const_iterator iter = origins.begin(); |
109 iter != origins.end(); ++iter) { | 112 iter != origins.end(); ++iter) { |
110 const IndexedDBInfo& origin = *iter; | 113 const IndexedDBInfo& origin = *iter; |
111 if (!BrowsingDataHelper::HasWebScheme(origin.origin_)) | 114 if (!BrowsingDataHelper::HasWebScheme(origin.origin_)) |
112 continue; // Non-websafe state is not considered browsing data. | 115 continue; // Non-websafe state is not considered browsing data. |
113 | 116 |
114 indexed_db_info_.push_back(origin); | 117 indexed_db_info_.push_back(origin); |
115 } | 118 } |
116 | 119 |
117 BrowserThread::PostTask( | 120 BrowserThread::PostTask( |
118 BrowserThread::UI, FROM_HERE, | 121 BrowserThread::UI, FROM_HERE, |
119 base::Bind(&BrowsingDataIndexedDBHelperImpl::NotifyInUIThread, this)); | 122 base::Bind(&BrowsingDataIndexedDBHelperImpl::NotifyInUIThread, this)); |
120 } | 123 } |
121 | 124 |
122 void BrowsingDataIndexedDBHelperImpl::NotifyInUIThread() { | 125 void BrowsingDataIndexedDBHelperImpl::NotifyInUIThread() { |
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
124 DCHECK(is_fetching_); | 127 DCHECK(is_fetching_); |
125 completion_callback_.Run(indexed_db_info_); | 128 completion_callback_.Run(indexed_db_info_); |
126 completion_callback_.Reset(); | 129 completion_callback_.Reset(); |
127 is_fetching_ = false; | 130 is_fetching_ = false; |
128 } | 131 } |
129 | 132 |
130 void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBInWebKitThread( | 133 void BrowsingDataIndexedDBHelperImpl::DeleteIndexedDBInIndexedDBThread( |
131 const GURL& origin) { | 134 const GURL& origin) { |
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 135 DCHECK(indexed_db_context_->OnIndexedDBThread()); |
133 indexed_db_context_->DeleteForOrigin(origin); | 136 indexed_db_context_->DeleteForOrigin(origin); |
134 } | 137 } |
135 | 138 |
136 } // namespace | 139 } // namespace |
137 | 140 |
138 | 141 |
139 // static | 142 // static |
140 BrowsingDataIndexedDBHelper* BrowsingDataIndexedDBHelper::Create( | 143 BrowsingDataIndexedDBHelper* BrowsingDataIndexedDBHelper::Create( |
141 IndexedDBContext* indexed_db_context) { | 144 IndexedDBContext* indexed_db_context) { |
142 return new BrowsingDataIndexedDBHelperImpl(indexed_db_context); | 145 return new BrowsingDataIndexedDBHelperImpl(indexed_db_context); |
(...skipping 10 matching lines...) Expand all Loading... | |
153 PendingIndexedDBInfo::~PendingIndexedDBInfo() { | 156 PendingIndexedDBInfo::~PendingIndexedDBInfo() { |
154 } | 157 } |
155 | 158 |
156 bool CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo::operator<( | 159 bool CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo::operator<( |
157 const PendingIndexedDBInfo& other) const { | 160 const PendingIndexedDBInfo& other) const { |
158 if (origin == other.origin) | 161 if (origin == other.origin) |
159 return name < other.name; | 162 return name < other.name; |
160 return origin < other.origin; | 163 return origin < other.origin; |
161 } | 164 } |
162 | 165 |
163 CannedBrowsingDataIndexedDBHelper::CannedBrowsingDataIndexedDBHelper() | 166 CannedBrowsingDataIndexedDBHelper::CannedBrowsingDataIndexedDBHelper( |
164 : is_fetching_(false) { | 167 Profile* profile) |
165 } | 168 : profile_(profile), |
169 indexed_db_context_(BrowserContext::GetDefaultStoragePartition(profile) | |
170 ->GetIndexedDBContext()), | |
171 is_fetching_(false) {} | |
166 | 172 |
167 CannedBrowsingDataIndexedDBHelper::~CannedBrowsingDataIndexedDBHelper() {} | 173 CannedBrowsingDataIndexedDBHelper::~CannedBrowsingDataIndexedDBHelper() {} |
168 | 174 |
169 CannedBrowsingDataIndexedDBHelper* CannedBrowsingDataIndexedDBHelper::Clone() { | 175 CannedBrowsingDataIndexedDBHelper* CannedBrowsingDataIndexedDBHelper::Clone() { |
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
171 CannedBrowsingDataIndexedDBHelper* clone = | 177 CannedBrowsingDataIndexedDBHelper* clone = |
172 new CannedBrowsingDataIndexedDBHelper(); | 178 new CannedBrowsingDataIndexedDBHelper(profile_); |
173 | 179 |
174 base::AutoLock auto_lock(lock_); | 180 base::AutoLock auto_lock(lock_); |
175 clone->pending_indexed_db_info_ = pending_indexed_db_info_; | 181 clone->pending_indexed_db_info_ = pending_indexed_db_info_; |
176 clone->indexed_db_info_ = indexed_db_info_; | 182 clone->indexed_db_info_ = indexed_db_info_; |
177 return clone; | 183 return clone; |
178 } | 184 } |
179 | 185 |
180 void CannedBrowsingDataIndexedDBHelper::AddIndexedDB( | 186 void CannedBrowsingDataIndexedDBHelper::AddIndexedDB( |
181 const GURL& origin, const string16& name) { | 187 const GURL& origin, const string16& name) { |
182 if (!BrowsingDataHelper::HasWebScheme(origin)) | 188 if (!BrowsingDataHelper::HasWebScheme(origin)) |
(...skipping 26 matching lines...) Expand all Loading... | |
209 } | 215 } |
210 | 216 |
211 void CannedBrowsingDataIndexedDBHelper::StartFetching( | 217 void CannedBrowsingDataIndexedDBHelper::StartFetching( |
212 const base::Callback<void(const std::list<IndexedDBInfo>&)>& callback) { | 218 const base::Callback<void(const std::list<IndexedDBInfo>&)>& callback) { |
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
214 DCHECK(!is_fetching_); | 220 DCHECK(!is_fetching_); |
215 DCHECK_EQ(false, callback.is_null()); | 221 DCHECK_EQ(false, callback.is_null()); |
216 | 222 |
217 is_fetching_ = true; | 223 is_fetching_ = true; |
218 completion_callback_ = callback; | 224 completion_callback_ = callback; |
219 BrowserThread::PostTask( | 225 indexed_db_context_->TaskRunner()->PostTask( |
220 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 226 FROM_HERE, |
221 base::Bind( | 227 base::Bind(&CannedBrowsingDataIndexedDBHelper:: |
222 &CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread, | 228 ConvertPendingInfoInIndexedDBThread, |
223 this)); | 229 this)); |
224 } | 230 } |
225 | 231 |
226 void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread() { | 232 void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInIndexedDBThread() { |
227 base::AutoLock auto_lock(lock_); | 233 base::AutoLock auto_lock(lock_); |
228 indexed_db_info_.clear(); | 234 indexed_db_info_.clear(); |
229 for (std::set<PendingIndexedDBInfo>::const_iterator | 235 for (std::set<PendingIndexedDBInfo>::const_iterator |
230 pending_info = pending_indexed_db_info_.begin(); | 236 pending_info = pending_indexed_db_info_.begin(); |
231 pending_info != pending_indexed_db_info_.end(); ++pending_info) { | 237 pending_info != pending_indexed_db_info_.end(); ++pending_info) { |
232 IndexedDBInfo info(pending_info->origin, 0, base::Time(), base::FilePath()); | 238 IndexedDBInfo info(pending_info->origin, 0, base::Time(), base::FilePath()); |
michaeln
2013/06/21 19:35:57
Not sure there's a need for a dependency on a Prof
jsbell
2013/06/21 20:39:37
Yeah, I remember your feedback from the previous C
jsbell
2013/06/24 17:50:43
Digging through history, it looks like this plumbi
| |
233 indexed_db_info_.push_back(info); | 239 indexed_db_info_.push_back(info); |
234 } | 240 } |
235 | 241 |
236 BrowserThread::PostTask( | 242 BrowserThread::PostTask( |
237 BrowserThread::UI, FROM_HERE, | 243 BrowserThread::UI, FROM_HERE, |
238 base::Bind(&CannedBrowsingDataIndexedDBHelper::NotifyInUIThread, this)); | 244 base::Bind(&CannedBrowsingDataIndexedDBHelper::NotifyInUIThread, this)); |
239 } | 245 } |
240 | 246 |
241 void CannedBrowsingDataIndexedDBHelper::NotifyInUIThread() { | 247 void CannedBrowsingDataIndexedDBHelper::NotifyInUIThread() { |
242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
243 DCHECK(is_fetching_); | 249 DCHECK(is_fetching_); |
244 | 250 |
245 completion_callback_.Run(indexed_db_info_); | 251 completion_callback_.Run(indexed_db_info_); |
246 completion_callback_.Reset(); | 252 completion_callback_.Reset(); |
247 is_fetching_ = false; | 253 is_fetching_ = false; |
248 } | 254 } |
OLD | NEW |