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

Unified Diff: components/cert_database/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: Flattened components/cert_database folders. 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 side-by-side diff with in-line comments
Download patch
Index: components/cert_database/cert_database_service.cc
diff --git a/components/cert_database/cert_database_service.cc b/components/cert_database/cert_database_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f17ee31a71b1121756acce0e64bb83cb46b7e54f
--- /dev/null
+++ b/components/cert_database/cert_database_service.cc
@@ -0,0 +1,88 @@
+// 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 "components/cert_database/cert_database_service.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
+#include "base/location.h"
+#include "base/single_thread_task_runner.h"
+#include "base/thread_task_runner_handle.h"
+#include "components/cert_database/cert_database_service_io_part.h"
+#include "net/cert/nss_cert_database.h"
+
+namespace cert_database {
+
+namespace {
+
+void CallBackOnTaskRunner(
+ const scoped_refptr<base::TaskRunner>& task_runner,
+ const CertDatabaseService::GetCertDBCallback& callback,
+ net::NSSCertDatabase* cert_db) {
+ task_runner->PostTask(FROM_HERE, base::Bind(callback, cert_db));
+}
+
+void GetNSSCertDatabaseOnIOThread(
+ base::WeakPtr<CertDatabaseServiceIOPart> io_part,
+ const CertDatabaseService::GetCertDBCallback& callback) {
+ if (!io_part)
+ return;
+ net::NSSCertDatabase* db = io_part->GetNSSCertDatabase(callback);
+ if (db)
+ callback.Run(db);
+}
+
+void DestroyIOPart(const base::WeakPtr<CertDatabaseServiceIOPart>& io_part) {
+ if (!io_part) {
+ LOG(WARNING) << "CertDatabaseServiceIOPart already destructed.";
+ return;
+ }
+ delete io_part.get();
+}
+
+} // namespace
+
+CertDatabaseService::CertDatabaseService(
+ const scoped_refptr<base::SequencedTaskRunner>& io_task_runner)
+ : io_task_runner_(io_task_runner), is_io_part_set_(false) {
+}
+
+CertDatabaseService::~CertDatabaseService() {
+ io_task_runner_->PostTask(FROM_HERE, base::Bind(&DestroyIOPart, io_part_));
+}
+
+void CertDatabaseService::GetNSSCertDatabase(
+ const GetCertDBCallback& callback) {
+ CHECK(is_io_part_set_);
+ GetCertDBCallback callback_on_origin_thread = base::Bind(
+ &CallBackOnTaskRunner, base::ThreadTaskRunnerHandle::Get(), callback);
+ io_task_runner_->PostTask(FROM_HERE,
+ base::Bind(&GetNSSCertDatabaseOnIOThread, io_part_,
+ callback_on_origin_thread));
+}
+
+void CertDatabaseService::SetIOPart(
+ scoped_ptr<CertDatabaseServiceIOPart> io_part) {
+ DCHECK(!is_io_part_set_);
+ is_io_part_set_ = true;
+ io_part_ = io_part->GetWeakPtr();
+ // This Service owns |io_part_|. Since this Service is living on UI and
+ // |io_part_| is living on IO thread, a scoped_ptr cannot be used. Instead,
+ // the Service's destructor will post a task to delete |io_part_| on the IO
+ // thread.
+ ignore_result(io_part.release());
+
+ // Must immediately post to IO for initialization, so that subsequent accesses
+ // hit the IO thread after Init() was called.
+ io_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CertDatabaseServiceIOPart::Init, io_part_));
+}
+
+base::WeakPtr<CertDatabaseServiceIOPart> CertDatabaseService::GetIOPart() {
+ CHECK(is_io_part_set_);
+ return io_part_;
+}
+
+} // namespace cert_database
« no previous file with comments | « components/cert_database/cert_database_service.h ('k') | components/cert_database/cert_database_service_io_part.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698