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_license_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 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.
| |
17 | |
18 // Determining the origins must be run on the file task thread. This calls | |
19 // |callback| on the main thread with the results. | |
20 void CountOriginsOnFileTaskRunner( | |
xhwang
2016/06/17 06:24:29
put this in an anonymous namespace?
jrummell
2016/06/21 00:13:44
Done.
| |
21 scoped_refptr<storage::FileSystemContext> filesystem_context, | |
22 OriginsDeterminedCB callback) { | |
xhwang
2016/06/17 06:24:30
pass callback by const-ref
jrummell
2016/06/21 00:13:44
Done.
| |
23 DCHECK(filesystem_context->default_file_task_runner() | |
24 ->RunsTasksOnCurrentThread()); | |
25 | |
26 storage::FileSystemBackend* backend = | |
27 filesystem_context->GetFileSystemBackend( | |
28 storage::kFileSystemTypePluginPrivate); | |
29 storage::FileSystemQuotaUtil* quota_util = backend->GetQuotaUtil(); | |
30 | |
31 std::set<GURL> origins; | |
32 quota_util->GetOriginsForTypeOnFileTaskRunner( | |
33 storage::kFileSystemTypePluginPrivate, &origins); | |
34 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
35 base::Bind(callback, origins)); | |
36 } | |
37 | |
38 MediaLicenseCounter::MediaLicenseResult::MediaLicenseResult( | |
39 const MediaLicenseCounter* source, | |
40 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 filesystem_context->default_file_task_runner()->PostTask( | |
69 FROM_HERE, | |
70 base::Bind(&CountOriginsOnFileTaskRunner, | |
71 base::Passed(std::move(filesystem_context)), | |
72 base::Bind(&MediaLicenseCounter::OnContentLicensesObtained, | |
73 weak_ptr_factory_.GetWeakPtr()))); | |
74 } | |
75 | |
76 void MediaLicenseCounter::OnContentLicensesObtained(std::set<GURL> origins) { | |
77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
78 ReportResult(base::WrapUnique(new MediaLicenseResult(this, origins))); | |
79 } | |
OLD | NEW |