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

Side by Side Diff: components/quirks/quirks_manager.cc

Issue 1921923002: Convert //components/[o-t]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 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
« no previous file with comments | « components/quirks/quirks_manager.h ('k') | components/rappor/log_uploader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/quirks/quirks_manager.h" 5 #include "components/quirks/quirks_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/rand_util.h" 14 #include "base/rand_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/task_runner_util.h" 16 #include "base/task_runner_util.h"
16 #include "components/prefs/pref_registry_simple.h" 17 #include "components/prefs/pref_registry_simple.h"
17 #include "components/prefs/scoped_user_pref_update.h" 18 #include "components/prefs/scoped_user_pref_update.h"
18 #include "components/quirks/pref_names.h" 19 #include "components/quirks/pref_names.h"
19 #include "components/quirks/quirks_client.h" 20 #include "components/quirks/quirks_client.h"
20 #include "components/quirks/switches.h" 21 #include "components/quirks/switches.h"
21 #include "net/url_request/url_fetcher.h" 22 #include "net/url_request/url_fetcher.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 72 }
72 73
73 std::string IdToFileName(int64_t product_id) { 74 std::string IdToFileName(int64_t product_id) {
74 return IdToHexString(product_id).append(kIccExtension); 75 return IdToHexString(product_id).append(kIccExtension);
75 } 76 }
76 77
77 //////////////////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////////////
78 // QuirksManager 79 // QuirksManager
79 80
80 QuirksManager::QuirksManager( 81 QuirksManager::QuirksManager(
81 scoped_ptr<Delegate> delegate, 82 std::unique_ptr<Delegate> delegate,
82 scoped_refptr<base::SequencedWorkerPool> blocking_pool, 83 scoped_refptr<base::SequencedWorkerPool> blocking_pool,
83 PrefService* local_state, 84 PrefService* local_state,
84 scoped_refptr<net::URLRequestContextGetter> url_context_getter) 85 scoped_refptr<net::URLRequestContextGetter> url_context_getter)
85 : waiting_for_login_(true), 86 : waiting_for_login_(true),
86 delegate_(std::move(delegate)), 87 delegate_(std::move(delegate)),
87 blocking_pool_(blocking_pool), 88 blocking_pool_(blocking_pool),
88 local_state_(local_state), 89 local_state_(local_state),
89 url_context_getter_(url_context_getter), 90 url_context_getter_(url_context_getter),
90 weak_ptr_factory_(this) {} 91 weak_ptr_factory_(this) {}
91 92
92 QuirksManager::~QuirksManager() { 93 QuirksManager::~QuirksManager() {
93 clients_.clear(); 94 clients_.clear();
94 manager_ = nullptr; 95 manager_ = nullptr;
95 } 96 }
96 97
97 // static 98 // static
98 void QuirksManager::Initialize( 99 void QuirksManager::Initialize(
99 scoped_ptr<Delegate> delegate, 100 std::unique_ptr<Delegate> delegate,
100 scoped_refptr<base::SequencedWorkerPool> blocking_pool, 101 scoped_refptr<base::SequencedWorkerPool> blocking_pool,
101 PrefService* local_state, 102 PrefService* local_state,
102 scoped_refptr<net::URLRequestContextGetter> url_context_getter) { 103 scoped_refptr<net::URLRequestContextGetter> url_context_getter) {
103 manager_ = new QuirksManager(std::move(delegate), blocking_pool, local_state, 104 manager_ = new QuirksManager(std::move(delegate), blocking_pool, local_state,
104 url_context_getter); 105 url_context_getter);
105 } 106 }
106 107
107 // static 108 // static
108 void QuirksManager::Shutdown() { 109 void QuirksManager::Shutdown() {
109 delete manager_; 110 delete manager_;
(...skipping 14 matching lines...) Expand all
124 void QuirksManager::OnLoginCompleted() { 125 void QuirksManager::OnLoginCompleted() {
125 if (!waiting_for_login_) 126 if (!waiting_for_login_)
126 return; 127 return;
127 128
128 waiting_for_login_ = false; 129 waiting_for_login_ = false;
129 if (!clients_.empty() && !QuirksEnabled()) { 130 if (!clients_.empty() && !QuirksEnabled()) {
130 VLOG(2) << clients_.size() << " client(s) deleted."; 131 VLOG(2) << clients_.size() << " client(s) deleted.";
131 clients_.clear(); 132 clients_.clear();
132 } 133 }
133 134
134 for (const scoped_ptr<QuirksClient>& client : clients_) 135 for (const std::unique_ptr<QuirksClient>& client : clients_)
135 client->StartDownload(); 136 client->StartDownload();
136 } 137 }
137 138
138 void QuirksManager::RequestIccProfilePath( 139 void QuirksManager::RequestIccProfilePath(
139 int64_t product_id, 140 int64_t product_id,
140 const RequestFinishedCallback& on_request_finished) { 141 const RequestFinishedCallback& on_request_finished) {
141 DCHECK(thread_checker_.CalledOnValidThread()); 142 DCHECK(thread_checker_.CalledOnValidThread());
142 143
143 std::string name = IdToFileName(product_id); 144 std::string name = IdToFileName(product_id);
144 base::PostTaskAndReplyWithResult( 145 base::PostTaskAndReplyWithResult(
145 blocking_pool_.get(), FROM_HERE, 146 blocking_pool_.get(), FROM_HERE,
146 base::Bind(&CheckForIccFile, 147 base::Bind(&CheckForIccFile,
147 delegate_->GetBuiltInDisplayProfileDirectory().Append(name), 148 delegate_->GetBuiltInDisplayProfileDirectory().Append(name),
148 delegate_->GetDownloadDisplayProfileDirectory().Append(name), 149 delegate_->GetDownloadDisplayProfileDirectory().Append(name),
149 QuirksEnabled()), 150 QuirksEnabled()),
150 base::Bind(&QuirksManager::OnIccFilePathRequestCompleted, 151 base::Bind(&QuirksManager::OnIccFilePathRequestCompleted,
151 weak_ptr_factory_.GetWeakPtr(), product_id, 152 weak_ptr_factory_.GetWeakPtr(), product_id,
152 on_request_finished)); 153 on_request_finished));
153 } 154 }
154 155
155 void QuirksManager::ClientFinished(QuirksClient* client) { 156 void QuirksManager::ClientFinished(QuirksClient* client) {
156 DCHECK(thread_checker_.CalledOnValidThread()); 157 DCHECK(thread_checker_.CalledOnValidThread());
157 SetLastServerCheck(client->product_id(), base::Time::Now()); 158 SetLastServerCheck(client->product_id(), base::Time::Now());
158 auto it = std::find_if(clients_.begin(), clients_.end(), 159 auto it = std::find_if(clients_.begin(), clients_.end(),
159 [client](const scoped_ptr<QuirksClient>& c) { 160 [client](const std::unique_ptr<QuirksClient>& c) {
160 return c.get() == client; 161 return c.get() == client;
161 }); 162 });
162 CHECK(it != clients_.end()); 163 CHECK(it != clients_.end());
163 clients_.erase(it); 164 clients_.erase(it);
164 } 165 }
165 166
166 scoped_ptr<net::URLFetcher> QuirksManager::CreateURLFetcher( 167 std::unique_ptr<net::URLFetcher> QuirksManager::CreateURLFetcher(
167 const GURL& url, 168 const GURL& url,
168 net::URLFetcherDelegate* delegate) { 169 net::URLFetcherDelegate* delegate) {
169 if (!fake_quirks_fetcher_creator_.is_null()) 170 if (!fake_quirks_fetcher_creator_.is_null())
170 return fake_quirks_fetcher_creator_.Run(url, delegate); 171 return fake_quirks_fetcher_creator_.Run(url, delegate);
171 172
172 return net::URLFetcher::Create(url, net::URLFetcher::GET, delegate); 173 return net::URLFetcher::Create(url, net::URLFetcher::GET, delegate);
173 } 174 }
174 175
175 void QuirksManager::OnIccFilePathRequestCompleted( 176 void QuirksManager::OnIccFilePathRequestCompleted(
176 int64_t product_id, 177 int64_t product_id,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 238
238 on_request_finished.Run(base::FilePath(), false); 239 on_request_finished.Run(base::FilePath(), false);
239 } 240 }
240 241
241 void QuirksManager::CreateClient( 242 void QuirksManager::CreateClient(
242 int64_t product_id, 243 int64_t product_id,
243 const RequestFinishedCallback& on_request_finished) { 244 const RequestFinishedCallback& on_request_finished) {
244 DCHECK(thread_checker_.CalledOnValidThread()); 245 DCHECK(thread_checker_.CalledOnValidThread());
245 QuirksClient* client = 246 QuirksClient* client =
246 new QuirksClient(product_id, on_request_finished, this); 247 new QuirksClient(product_id, on_request_finished, this);
247 clients_.insert(make_scoped_ptr(client)); 248 clients_.insert(base::WrapUnique(client));
248 if (!waiting_for_login_) 249 if (!waiting_for_login_)
249 client->StartDownload(); 250 client->StartDownload();
250 else 251 else
251 VLOG(2) << "Quirks Client created; waiting for login to begin download."; 252 VLOG(2) << "Quirks Client created; waiting for login to begin download.";
252 } 253 }
253 254
254 bool QuirksManager::QuirksEnabled() { 255 bool QuirksManager::QuirksEnabled() {
255 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 256 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
256 switches::kDisableQuirksClient)) { 257 switches::kDisableQuirksClient)) {
257 VLOG(2) << "Quirks Client disabled by command line flag."; 258 VLOG(2) << "Quirks Client disabled by command line flag.";
258 return false; 259 return false;
259 } 260 }
260 if (!delegate_->DevicePolicyEnabled()) { 261 if (!delegate_->DevicePolicyEnabled()) {
261 VLOG(2) << "Quirks Client disabled by device policy."; 262 VLOG(2) << "Quirks Client disabled by device policy.";
262 return false; 263 return false;
263 } 264 }
264 return true; 265 return true;
265 } 266 }
266 267
267 void QuirksManager::SetLastServerCheck(int64_t product_id, 268 void QuirksManager::SetLastServerCheck(int64_t product_id,
268 const base::Time& last_check) { 269 const base::Time& last_check) {
269 DCHECK(thread_checker_.CalledOnValidThread()); 270 DCHECK(thread_checker_.CalledOnValidThread());
270 DictionaryPrefUpdate dict(local_state_, prefs::kQuirksClientLastServerCheck); 271 DictionaryPrefUpdate dict(local_state_, prefs::kQuirksClientLastServerCheck);
271 dict->SetDouble(IdToHexString(product_id), last_check.ToDoubleT()); 272 dict->SetDouble(IdToHexString(product_id), last_check.ToDoubleT());
272 } 273 }
273 274
274 } // namespace quirks 275 } // namespace quirks
OLDNEW
« no previous file with comments | « components/quirks/quirks_manager.h ('k') | components/rappor/log_uploader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698