OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/nss_context.h" | 5 #include "chrome/browser/net/nss_context.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/macros.h" | 9 #include "base/macros.h" |
8 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
9 #include "base/supports_user_data.h" | 11 #include "base/supports_user_data.h" |
10 #include "chrome/browser/profiles/profile_io_data.h" | 12 #include "chrome/browser/profiles/profile_io_data.h" |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
12 #include "crypto/nss_util_internal.h" | 14 #include "crypto/nss_util_internal.h" |
13 #include "net/cert/nss_cert_database_chromeos.h" | 15 #include "net/cert/nss_cert_database_chromeos.h" |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 void* kDatabaseManagerKey = &kDatabaseManagerKey; | 19 void* kDatabaseManagerKey = &kDatabaseManagerKey; |
18 | 20 |
19 class NSSCertDatabaseChromeOSManager : public base::SupportsUserData::Data { | 21 class NSSCertDatabaseChromeOSManager : public base::SupportsUserData::Data { |
20 public: | 22 public: |
21 typedef base::Callback<void(net::NSSCertDatabaseChromeOS*)> | 23 typedef base::Callback<void(net::NSSCertDatabaseChromeOS*)> |
22 GetNSSCertDatabaseCallback; | 24 GetNSSCertDatabaseCallback; |
23 explicit NSSCertDatabaseChromeOSManager(const std::string& username_hash) | 25 explicit NSSCertDatabaseChromeOSManager(const std::string& username_hash) |
24 : username_hash_(username_hash), weak_ptr_factory_(this) { | 26 : username_hash_(username_hash), weak_ptr_factory_(this) { |
25 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 27 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
26 crypto::ScopedPK11Slot private_slot(crypto::GetPrivateSlotForChromeOSUser( | 28 crypto::ScopedPK11Slot private_slot(crypto::GetPrivateSlotForChromeOSUser( |
27 username_hash, | 29 username_hash, |
28 base::Bind(&NSSCertDatabaseChromeOSManager::DidGetPrivateSlot, | 30 base::Bind(&NSSCertDatabaseChromeOSManager::DidGetPrivateSlot, |
29 weak_ptr_factory_.GetWeakPtr()))); | 31 weak_ptr_factory_.GetWeakPtr()))); |
30 if (private_slot) | 32 if (private_slot) |
31 DidGetPrivateSlot(private_slot.Pass()); | 33 DidGetPrivateSlot(std::move(private_slot)); |
32 } | 34 } |
33 | 35 |
34 ~NSSCertDatabaseChromeOSManager() override { | 36 ~NSSCertDatabaseChromeOSManager() override { |
35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 37 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
36 } | 38 } |
37 | 39 |
38 net::NSSCertDatabaseChromeOS* GetNSSCertDatabase( | 40 net::NSSCertDatabaseChromeOS* GetNSSCertDatabase( |
39 const GetNSSCertDatabaseCallback& callback) { | 41 const GetNSSCertDatabaseCallback& callback) { |
40 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 42 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
41 | 43 |
42 if (nss_cert_database_) | 44 if (nss_cert_database_) |
43 return nss_cert_database_.get(); | 45 return nss_cert_database_.get(); |
44 | 46 |
45 ready_callback_list_.push_back(callback); | 47 ready_callback_list_.push_back(callback); |
46 return NULL; | 48 return NULL; |
47 } | 49 } |
48 | 50 |
49 private: | 51 private: |
50 typedef std::vector<GetNSSCertDatabaseCallback> ReadyCallbackList; | 52 typedef std::vector<GetNSSCertDatabaseCallback> ReadyCallbackList; |
51 | 53 |
52 void DidGetPrivateSlot(crypto::ScopedPK11Slot private_slot) { | 54 void DidGetPrivateSlot(crypto::ScopedPK11Slot private_slot) { |
53 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 55 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
54 nss_cert_database_.reset(new net::NSSCertDatabaseChromeOS( | 56 nss_cert_database_.reset(new net::NSSCertDatabaseChromeOS( |
55 crypto::GetPublicSlotForChromeOSUser(username_hash_), | 57 crypto::GetPublicSlotForChromeOSUser(username_hash_), |
56 private_slot.Pass())); | 58 std::move(private_slot))); |
57 | 59 |
58 ReadyCallbackList callback_list; | 60 ReadyCallbackList callback_list; |
59 callback_list.swap(ready_callback_list_); | 61 callback_list.swap(ready_callback_list_); |
60 for (ReadyCallbackList::iterator i = callback_list.begin(); | 62 for (ReadyCallbackList::iterator i = callback_list.begin(); |
61 i != callback_list.end(); | 63 i != callback_list.end(); |
62 ++i) { | 64 ++i) { |
63 (*i).Run(nss_cert_database_.get()); | 65 (*i).Run(nss_cert_database_.get()); |
64 } | 66 } |
65 } | 67 } |
66 | 68 |
(...skipping 25 matching lines...) Expand all Loading... |
92 } | 94 } |
93 | 95 |
94 void CallWithNSSCertDatabase( | 96 void CallWithNSSCertDatabase( |
95 const base::Callback<void(net::NSSCertDatabase*)>& callback, | 97 const base::Callback<void(net::NSSCertDatabase*)>& callback, |
96 net::NSSCertDatabaseChromeOS* db) { | 98 net::NSSCertDatabaseChromeOS* db) { |
97 callback.Run(db); | 99 callback.Run(db); |
98 } | 100 } |
99 | 101 |
100 void SetSystemSlot(crypto::ScopedPK11Slot system_slot, | 102 void SetSystemSlot(crypto::ScopedPK11Slot system_slot, |
101 net::NSSCertDatabaseChromeOS* db) { | 103 net::NSSCertDatabaseChromeOS* db) { |
102 db->SetSystemSlot(system_slot.Pass()); | 104 db->SetSystemSlot(std::move(system_slot)); |
103 } | 105 } |
104 | 106 |
105 void SetSystemSlotOfDBForResourceContext(content::ResourceContext* context, | 107 void SetSystemSlotOfDBForResourceContext(content::ResourceContext* context, |
106 crypto::ScopedPK11Slot system_slot) { | 108 crypto::ScopedPK11Slot system_slot) { |
107 base::Callback<void(net::NSSCertDatabaseChromeOS*)> callback = | 109 base::Callback<void(net::NSSCertDatabaseChromeOS*)> callback = |
108 base::Bind(&SetSystemSlot, base::Passed(&system_slot)); | 110 base::Bind(&SetSystemSlot, base::Passed(&system_slot)); |
109 | 111 |
110 net::NSSCertDatabaseChromeOS* db = | 112 net::NSSCertDatabaseChromeOS* db = |
111 GetNSSCertDatabaseChromeOS(context, callback); | 113 GetNSSCertDatabaseChromeOS(context, callback); |
112 if (db) | 114 if (db) |
(...skipping 22 matching lines...) Expand all Loading... |
135 context, base::Bind(&CallWithNSSCertDatabase, callback)); | 137 context, base::Bind(&CallWithNSSCertDatabase, callback)); |
136 } | 138 } |
137 | 139 |
138 void EnableNSSSystemKeySlotForResourceContext( | 140 void EnableNSSSystemKeySlotForResourceContext( |
139 content::ResourceContext* context) { | 141 content::ResourceContext* context) { |
140 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 142 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
141 base::Callback<void(crypto::ScopedPK11Slot)> callback = | 143 base::Callback<void(crypto::ScopedPK11Slot)> callback = |
142 base::Bind(&SetSystemSlotOfDBForResourceContext, context); | 144 base::Bind(&SetSystemSlotOfDBForResourceContext, context); |
143 crypto::ScopedPK11Slot system_slot = crypto::GetSystemNSSKeySlot(callback); | 145 crypto::ScopedPK11Slot system_slot = crypto::GetSystemNSSKeySlot(callback); |
144 if (system_slot) | 146 if (system_slot) |
145 callback.Run(system_slot.Pass()); | 147 callback.Run(std::move(system_slot)); |
146 } | 148 } |
OLD | NEW |