Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(953)

Side by Side Diff: chrome/browser/browsing_data/browsing_data_media_license_helper.cc

Issue 2359393002: Adds media license nodes to cookie tree model and cookies view. (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #include "chrome/browser/browsing_data/browsing_data_media_license_helper.h"
6
7 #include <memory>
8 #include <set>
9
10 #include "base/bind.h"
11 #include "base/location.h"
12 #include "base/macros.h"
13 #include "base/sequenced_task_runner.h"
14 #include "chrome/browser/browsing_data/browsing_data_helper.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "storage/browser/fileapi/file_system_context.h"
17 #include "storage/browser/fileapi/file_system_quota_util.h"
18 #include "storage/browser/fileapi/plugin_private_file_system_backend.h"
19 #include "storage/common/fileapi/file_system_types.h"
20
21 using content::BrowserThread;
22
23 namespace {
24
25 // An implementation of the BrowsingDataMediaLicenseHelper interface that
26 // determine data on media licenses in a given |filesystem_context| and
27 // returns a list of MediaLicenseInfo items to a client.
28 class BrowsingDataMediaLicenseHelperImpl
29 : public BrowsingDataMediaLicenseHelper {
30 public:
31 // BrowsingDataMediaLicenseHelper implementation
32 explicit BrowsingDataMediaLicenseHelperImpl(
33 storage::FileSystemContext* filesystem_context);
34 void StartFetching(const FetchCallback& callback) final;
35 void DeleteMediaLicenseOrigin(const GURL& origin) final;
36
37 private:
38 ~BrowsingDataMediaLicenseHelperImpl() final;
39
40 // Enumerates all filesystem files, storing the resulting list into
41 // file_system_file_ for later use. This must be called on the file
42 // task runner.
43 void FetchMediaLicenseInfoOnFileTaskRunner(const FetchCallback& callback);
44
45 // Deletes all file systems associated with |origin|. This must be called on
46 // the file task runner.
47 void DeleteMediaLicenseOriginOnFileTaskRunner(const GURL& origin);
48
49 // Returns the file task runner for the |filesystem_context_|.
50 base::SequencedTaskRunner* file_task_runner() {
51 return filesystem_context_->default_file_task_runner();
52 }
53
54 // Keep a reference to the FileSystemContext object for the current profile
55 // for use on the file task runner.
56 scoped_refptr<storage::FileSystemContext> filesystem_context_;
57
58 DISALLOW_COPY_AND_ASSIGN(BrowsingDataMediaLicenseHelperImpl);
59 };
60
61 BrowsingDataMediaLicenseHelperImpl::BrowsingDataMediaLicenseHelperImpl(
62 storage::FileSystemContext* filesystem_context)
63 : filesystem_context_(filesystem_context) {
64 DCHECK(filesystem_context_.get());
65 }
66
67 BrowsingDataMediaLicenseHelperImpl::~BrowsingDataMediaLicenseHelperImpl() {}
68
69 void BrowsingDataMediaLicenseHelperImpl::StartFetching(
70 const FetchCallback& callback) {
71 DCHECK_CURRENTLY_ON(BrowserThread::UI);
72 DCHECK(!callback.is_null());
73 file_task_runner()->PostTask(
74 FROM_HERE, base::Bind(&BrowsingDataMediaLicenseHelperImpl::
75 FetchMediaLicenseInfoOnFileTaskRunner,
76 this, callback));
77 }
78
79 void BrowsingDataMediaLicenseHelperImpl::DeleteMediaLicenseOrigin(
80 const GURL& origin) {
81 DCHECK_CURRENTLY_ON(BrowserThread::UI);
82 file_task_runner()->PostTask(
83 FROM_HERE, base::Bind(&BrowsingDataMediaLicenseHelperImpl::
84 DeleteMediaLicenseOriginOnFileTaskRunner,
85 this, origin));
86 }
87
88 void BrowsingDataMediaLicenseHelperImpl::FetchMediaLicenseInfoOnFileTaskRunner(
89 const FetchCallback& callback) {
90 DCHECK(file_task_runner()->RunsTasksOnCurrentThread());
91 DCHECK(!callback.is_null());
92
93 const storage::FileSystemType kType = storage::kFileSystemTypePluginPrivate;
94
95 storage::PluginPrivateFileSystemBackend* backend =
96 static_cast<storage::PluginPrivateFileSystemBackend*>(
97 filesystem_context_->GetFileSystemBackend(kType));
98
99 // Determine the set of origins used.
100 std::set<GURL> origins;
101 std::list<MediaLicenseInfo> result;
102 backend->GetOriginsForTypeOnFileTaskRunner(kType, &origins);
103 for (const GURL& origin : origins) {
104 if (!BrowsingDataHelper::HasWebScheme(origin))
105 continue; // Non-websafe state is not considered browsing data.
106
107 int64_t size;
108 base::Time last_modified_time;
109 backend->GetOriginDetailsOnFileTaskRunner(filesystem_context_.get(), origin,
110 &size, &last_modified_time);
111 result.push_back(MediaLicenseInfo(origin, size, last_modified_time));
112 }
113
114 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
115 base::Bind(callback, result));
116 }
117
118 void BrowsingDataMediaLicenseHelperImpl::
119 DeleteMediaLicenseOriginOnFileTaskRunner(const GURL& origin) {
120 DCHECK(file_task_runner()->RunsTasksOnCurrentThread());
121
122 const storage::FileSystemType kType = storage::kFileSystemTypePluginPrivate;
123 storage::FileSystemBackend* backend =
124 filesystem_context_->GetFileSystemBackend(kType);
125 storage::FileSystemQuotaUtil* quota_util = backend->GetQuotaUtil();
126 quota_util->DeleteOriginDataOnFileTaskRunner(
127 filesystem_context_.get(), filesystem_context_->quota_manager_proxy(),
128 origin, kType);
129 }
130
131 } // namespace
132
133 BrowsingDataMediaLicenseHelper::MediaLicenseInfo::MediaLicenseInfo(
134 const GURL& origin,
135 int64_t size,
136 base::Time last_modified_time)
137 : origin(origin), size(size), last_modified_time(last_modified_time) {}
138
139 BrowsingDataMediaLicenseHelper::MediaLicenseInfo::MediaLicenseInfo(
140 const MediaLicenseInfo& other) = default;
141
142 BrowsingDataMediaLicenseHelper::MediaLicenseInfo::~MediaLicenseInfo() {}
143
144 // static
145 BrowsingDataMediaLicenseHelper* BrowsingDataMediaLicenseHelper::Create(
146 storage::FileSystemContext* filesystem_context) {
147 return new BrowsingDataMediaLicenseHelperImpl(filesystem_context);
148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698