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

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: Added Linux implementation. Created 6 years, 3 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 | 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 {
17
18 void CallBackOnTaskRunner(
19 const scoped_refptr<base::TaskRunner>& task_runner,
20 const CertDatabaseService::GetCertDBCallback& callback,
21 net::NSSCertDatabase* cert_db) {
22 task_runner->PostTask(FROM_HERE, base::Bind(callback, cert_db));
23 }
24
25 void GetNSSCertDBOnIOThread(
26 base::WeakPtr<CertDatabaseServiceIOPart> io_part,
27 const CertDatabaseService::GetCertDBCallback& callback) {
28 if (!io_part)
29 return;
30 net::NSSCertDatabase* db = io_part->GetNSSCertDatabase(callback);
31 if (db)
32 callback.Run(db);
33 }
34
35 void DestroyIOPart(const base::WeakPtr<CertDatabaseServiceIOPart>& io_part) {
36 if (!io_part) {
37 LOG(WARNING) << "CertDatabaseServiceIOPart already destructed.";
38 return;
39 }
40 delete io_part.get();
41 }
42
43 } // namespace
44
45 CertDatabaseService::CertDatabaseService(
46 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner)
47 : io_task_runner_(io_task_runner), is_io_part_set_(false) {
48 }
49
50 CertDatabaseService::~CertDatabaseService() {
51 io_task_runner_->PostTask(FROM_HERE, base::Bind(DestroyIOPart, io_part_));
52 }
53
54 void CertDatabaseService::GetNSSCertDatabase(
55 const GetCertDBCallback& callback) {
56 CHECK(is_io_part_set_);
57 GetCertDBCallback callback_on_origin_thread = base::Bind(
58 &CallBackOnTaskRunner, base::ThreadTaskRunnerHandle::Get(), callback);
59 io_task_runner_->PostTask(
60 FROM_HERE,
61 base::Bind(&GetNSSCertDBOnIOThread, io_part_, callback_on_origin_thread));
62 }
63
64 void CertDatabaseService::SetIOPart(
65 scoped_ptr<CertDatabaseServiceIOPart> io_part) {
66 DCHECK(!is_io_part_set_);
67 is_io_part_set_ = true;
68 io_part_ = io_part->GetWeakPtr();
69 ignore_result(io_part.release());
70
71 // Must immediatly post to IO for initialization, so that subsequent accesses
72 // hit the IO thread after Init() was called.
73 io_task_runner_->PostTask(
74 FROM_HERE, base::Bind(&CertDatabaseServiceIOPart::Init, io_part_));
75 }
76
77 base::WeakPtr<CertDatabaseServiceIOPart> CertDatabaseService::GetIOPart() {
78 CHECK(is_io_part_set_);
79 return io_part_;
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698