Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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/media_licenses_counter.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "chrome/common/pref_names.h" | |
| 12 #include "content/public/browser/browser_thread.h" | |
| 13 #include "content/public/browser/storage_partition.h" | |
| 14 #include "storage/browser/fileapi/file_system_context.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 using OriginsDeterminedCB = base::Callback<void(const std::set<GURL>&)>; | |
| 19 | |
| 20 // Determining the origins must be run on the file task thread. This calls | |
| 21 // |callback| on the main thread with the results. | |
| 22 void CountOriginsOnFileTaskRunner( | |
| 23 scoped_refptr<storage::FileSystemContext> filesystem_context, | |
| 24 const OriginsDeterminedCB& callback) { | |
| 25 DCHECK(filesystem_context->default_file_task_runner() | |
| 26 ->RunsTasksOnCurrentThread()); | |
| 27 | |
| 28 storage::FileSystemBackend* backend = | |
| 29 filesystem_context->GetFileSystemBackend( | |
| 30 storage::kFileSystemTypePluginPrivate); | |
| 31 storage::FileSystemQuotaUtil* quota_util = backend->GetQuotaUtil(); | |
| 32 | |
| 33 std::set<GURL> origins; | |
| 34 quota_util->GetOriginsForTypeOnFileTaskRunner( | |
| 35 storage::kFileSystemTypePluginPrivate, &origins); | |
| 36 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 37 base::Bind(callback, origins)); | |
| 38 } | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 MediaLicenseCounter::MediaLicenseResult::MediaLicenseResult( | |
| 43 const MediaLicenseCounter* source, | |
| 44 const std::set<GURL>& origins) | |
| 45 : FinishedResult(source, origins.size()) { | |
| 46 if (!origins.empty()) | |
| 47 one_origin_ = origins.begin()->GetOrigin().spec(); | |
| 48 } | |
| 49 | |
| 50 MediaLicenseCounter::MediaLicenseResult::~MediaLicenseResult() {} | |
| 51 | |
| 52 const std::string& MediaLicenseCounter::MediaLicenseResult::GetOneOrigin() | |
| 53 const { | |
| 54 return one_origin_; | |
| 55 } | |
| 56 | |
| 57 MediaLicenseCounter::MediaLicenseCounter() | |
| 58 : pref_name_(prefs::kDeleteMediaLicenses), weak_ptr_factory_(this) {} | |
| 59 | |
| 60 MediaLicenseCounter::~MediaLicenseCounter() {} | |
| 61 | |
| 62 const std::string& MediaLicenseCounter::GetPrefName() const { | |
| 63 return pref_name_; | |
| 64 } | |
| 65 | |
| 66 void MediaLicenseCounter::Count() { | |
| 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 68 scoped_refptr<storage::FileSystemContext> filesystem_context = | |
| 69 make_scoped_refptr( | |
| 70 content::BrowserContext::GetDefaultStoragePartition(GetProfile()) | |
| 71 ->GetFileSystemContext()); | |
| 72 filesystem_context->default_file_task_runner()->PostTask( | |
| 73 FROM_HERE, | |
| 74 base::Bind(&CountOriginsOnFileTaskRunner, | |
| 75 base::Passed(std::move(filesystem_context)), | |
|
michaeln
2016/06/21 20:23:41
This looks a little dicey, is it possible for the
jrummell
2016/06/23 02:48:55
Done.
| |
| 76 base::Bind(&MediaLicenseCounter::OnContentLicensesObtained, | |
| 77 weak_ptr_factory_.GetWeakPtr()))); | |
| 78 } | |
| 79 | |
| 80 void MediaLicenseCounter::OnContentLicensesObtained( | |
| 81 const std::set<GURL>& origins) { | |
| 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 83 ReportResult(base::WrapUnique(new MediaLicenseResult(this, origins))); | |
| 84 } | |
| OLD | NEW |