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.
5 #include "chrome/browser/net/nss_context.h"
7 #include "base/sequenced_task_runner.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/resource_context.h"
14 using content::BrowserThread
;
18 // Relays callback to the right message loop.
19 void DidGetCertDBOnIOThread(
20 const scoped_refptr
<base::SequencedTaskRunner
>& response_task_runner
,
21 const base::Callback
<void(net::NSSCertDatabase
*)>& callback
,
22 net::NSSCertDatabase
* cert_db
) {
23 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
25 response_task_runner
->PostTask(FROM_HERE
, base::Bind(callback
, cert_db
));
28 // Gets NSSCertDatabase for the resource context.
29 void GetCertDBOnIOThread(
30 content::ResourceContext
* context
,
31 const scoped_refptr
<base::SequencedTaskRunner
>& response_task_runner
,
32 const base::Callback
<void(net::NSSCertDatabase
*)>& callback
) {
33 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
35 // Note that the callback will be used only if the cert database hasn't yet
37 net::NSSCertDatabase
* cert_db
= GetNSSCertDatabaseForResourceContext(
39 base::Bind(&DidGetCertDBOnIOThread
, response_task_runner
, callback
));
42 DidGetCertDBOnIOThread(response_task_runner
, callback
, cert_db
);
47 void GetNSSCertDatabaseForProfile(
49 const base::Callback
<void(net::NSSCertDatabase
*)>& callback
) {
50 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
52 BrowserThread::PostTask(BrowserThread::IO
,
54 base::Bind(&GetCertDBOnIOThread
,
55 profile
->GetResourceContext(),
56 base::ThreadTaskRunnerHandle::Get(),