BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / net / nss_context.cc
blob8865e1498ea8a01d49b55dde12248a59f0532633
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;
16 namespace {
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
36 // been initialized.
37 net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext(
38 context,
39 base::Bind(&DidGetCertDBOnIOThread, response_task_runner, callback));
41 if (cert_db)
42 DidGetCertDBOnIOThread(response_task_runner, callback, cert_db);
45 } // namespace
47 void GetNSSCertDatabaseForProfile(
48 Profile* profile,
49 const base::Callback<void(net::NSSCertDatabase*)>& callback) {
50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
52 BrowserThread::PostTask(BrowserThread::IO,
53 FROM_HERE,
54 base::Bind(&GetCertDBOnIOThread,
55 profile->GetResourceContext(),
56 base::ThreadTaskRunnerHandle::Get(),
57 callback));