Chromium Code Reviews| Index: chrome/browser/chromeos/net/nss_cert_database_factory.cc |
| diff --git a/chrome/browser/chromeos/net/nss_cert_database_factory.cc b/chrome/browser/chromeos/net/nss_cert_database_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..60a27b6c7b9405a6d00f352baf3a4f2c138bf12c |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/net/nss_cert_database_factory.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/net/nss_cert_database_factory.h" |
| + |
| +#include "base/message_loop/message_loop_proxy.h" |
| +#include "chrome/browser/chromeos/profiles/profile_helper.h" |
| +#include "chrome/browser/net/nss_context.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/resource_context.h" |
| + |
| +using content::BrowserThread; |
| + |
| +namespace { |
| + |
| +// Relays callback to the right message loop. |
| +void DidGetCertDBOnIOThread( |
| + scoped_refptr<base::MessageLoopProxy> response_message_loop, |
| + const base::Callback<void(net::NSSCertDatabase*)>& callback, |
| + net::NSSCertDatabase* cert_db) { |
| + response_message_loop->PostTask(FROM_HERE, base::Bind(callback, cert_db)); |
| +} |
| + |
| +// Gets NSSCertDatabase for the resource context. It must be called on IO |
|
pneubeck (no reviews)
2014/01/24 13:18:02
Instead of the "It must be called on..." add a DCH
tbarzic
2014/01/25 00:26:27
Done.
|
| +// thread. |
| +void GetCertDBOnIOThread( |
| + content::ResourceContext* context, |
| + scoped_refptr<base::MessageLoopProxy> response_message_loop, |
| + const base::Callback<void(net::NSSCertDatabase*)>& callback) { |
| + // Note that the callback will be used only if the cert database hasn't yet |
| + // been initialized. |
| + net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext( |
| + context, |
| + base::Bind(&DidGetCertDBOnIOThread, response_message_loop, callback)); |
| + |
| + if (cert_db) |
| + DidGetCertDBOnIOThread(response_message_loop, callback, cert_db); |
| +} |
| + |
| +} // namespace |
| + |
| +namespace chromeos { |
| + |
| +void GetNSSCertDatabaseForProfile( |
| + Profile* profile, |
| + const base::Callback<void(net::NSSCertDatabase*)>& callback) { |
| + BrowserThread::PostTask(BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&GetCertDBOnIOThread, |
| + profile->GetResourceContext(), |
| + base::MessageLoopProxy::current(), |
| + callback)); |
| +} |
| + |
| +} // namespace chromeos |
| + |