Chromium Code Reviews| Index: chrome/browser/browsing_data/media_license_counter.cc |
| diff --git a/chrome/browser/browsing_data/media_license_counter.cc b/chrome/browser/browsing_data/media_license_counter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..53e13060a1b26fa1e37592b51ea9eaf4cd972867 |
| --- /dev/null |
| +++ b/chrome/browser/browsing_data/media_license_counter.cc |
| @@ -0,0 +1,79 @@ |
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/browsing_data/media_license_counter.h" |
| + |
| +#include <stdint.h> |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/storage_partition.h" |
| +#include "storage/browser/fileapi/file_system_context.h" |
| + |
| +using OriginsDeterminedCB = base::Callback<void(std::set<GURL>)>; |
|
xhwang
2016/06/17 06:24:29
pass std::set by const-ref
jrummell
2016/06/21 00:13:44
Done.
|
| + |
| +// Determining the origins must be run on the file task thread. This calls |
| +// |callback| on the main thread with the results. |
| +void CountOriginsOnFileTaskRunner( |
|
xhwang
2016/06/17 06:24:29
put this in an anonymous namespace?
jrummell
2016/06/21 00:13:44
Done.
|
| + scoped_refptr<storage::FileSystemContext> filesystem_context, |
| + OriginsDeterminedCB callback) { |
|
xhwang
2016/06/17 06:24:30
pass callback by const-ref
jrummell
2016/06/21 00:13:44
Done.
|
| + DCHECK(filesystem_context->default_file_task_runner() |
| + ->RunsTasksOnCurrentThread()); |
| + |
| + storage::FileSystemBackend* backend = |
| + filesystem_context->GetFileSystemBackend( |
| + storage::kFileSystemTypePluginPrivate); |
| + storage::FileSystemQuotaUtil* quota_util = backend->GetQuotaUtil(); |
| + |
| + std::set<GURL> origins; |
| + quota_util->GetOriginsForTypeOnFileTaskRunner( |
| + storage::kFileSystemTypePluginPrivate, &origins); |
| + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| + base::Bind(callback, origins)); |
| +} |
| + |
| +MediaLicenseCounter::MediaLicenseResult::MediaLicenseResult( |
| + const MediaLicenseCounter* source, |
| + std::set<GURL> origins) |
| + : FinishedResult(source, origins.size()) { |
| + if (!origins.empty()) |
| + one_origin_ = origins.begin()->GetOrigin().spec(); |
| +} |
| + |
| +MediaLicenseCounter::MediaLicenseResult::~MediaLicenseResult() {} |
| + |
| +const std::string& MediaLicenseCounter::MediaLicenseResult::GetOneOrigin() |
| + const { |
| + return one_origin_; |
| +} |
| + |
| +MediaLicenseCounter::MediaLicenseCounter() |
| + : pref_name_(prefs::kDeleteMediaLicenses), weak_ptr_factory_(this) {} |
| + |
| +MediaLicenseCounter::~MediaLicenseCounter() {} |
| + |
| +const std::string& MediaLicenseCounter::GetPrefName() const { |
| + return pref_name_; |
| +} |
| + |
| +void MediaLicenseCounter::Count() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + scoped_refptr<storage::FileSystemContext> filesystem_context = |
| + make_scoped_refptr( |
| + content::BrowserContext::GetDefaultStoragePartition(GetProfile()) |
| + ->GetFileSystemContext()); |
| + filesystem_context->default_file_task_runner()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&CountOriginsOnFileTaskRunner, |
| + base::Passed(std::move(filesystem_context)), |
| + base::Bind(&MediaLicenseCounter::OnContentLicensesObtained, |
| + weak_ptr_factory_.GetWeakPtr()))); |
| +} |
| + |
| +void MediaLicenseCounter::OnContentLicensesObtained(std::set<GURL> origins) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + ReportResult(base::WrapUnique(new MediaLicenseResult(this, origins))); |
| +} |