Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_local_storage_helper.cc
blob7aad2f193ac13fe08831d4e51034b7c47a2eb2d8
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
3 // found in the LICENSE file.
5 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
7 #include "base/bind.h"
8 #include "chrome/browser/browsing_data/browsing_data_helper.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/local_storage_usage_info.h"
12 #include "content/public/browser/storage_partition.h"
14 using content::BrowserContext;
15 using content::BrowserThread;
16 using content::DOMStorageContext;
18 BrowsingDataLocalStorageHelper::LocalStorageInfo::LocalStorageInfo(
19 const GURL& origin_url, int64 size, base::Time last_modified)
20 : origin_url(origin_url), size(size), last_modified(last_modified) {}
22 BrowsingDataLocalStorageHelper::LocalStorageInfo::~LocalStorageInfo() {}
24 BrowsingDataLocalStorageHelper::BrowsingDataLocalStorageHelper(Profile* profile)
25 : dom_storage_context_(BrowserContext::GetDefaultStoragePartition(profile)
26 ->GetDOMStorageContext()) {
27 DCHECK(dom_storage_context_);
30 BrowsingDataLocalStorageHelper::~BrowsingDataLocalStorageHelper() {
33 void BrowsingDataLocalStorageHelper::StartFetching(
34 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) {
35 DCHECK_CURRENTLY_ON(BrowserThread::UI);
36 DCHECK(!is_fetching_);
37 DCHECK(!callback.is_null());
39 is_fetching_ = true;
40 completion_callback_ = callback;
41 dom_storage_context_->GetLocalStorageUsage(
42 base::Bind(
43 &BrowsingDataLocalStorageHelper::GetUsageInfoCallback, this));
46 void BrowsingDataLocalStorageHelper::DeleteOrigin(const GURL& origin) {
47 DCHECK_CURRENTLY_ON(BrowserThread::UI);
48 dom_storage_context_->DeleteLocalStorage(origin);
51 void BrowsingDataLocalStorageHelper::GetUsageInfoCallback(
52 const std::vector<content::LocalStorageUsageInfo>& infos) {
53 DCHECK_CURRENTLY_ON(BrowserThread::UI);
55 for (size_t i = 0; i < infos.size(); ++i) {
56 // Non-websafe state is not considered browsing data.
57 const content::LocalStorageUsageInfo& info = infos[i];
58 if (BrowsingDataHelper::HasWebScheme(info.origin)) {
59 local_storage_info_.push_back(
60 LocalStorageInfo(info.origin, info.data_size, info.last_modified));
64 BrowserThread::PostTask(
65 BrowserThread::UI, FROM_HERE,
66 base::Bind(&BrowsingDataLocalStorageHelper::CallCompletionCallback,
67 this));
70 void BrowsingDataLocalStorageHelper::CallCompletionCallback() {
71 DCHECK(is_fetching_);
72 completion_callback_.Run(local_storage_info_);
73 completion_callback_.Reset();
74 is_fetching_ = false;
77 //---------------------------------------------------------
79 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper(
80 Profile* profile)
81 : BrowsingDataLocalStorageHelper(profile) {
84 void CannedBrowsingDataLocalStorageHelper::AddLocalStorage(
85 const GURL& origin) {
86 if (BrowsingDataHelper::HasWebScheme(origin))
87 pending_local_storage_info_.insert(origin);
90 void CannedBrowsingDataLocalStorageHelper::Reset() {
91 pending_local_storage_info_.clear();
94 bool CannedBrowsingDataLocalStorageHelper::empty() const {
95 return pending_local_storage_info_.empty();
98 size_t CannedBrowsingDataLocalStorageHelper::GetLocalStorageCount() const {
99 return pending_local_storage_info_.size();
102 const std::set<GURL>&
103 CannedBrowsingDataLocalStorageHelper::GetLocalStorageInfo() const {
104 return pending_local_storage_info_;
107 void CannedBrowsingDataLocalStorageHelper::StartFetching(
108 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) {
109 DCHECK_CURRENTLY_ON(BrowserThread::UI);
110 DCHECK(!callback.is_null());
112 std::list<LocalStorageInfo> result;
113 for (const GURL& url : pending_local_storage_info_)
114 result.push_back(LocalStorageInfo(url, 0, base::Time()));
116 BrowserThread::PostTask(
117 BrowserThread::UI, FROM_HERE, base::Bind(callback, result));
120 void CannedBrowsingDataLocalStorageHelper::DeleteOrigin(const GURL& origin) {
121 pending_local_storage_info_.erase(origin);
122 BrowsingDataLocalStorageHelper::DeleteOrigin(origin);
125 CannedBrowsingDataLocalStorageHelper::~CannedBrowsingDataLocalStorageHelper() {}