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

Unified Diff: components/cert_database/cert_database_service.h

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
« no previous file with comments | « components/cert_database/OWNERS ('k') | components/cert_database/cert_database_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cert_database/cert_database_service.h
diff --git a/components/cert_database/cert_database_service.h b/components/cert_database/cert_database_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..b3e1bf1c4daca848d2b407bfde142f29c8a4bbcf
--- /dev/null
+++ b/components/cert_database/cert_database_service.h
@@ -0,0 +1,63 @@
+// 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.
+
+#ifndef COMPONENTS_CERT_DATABASE_PUBLIC_CERT_DATABASE_SERVICE_H_
+#define COMPONENTS_CERT_DATABASE_PUBLIC_CERT_DATABASE_SERVICE_H_
+
+#include "base/callback_forward.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "components/keyed_service/core/keyed_service.h"
+
+namespace net {
+class NSSCertDatabase;
+}
+
+namespace cert_database {
+
+class CertDatabaseServiceIOPart;
+
+// This Service lives on the the UI thread, i.e. all methods must be called on
+// the UI thread.
+class CertDatabaseService : public KeyedService {
+ public:
+ typedef base::Callback<void(net::NSSCertDatabase*)> GetCertDBCallback;
+
+ explicit CertDatabaseService(
+ const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
+ ~CertDatabaseService() override;
+
+ // This function is for migrating from old users of nss_context. New users
+ // should use GetIOPart();
+ void GetNSSCertDatabase(const GetCertDBCallback& callback);
+
+ // Passes ownership of |io_part| to this service.
+ // This will initialize |io_part| by calling its Init() method. Afterwards it
+ // must only be accessed through a WeakPtr and on the IO thread.
+ void SetIOPart(scoped_ptr<CertDatabaseServiceIOPart> io_part);
+
+ // This method must be called on the UI thread, but the WeakPtr must only be
+ // dereferenced on the IO thread.
+ base::WeakPtr<CertDatabaseServiceIOPart> GetIOPart();
+
+ private:
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
+
+ // Whether |io_part_| was set. |io_part_| itself can't be checked on the UI
+ // thread.
+ bool is_io_part_set_;
+
+ // This service is owning the IOPart. However, it lives on the IO thread thus
+ // scoped_ptr cannot not be used. We keep a WeakPtr, so that we can copy
+ // further WeakPtrs on the UI thread.
+ // A task to delete |io_part_| is posted to the IO thread from the service's
+ // destructor.
+ base::WeakPtr<CertDatabaseServiceIOPart> io_part_;
+
+ DISALLOW_COPY_AND_ASSIGN(CertDatabaseService);
+};
+
+} // namespace cert_database
+
+#endif // COMPONENTS_CERT_DATABASE_PUBLIC_CERT_DATABASE_SERVICE_H_
« no previous file with comments | « components/cert_database/OWNERS ('k') | components/cert_database/cert_database_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698