| OLD | NEW | 
|---|
| (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/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 "base/task_runner_util.h" | 
|  | 12 #include "chrome/common/pref_names.h" | 
|  | 13 #include "content/public/browser/browser_thread.h" | 
|  | 14 #include "content/public/browser/storage_partition.h" | 
|  | 15 #include "storage/browser/fileapi/file_system_context.h" | 
|  | 16 | 
|  | 17 namespace { | 
|  | 18 | 
|  | 19 // Determining the origins must be run on the file task thread. | 
|  | 20 std::set<GURL> CountOriginsOnFileTaskRunner( | 
|  | 21     storage::FileSystemContext* filesystem_context) { | 
|  | 22   DCHECK(filesystem_context->default_file_task_runner() | 
|  | 23              ->RunsTasksOnCurrentThread()); | 
|  | 24 | 
|  | 25   storage::FileSystemBackend* backend = | 
|  | 26       filesystem_context->GetFileSystemBackend( | 
|  | 27           storage::kFileSystemTypePluginPrivate); | 
|  | 28   storage::FileSystemQuotaUtil* quota_util = backend->GetQuotaUtil(); | 
|  | 29 | 
|  | 30   std::set<GURL> origins; | 
|  | 31   quota_util->GetOriginsForTypeOnFileTaskRunner( | 
|  | 32       storage::kFileSystemTypePluginPrivate, &origins); | 
|  | 33   return origins; | 
|  | 34 } | 
|  | 35 | 
|  | 36 }  // namespace | 
|  | 37 | 
|  | 38 MediaLicenseCounter::MediaLicenseResult::MediaLicenseResult( | 
|  | 39     const MediaLicenseCounter* source, | 
|  | 40     const std::set<GURL>& origins) | 
|  | 41     : FinishedResult(source, origins.size()) { | 
|  | 42   if (!origins.empty()) | 
|  | 43     one_origin_ = origins.begin()->GetOrigin().spec(); | 
|  | 44 } | 
|  | 45 | 
|  | 46 MediaLicenseCounter::MediaLicenseResult::~MediaLicenseResult() {} | 
|  | 47 | 
|  | 48 const std::string& MediaLicenseCounter::MediaLicenseResult::GetOneOrigin() | 
|  | 49     const { | 
|  | 50   return one_origin_; | 
|  | 51 } | 
|  | 52 | 
|  | 53 MediaLicenseCounter::MediaLicenseCounter() | 
|  | 54     : pref_name_(prefs::kDeleteMediaLicenses), weak_ptr_factory_(this) {} | 
|  | 55 | 
|  | 56 MediaLicenseCounter::~MediaLicenseCounter() {} | 
|  | 57 | 
|  | 58 const std::string& MediaLicenseCounter::GetPrefName() const { | 
|  | 59   return pref_name_; | 
|  | 60 } | 
|  | 61 | 
|  | 62 void MediaLicenseCounter::Count() { | 
|  | 63   DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 
|  | 64   scoped_refptr<storage::FileSystemContext> filesystem_context = | 
|  | 65       make_scoped_refptr( | 
|  | 66           content::BrowserContext::GetDefaultStoragePartition(GetProfile()) | 
|  | 67               ->GetFileSystemContext()); | 
|  | 68   base::PostTaskAndReplyWithResult( | 
|  | 69       filesystem_context->default_file_task_runner(), FROM_HERE, | 
|  | 70       base::Bind(&CountOriginsOnFileTaskRunner, | 
|  | 71                  base::RetainedRef(filesystem_context)), | 
|  | 72       base::Bind(&MediaLicenseCounter::OnContentLicensesObtained, | 
|  | 73                  weak_ptr_factory_.GetWeakPtr())); | 
|  | 74 } | 
|  | 75 | 
|  | 76 void MediaLicenseCounter::OnContentLicensesObtained( | 
|  | 77     const std::set<GURL>& origins) { | 
|  | 78   DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 
|  | 79   ReportResult(base::WrapUnique(new MediaLicenseResult(this, origins))); | 
|  | 80 } | 
| OLD | NEW | 
|---|