OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/chromeos/certificate_provider/certificate_provider_serv
ice_factory.h" | 5 #include "chrome/browser/chromeos/certificate_provider/certificate_provider_serv
ice_factory.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <string> | 8 #include <string> |
8 #include <utility> | 9 #include <utility> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
13 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "chrome/browser/chromeos/certificate_provider/certificate_provider_serv
ice.h" | 18 #include "chrome/browser/chromeos/certificate_provider/certificate_provider_serv
ice.h" |
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
19 #include "chrome/browser/profiles/incognito_helpers.h" | 20 #include "chrome/browser/profiles/incognito_helpers.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/extensions/api/certificate_provider.h" | 22 #include "chrome/common/extensions/api/certificate_provider.h" |
22 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 23 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
23 #include "extensions/browser/event_listener_map.h" | 24 #include "extensions/browser/event_listener_map.h" |
24 #include "extensions/browser/event_router.h" | 25 #include "extensions/browser/event_router.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 std::vector<std::string> ids; | 88 std::vector<std::string> ids; |
88 for (const auto& listener : | 89 for (const auto& listener : |
89 event_router_->listeners().GetEventListenersByName(event_name)) { | 90 event_router_->listeners().GetEventListenersByName(event_name)) { |
90 ids.push_back(listener->extension_id()); | 91 ids.push_back(listener->extension_id()); |
91 } | 92 } |
92 return ids; | 93 return ids; |
93 } | 94 } |
94 | 95 |
95 void DefaultDelegate::BroadcastCertificateRequest(int request_id) { | 96 void DefaultDelegate::BroadcastCertificateRequest(int request_id) { |
96 const std::string event_name(api_cp::OnCertificatesRequested::kEventName); | 97 const std::string event_name(api_cp::OnCertificatesRequested::kEventName); |
97 scoped_ptr<base::ListValue> internal_args(new base::ListValue); | 98 std::unique_ptr<base::ListValue> internal_args(new base::ListValue); |
98 internal_args->AppendInteger(request_id); | 99 internal_args->AppendInteger(request_id); |
99 scoped_ptr<extensions::Event> event(new extensions::Event( | 100 std::unique_ptr<extensions::Event> event(new extensions::Event( |
100 extensions::events::CERTIFICATEPROVIDER_ON_CERTIFICATES_REQUESTED, | 101 extensions::events::CERTIFICATEPROVIDER_ON_CERTIFICATES_REQUESTED, |
101 event_name, std::move(internal_args))); | 102 event_name, std::move(internal_args))); |
102 event_router_->BroadcastEvent(std::move(event)); | 103 event_router_->BroadcastEvent(std::move(event)); |
103 } | 104 } |
104 | 105 |
105 bool DefaultDelegate::DispatchSignRequestToExtension( | 106 bool DefaultDelegate::DispatchSignRequestToExtension( |
106 const std::string& extension_id, | 107 const std::string& extension_id, |
107 int request_id, | 108 int request_id, |
108 net::SSLPrivateKey::Hash hash, | 109 net::SSLPrivateKey::Hash hash, |
109 const scoped_refptr<net::X509Certificate>& certificate, | 110 const scoped_refptr<net::X509Certificate>& certificate, |
(...skipping 22 matching lines...) Expand all Loading... |
132 } | 133 } |
133 request.digest.assign(digest.begin(), digest.end()); | 134 request.digest.assign(digest.begin(), digest.end()); |
134 std::string cert_der; | 135 std::string cert_der; |
135 if (!net::X509Certificate::GetDEREncoded(certificate->os_cert_handle(), | 136 if (!net::X509Certificate::GetDEREncoded(certificate->os_cert_handle(), |
136 &cert_der)) { | 137 &cert_der)) { |
137 LOG(ERROR) << "Could not DER encode the certificate."; | 138 LOG(ERROR) << "Could not DER encode the certificate."; |
138 return false; // Behave as if the extension wasn't registered anymore. | 139 return false; // Behave as if the extension wasn't registered anymore. |
139 } | 140 } |
140 request.certificate.assign(cert_der.begin(), cert_der.end()); | 141 request.certificate.assign(cert_der.begin(), cert_der.end()); |
141 | 142 |
142 scoped_ptr<base::ListValue> internal_args(new base::ListValue); | 143 std::unique_ptr<base::ListValue> internal_args(new base::ListValue); |
143 internal_args->AppendInteger(request_id); | 144 internal_args->AppendInteger(request_id); |
144 internal_args->Append(request.ToValue()); | 145 internal_args->Append(request.ToValue()); |
145 | 146 |
146 event_router_->DispatchEventToExtension( | 147 event_router_->DispatchEventToExtension( |
147 extension_id, | 148 extension_id, |
148 make_scoped_ptr(new extensions::Event( | 149 base::WrapUnique(new extensions::Event( |
149 extensions::events::CERTIFICATEPROVIDER_ON_SIGN_DIGEST_REQUESTED, | 150 extensions::events::CERTIFICATEPROVIDER_ON_SIGN_DIGEST_REQUESTED, |
150 event_name, std::move(internal_args)))); | 151 event_name, std::move(internal_args)))); |
151 return true; | 152 return true; |
152 } | 153 } |
153 | 154 |
154 void DefaultDelegate::OnExtensionUnloaded( | 155 void DefaultDelegate::OnExtensionUnloaded( |
155 content::BrowserContext* browser_context, | 156 content::BrowserContext* browser_context, |
156 const extensions::Extension* extension, | 157 const extensions::Extension* extension, |
157 extensions::UnloadedExtensionInfo::Reason reason) { | 158 extensions::UnloadedExtensionInfo::Reason reason) { |
158 service_->OnExtensionUnloaded(extension->id()); | 159 service_->OnExtensionUnloaded(extension->id()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 return true; | 193 return true; |
193 } | 194 } |
194 | 195 |
195 KeyedService* CertificateProviderServiceFactory::BuildServiceInstanceFor( | 196 KeyedService* CertificateProviderServiceFactory::BuildServiceInstanceFor( |
196 content::BrowserContext* context) const { | 197 content::BrowserContext* context) const { |
197 if (chromeos::ProfileHelper::IsSigninProfile( | 198 if (chromeos::ProfileHelper::IsSigninProfile( |
198 Profile::FromBrowserContext(context))) { | 199 Profile::FromBrowserContext(context))) { |
199 return nullptr; | 200 return nullptr; |
200 } | 201 } |
201 CertificateProviderService* const service = new CertificateProviderService(); | 202 CertificateProviderService* const service = new CertificateProviderService(); |
202 service->SetDelegate(make_scoped_ptr(new DefaultDelegate( | 203 service->SetDelegate(base::WrapUnique(new DefaultDelegate( |
203 service, | 204 service, |
204 extensions::ExtensionRegistryFactory::GetForBrowserContext(context), | 205 extensions::ExtensionRegistryFactory::GetForBrowserContext(context), |
205 extensions::EventRouterFactory::GetForBrowserContext(context)))); | 206 extensions::EventRouterFactory::GetForBrowserContext(context)))); |
206 return service; | 207 return service; |
207 } | 208 } |
208 | 209 |
209 } // namespace chromeos | 210 } // namespace chromeos |
OLD | NEW |