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

Side by Side Diff: components/cert_database/core/cert_database_service.cc

Issue 419013003: Replace c/b/nss_context by a KeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/cert_database/public/cert_database_service.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "components/cert_database/public/cert_database_service_io_part.h"
14 #include "net/cert/nss_cert_database.h"
15
16 namespace cert_database {
17
18 namespace {
19
20 void CallBackOnTaskRunner(
21 const scoped_refptr<base::TaskRunner>& task_runner,
22 const CertDatabaseService::GetCertDBCallback& callback,
23 net::NSSCertDatabase* cert_db) {
24 task_runner->PostTask(FROM_HERE, base::Bind(callback, cert_db));
25 }
26
27 void GetNSSCertDBOnIOThread(
28 base::WeakPtr<CertDatabaseServiceIOPart> io_part,
29 const CertDatabaseService::GetCertDBCallback& callback) {
30 if (!io_part)
31 return;
32 net::NSSCertDatabase* db = io_part->GetNSSCertDatabase(callback);
33 if (db)
34 callback.Run(db);
35 }
36
37 void DestroyIOPart(const base::WeakPtr<CertDatabaseServiceIOPart>& io_part) {
38 if (!io_part) {
39 LOG(WARNING) << "CertDatabaseServiceIOPart already destructed.";
40 return;
41 }
42 delete io_part.get();
43 }
44
45 } // namespace
46
47 CertDatabaseService::CertDatabaseService(
48 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner)
49 : io_task_runner_(io_task_runner), is_io_part_set_(false) {
50 }
51
52 CertDatabaseService::~CertDatabaseService() {
53 io_task_runner_->PostTask(FROM_HERE, base::Bind(&DestroyIOPart, io_part_));
54 }
55
56 void CertDatabaseService::GetNSSCertDatabase(
57 const GetCertDBCallback& callback) {
58 CHECK(is_io_part_set_);
59 GetCertDBCallback callback_on_origin_thread = base::Bind(
60 &CallBackOnTaskRunner, base::ThreadTaskRunnerHandle::Get(), callback);
61 io_task_runner_->PostTask(
62 FROM_HERE,
63 base::Bind(&GetNSSCertDBOnIOThread, io_part_, callback_on_origin_thread));
64 }
65
66 void CertDatabaseService::SetIOPart(
67 scoped_ptr<CertDatabaseServiceIOPart> io_part) {
68 DCHECK(!is_io_part_set_);
69 is_io_part_set_ = true;
70 io_part_ = io_part->GetWeakPtr();
71 ignore_result(io_part.release());
mmenke 2014/11/04 20:02:18 Who owns the io_part_ after this? It's not at all
pneubeck (no reviews) 2014/11/05 14:53:38 Added a comment to clarify (there was one in the h
72
73 // Must immediatly post to IO for initialization, so that subsequent accesses
74 // hit the IO thread after Init() was called.
75 io_task_runner_->PostTask(
76 FROM_HERE, base::Bind(&CertDatabaseServiceIOPart::Init, io_part_));
77 }
78
79 base::WeakPtr<CertDatabaseServiceIOPart> CertDatabaseService::GetIOPart() {
80 CHECK(is_io_part_set_);
81 return io_part_;
82 }
83
84 } // namespace cert_database
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698