| 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_local_storage_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 8 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/local_storage_usage_info.h" | 11 #include "content/public/browser/local_storage_usage_info.h" |
| 13 #include "content/public/browser/storage_partition.h" | 12 #include "content/public/browser/storage_partition.h" |
| 14 | 13 |
| 15 using content::BrowserContext; | 14 using content::BrowserContext; |
| 16 using content::BrowserThread; | 15 using content::BrowserThread; |
| 17 using content::DOMStorageContext; | 16 using content::DOMStorageContext; |
| 18 | 17 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return pending_local_storage_info_.size(); | 113 return pending_local_storage_info_.size(); |
| 115 } | 114 } |
| 116 | 115 |
| 117 const std::set<GURL>& | 116 const std::set<GURL>& |
| 118 CannedBrowsingDataLocalStorageHelper::GetLocalStorageInfo() const { | 117 CannedBrowsingDataLocalStorageHelper::GetLocalStorageInfo() const { |
| 119 return pending_local_storage_info_; | 118 return pending_local_storage_info_; |
| 120 } | 119 } |
| 121 | 120 |
| 122 void CannedBrowsingDataLocalStorageHelper::StartFetching( | 121 void CannedBrowsingDataLocalStorageHelper::StartFetching( |
| 123 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) { | 122 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) { |
| 124 DCHECK(!is_fetching_); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 125 DCHECK_EQ(false, callback.is_null()); | 124 DCHECK(!callback.is_null()); |
| 126 | 125 |
| 127 is_fetching_ = true; | 126 std::list<LocalStorageInfo> result; |
| 128 completion_callback_ = callback; | 127 for (std::set<GURL>::iterator iter = pending_local_storage_info_.begin(); |
| 128 iter != pending_local_storage_info_.end(); ++iter) { |
| 129 result.push_back( |
| 130 LocalStorageInfo(*iter, 0, base::Time())); |
| 131 } |
| 129 | 132 |
| 130 // We post a task to emulate async fetching behavior. | 133 BrowserThread::PostTask( |
| 131 base::MessageLoop::current()->PostTask( | 134 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); |
| 132 FROM_HERE, | 135 } |
| 133 base::Bind(&CannedBrowsingDataLocalStorageHelper::ConvertPendingInfo, | 136 |
| 134 this)); | 137 void CannedBrowsingDataLocalStorageHelper::DeleteOrigin(const GURL& origin) { |
| 138 pending_local_storage_info_.erase(origin); |
| 139 BrowsingDataLocalStorageHelper::DeleteOrigin(origin); |
| 135 } | 140 } |
| 136 | 141 |
| 137 CannedBrowsingDataLocalStorageHelper::~CannedBrowsingDataLocalStorageHelper() {} | 142 CannedBrowsingDataLocalStorageHelper::~CannedBrowsingDataLocalStorageHelper() {} |
| 138 | |
| 139 void CannedBrowsingDataLocalStorageHelper::ConvertPendingInfo() { | |
| 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 141 local_storage_info_.clear(); | |
| 142 for (std::set<GURL>::iterator iter = pending_local_storage_info_.begin(); | |
| 143 iter != pending_local_storage_info_.end(); ++iter) { | |
| 144 local_storage_info_.push_back( | |
| 145 LocalStorageInfo(*iter, 0, base::Time())); | |
| 146 } | |
| 147 base::MessageLoop::current()->PostTask( | |
| 148 FROM_HERE, | |
| 149 base::Bind(&CannedBrowsingDataLocalStorageHelper::CallCompletionCallback, | |
| 150 this)); | |
| 151 } | |
| OLD | NEW |