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

Side by Side Diff: net/ssl/channel_id_service.cc

Issue 2910473005: Deprecate NonThreadSafe in net/ in favor of SequenceChecker/ThreadChecker. (Closed)
Patch Set: rebase on r476634 Created 3 years, 6 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 | « net/ssl/channel_id_service.h ('k') | net/ssl/channel_id_store.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/ssl/channel_id_service.h" 5 #include "net/ssl/channel_id_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 ChannelIDService::ChannelIDService(ChannelIDStore* channel_id_store) 254 ChannelIDService::ChannelIDService(ChannelIDStore* channel_id_store)
255 : channel_id_store_(channel_id_store), 255 : channel_id_store_(channel_id_store),
256 id_(g_next_id.GetNext()), 256 id_(g_next_id.GetNext()),
257 requests_(0), 257 requests_(0),
258 key_store_hits_(0), 258 key_store_hits_(0),
259 inflight_joins_(0), 259 inflight_joins_(0),
260 workers_created_(0), 260 workers_created_(0),
261 weak_ptr_factory_(this) {} 261 weak_ptr_factory_(this) {}
262 262
263 ChannelIDService::~ChannelIDService() { 263 ChannelIDService::~ChannelIDService() {
264 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
264 } 265 }
265 266
266 // static 267 // static
267 std::string ChannelIDService::GetDomainForHost(const std::string& host) { 268 std::string ChannelIDService::GetDomainForHost(const std::string& host) {
268 std::string domain = 269 std::string domain =
269 registry_controlled_domains::GetDomainAndRegistry( 270 registry_controlled_domains::GetDomainAndRegistry(
270 host, registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 271 host, registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
271 if (domain.empty()) 272 if (domain.empty())
272 return host; 273 return host;
273 return domain; 274 return domain;
274 } 275 }
275 276
276 int ChannelIDService::GetOrCreateChannelID( 277 int ChannelIDService::GetOrCreateChannelID(
277 const std::string& host, 278 const std::string& host,
278 std::unique_ptr<crypto::ECPrivateKey>* key, 279 std::unique_ptr<crypto::ECPrivateKey>* key,
279 const CompletionCallback& callback, 280 const CompletionCallback& callback,
280 Request* out_req) { 281 Request* out_req) {
281 DVLOG(1) << __func__ << " " << host; 282 DVLOG(1) << __func__ << " " << host;
282 DCHECK(CalledOnValidThread()); 283 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
283 284
284 if (callback.is_null() || !key || host.empty()) { 285 if (callback.is_null() || !key || host.empty()) {
285 RecordGetChannelIDResult(INVALID_ARGUMENT); 286 RecordGetChannelIDResult(INVALID_ARGUMENT);
286 return ERR_INVALID_ARGUMENT; 287 return ERR_INVALID_ARGUMENT;
287 } 288 }
288 289
289 std::string domain = GetDomainForHost(host); 290 std::string domain = GetDomainForHost(host);
290 if (domain.empty()) { 291 if (domain.empty()) {
291 RecordGetChannelIDResult(INVALID_ARGUMENT); 292 RecordGetChannelIDResult(INVALID_ARGUMENT);
292 return ERR_INVALID_ARGUMENT; 293 return ERR_INVALID_ARGUMENT;
(...skipping 28 matching lines...) Expand all
321 } 322 }
322 323
323 return err; 324 return err;
324 } 325 }
325 326
326 int ChannelIDService::GetChannelID(const std::string& host, 327 int ChannelIDService::GetChannelID(const std::string& host,
327 std::unique_ptr<crypto::ECPrivateKey>* key, 328 std::unique_ptr<crypto::ECPrivateKey>* key,
328 const CompletionCallback& callback, 329 const CompletionCallback& callback,
329 Request* out_req) { 330 Request* out_req) {
330 DVLOG(1) << __func__ << " " << host; 331 DVLOG(1) << __func__ << " " << host;
331 DCHECK(CalledOnValidThread()); 332 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
332 333
333 if (callback.is_null() || !key || host.empty()) { 334 if (callback.is_null() || !key || host.empty()) {
334 RecordGetChannelIDResult(INVALID_ARGUMENT); 335 RecordGetChannelIDResult(INVALID_ARGUMENT);
335 return ERR_INVALID_ARGUMENT; 336 return ERR_INVALID_ARGUMENT;
336 } 337 }
337 338
338 std::string domain = GetDomainForHost(host); 339 std::string domain = GetDomainForHost(host);
339 if (domain.empty()) { 340 if (domain.empty()) {
340 RecordGetChannelIDResult(INVALID_ARGUMENT); 341 RecordGetChannelIDResult(INVALID_ARGUMENT);
341 return ERR_INVALID_ARGUMENT; 342 return ERR_INVALID_ARGUMENT;
342 } 343 }
343 344
344 requests_++; 345 requests_++;
345 346
346 // See if a request for the same domain currently in flight. 347 // See if a request for the same domain currently in flight.
347 bool create_if_missing = false; 348 bool create_if_missing = false;
348 if (JoinToInFlightRequest(domain, key, create_if_missing, callback, 349 if (JoinToInFlightRequest(domain, key, create_if_missing, callback,
349 out_req)) { 350 out_req)) {
350 return ERR_IO_PENDING; 351 return ERR_IO_PENDING;
351 } 352 }
352 353
353 int err = LookupChannelID(domain, key, create_if_missing, callback, out_req); 354 int err = LookupChannelID(domain, key, create_if_missing, callback, out_req);
354 return err; 355 return err;
355 } 356 }
356 357
357 void ChannelIDService::GotChannelID(int err, 358 void ChannelIDService::GotChannelID(int err,
358 const std::string& server_identifier, 359 const std::string& server_identifier,
359 std::unique_ptr<crypto::ECPrivateKey> key) { 360 std::unique_ptr<crypto::ECPrivateKey> key) {
360 DCHECK(CalledOnValidThread()); 361 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
361 362
362 auto j = inflight_.find(server_identifier); 363 auto j = inflight_.find(server_identifier);
363 if (j == inflight_.end()) { 364 if (j == inflight_.end()) {
364 NOTREACHED(); 365 NOTREACHED();
365 return; 366 return;
366 } 367 }
367 368
368 if (err == OK) { 369 if (err == OK) {
369 // Async DB lookup found a valid channel ID. 370 // Async DB lookup found a valid channel ID.
370 key_store_hits_++; 371 key_store_hits_++;
(...skipping 19 matching lines...) Expand all
390 } 391 }
391 392
392 ChannelIDStore* ChannelIDService::GetChannelIDStore() { 393 ChannelIDStore* ChannelIDService::GetChannelIDStore() {
393 return channel_id_store_.get(); 394 return channel_id_store_.get();
394 } 395 }
395 396
396 void ChannelIDService::GeneratedChannelID( 397 void ChannelIDService::GeneratedChannelID(
397 const std::string& server_identifier, 398 const std::string& server_identifier,
398 int error, 399 int error,
399 std::unique_ptr<ChannelIDStore::ChannelID> channel_id) { 400 std::unique_ptr<ChannelIDStore::ChannelID> channel_id) {
400 DCHECK(CalledOnValidThread()); 401 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
401 402
402 std::unique_ptr<crypto::ECPrivateKey> key; 403 std::unique_ptr<crypto::ECPrivateKey> key;
403 if (error == OK) { 404 if (error == OK) {
404 key = channel_id->key()->Copy(); 405 key = channel_id->key()->Copy();
405 channel_id_store_->SetChannelID(std::move(channel_id)); 406 channel_id_store_->SetChannelID(std::move(channel_id));
406 } 407 }
407 HandleResult(error, server_identifier, std::move(key)); 408 HandleResult(error, server_identifier, std::move(key));
408 } 409 }
409 410
410 void ChannelIDService::HandleResult(int error, 411 void ChannelIDService::HandleResult(int error,
411 const std::string& server_identifier, 412 const std::string& server_identifier,
412 std::unique_ptr<crypto::ECPrivateKey> key) { 413 std::unique_ptr<crypto::ECPrivateKey> key) {
413 DCHECK(CalledOnValidThread()); 414 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
414 415
415 auto j = inflight_.find(server_identifier); 416 auto j = inflight_.find(server_identifier);
416 if (j == inflight_.end()) { 417 if (j == inflight_.end()) {
417 NOTREACHED(); 418 NOTREACHED();
418 return; 419 return;
419 } 420 }
420 std::unique_ptr<ChannelIDServiceJob> job = std::move(j->second); 421 std::unique_ptr<ChannelIDServiceJob> job = std::move(j->second);
421 inflight_.erase(j); 422 inflight_.erase(j);
422 423
423 job->HandleResult(error, std::move(key)); 424 job->HandleResult(error, std::move(key));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } 476 }
476 477
477 return err; 478 return err;
478 } 479 }
479 480
480 int ChannelIDService::channel_id_count() { 481 int ChannelIDService::channel_id_count() {
481 return channel_id_store_->GetChannelIDCount(); 482 return channel_id_store_->GetChannelIDCount();
482 } 483 }
483 484
484 } // namespace net 485 } // namespace net
OLDNEW
« no previous file with comments | « net/ssl/channel_id_service.h ('k') | net/ssl/channel_id_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698