OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef COMPONENTS_CERT_DATABASE_PUBLIC_CERT_DATABASE_SERVICE_H_ |
| 6 #define COMPONENTS_CERT_DATABASE_PUBLIC_CERT_DATABASE_SERVICE_H_ |
| 7 |
| 8 #include "base/callback_forward.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "components/keyed_service/core/keyed_service.h" |
| 12 |
| 13 namespace net { |
| 14 class NSSCertDatabase; |
| 15 } |
| 16 |
| 17 namespace cert_database { |
| 18 |
| 19 class CertDatabaseServiceIOPart; |
| 20 |
| 21 // This Service lives on the the UI thread, i.e. all methods must be called on |
| 22 // the UI thread. |
| 23 class CertDatabaseService : public KeyedService { |
| 24 public: |
| 25 typedef base::Callback<void(net::NSSCertDatabase*)> GetCertDBCallback; |
| 26 |
| 27 explicit CertDatabaseService( |
| 28 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner); |
| 29 ~CertDatabaseService() override; |
| 30 |
| 31 // This function is for migrating from old users of nss_context. New users |
| 32 // should use GetIOPart(); |
| 33 void GetNSSCertDatabase(const GetCertDBCallback& callback); |
| 34 |
| 35 // Passes ownership of |io_part| to this service. |
| 36 // This will initialize |io_part| by calling its Init() method. Afterwards it |
| 37 // must only be accessed through a WeakPtr and on the IO thread. |
| 38 void SetIOPart(scoped_ptr<CertDatabaseServiceIOPart> io_part); |
| 39 |
| 40 // This method must be called on the UI thread, but the WeakPtr must only be |
| 41 // dereferenced on the IO thread. |
| 42 base::WeakPtr<CertDatabaseServiceIOPart> GetIOPart(); |
| 43 |
| 44 private: |
| 45 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
| 46 |
| 47 // Whether |io_part_| was set. |io_part_| itself can't be checked on the UI |
| 48 // thread. |
| 49 bool is_io_part_set_; |
| 50 |
| 51 // This service is owning the IOPart. However, it lives on the IO thread thus |
| 52 // scoped_ptr cannot not be used. We keep a WeakPtr, so that we can copy |
| 53 // further WeakPtrs on the UI thread. |
| 54 // A task to delete |io_part_| is posted to the IO thread from the service's |
| 55 // destructor. |
| 56 base::WeakPtr<CertDatabaseServiceIOPart> io_part_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(CertDatabaseService); |
| 59 }; |
| 60 |
| 61 } // namespace cert_database |
| 62 |
| 63 #endif // COMPONENTS_CERT_DATABASE_PUBLIC_CERT_DATABASE_SERVICE_H_ |
OLD | NEW |