Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_local_storage_helper.cc
blob6a5ef06625ef28ea7deb927eb6bbc78d19098b9e
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(
25 Profile* profile)
26 : dom_storage_context_(
27 BrowserContext::GetDefaultStoragePartition(profile)->
28 GetDOMStorageContext()),
29 is_fetching_(false) {
30 DCHECK(dom_storage_context_);
33 BrowsingDataLocalStorageHelper::~BrowsingDataLocalStorageHelper() {
36 void BrowsingDataLocalStorageHelper::StartFetching(
37 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) {
38 DCHECK_CURRENTLY_ON(BrowserThread::UI);
39 DCHECK(!is_fetching_);
40 DCHECK(!callback.is_null());
42 is_fetching_ = true;
43 completion_callback_ = callback;
44 dom_storage_context_->GetLocalStorageUsage(
45 base::Bind(
46 &BrowsingDataLocalStorageHelper::GetUsageInfoCallback, this));
49 void BrowsingDataLocalStorageHelper::DeleteOrigin(const GURL& origin) {
50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
51 dom_storage_context_->DeleteLocalStorage(origin);
54 void BrowsingDataLocalStorageHelper::GetUsageInfoCallback(
55 const std::vector<content::LocalStorageUsageInfo>& infos) {
56 DCHECK_CURRENTLY_ON(BrowserThread::UI);
58 for (size_t i = 0; i < infos.size(); ++i) {
59 // Non-websafe state is not considered browsing data.
60 const content::LocalStorageUsageInfo& info = infos[i];
61 if (BrowsingDataHelper::HasWebScheme(info.origin)) {
62 local_storage_info_.push_back(
63 LocalStorageInfo(info.origin, info.data_size, info.last_modified));
67 BrowserThread::PostTask(
68 BrowserThread::UI, FROM_HERE,
69 base::Bind(&BrowsingDataLocalStorageHelper::CallCompletionCallback,
70 this));
73 void BrowsingDataLocalStorageHelper::CallCompletionCallback() {
74 DCHECK(is_fetching_);
75 completion_callback_.Run(local_storage_info_);
76 completion_callback_.Reset();
77 is_fetching_ = false;
80 //---------------------------------------------------------
82 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper(
83 Profile* profile)
84 : BrowsingDataLocalStorageHelper(profile) {
87 void CannedBrowsingDataLocalStorageHelper::AddLocalStorage(
88 const GURL& origin) {
89 if (BrowsingDataHelper::HasWebScheme(origin))
90 pending_local_storage_info_.insert(origin);
93 void CannedBrowsingDataLocalStorageHelper::Reset() {
94 pending_local_storage_info_.clear();
97 bool CannedBrowsingDataLocalStorageHelper::empty() const {
98 return pending_local_storage_info_.empty();
101 size_t CannedBrowsingDataLocalStorageHelper::GetLocalStorageCount() const {
102 return pending_local_storage_info_.size();
105 const std::set<GURL>&
106 CannedBrowsingDataLocalStorageHelper::GetLocalStorageInfo() const {
107 return pending_local_storage_info_;
110 void CannedBrowsingDataLocalStorageHelper::StartFetching(
111 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) {
112 DCHECK_CURRENTLY_ON(BrowserThread::UI);
113 DCHECK(!callback.is_null());
115 std::list<LocalStorageInfo> result;
116 for (std::set<GURL>::iterator iter = pending_local_storage_info_.begin();
117 iter != pending_local_storage_info_.end(); ++iter) {
118 result.push_back(
119 LocalStorageInfo(*iter, 0, base::Time()));
122 BrowserThread::PostTask(
123 BrowserThread::UI, FROM_HERE, base::Bind(callback, result));
126 void CannedBrowsingDataLocalStorageHelper::DeleteOrigin(const GURL& origin) {
127 pending_local_storage_info_.erase(origin);
128 BrowsingDataLocalStorageHelper::DeleteOrigin(origin);
131 CannedBrowsingDataLocalStorageHelper::~CannedBrowsingDataLocalStorageHelper() {}