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

Unified Diff: components/webcrypto/webcrypto_impl.cc

Issue 2088323002: Update some WebCrypto comments to better describe the threading reality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix a typo "mutated" --> "mutate" Created 4 years, 6 months 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/webcrypto/blink_key_handle.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/webcrypto/webcrypto_impl.cc
diff --git a/components/webcrypto/webcrypto_impl.cc b/components/webcrypto/webcrypto_impl.cc
index 5712854e557850908760ddaee65a768696d24868..7986b7741148e12e16ede9dbc6b392352cf098f5 100644
--- a/components/webcrypto/webcrypto_impl.cc
+++ b/components/webcrypto/webcrypto_impl.cc
@@ -36,10 +36,7 @@ namespace {
// ---------------------
//
// WebCrypto operations can be slow. For instance generating an RSA key can
-// seconds.
-//
-// Moreover the underlying crypto libraries are not threadsafe when operating
-// on the same key.
+// take seconds.
//
// The strategy used here is to run a sequenced worker pool for all WebCrypto
// operations (except structured cloning). This same pool is also used by
@@ -47,26 +44,24 @@ namespace {
//
// A few notes to keep in mind:
//
-// * PostTaskAndReply() cannot be used for two reasons:
-//
-// (1) Blink web worker threads do not have an associated message loop so
-// construction of the reply callback will crash.
+// * PostTaskAndReply() is not used because of how it handles failures -- it
+// leaks the callback when failing to post back to the origin thread.
//
-// (2) PostTaskAndReply() handles failure posting the reply by leaking the
-// callback, rather than destroying it. In the case of Web Workers this
-// condition is reachable via normal execution, since Web Workers can
-// be stopped before the WebCrypto operation has finished. A policy of
-// leaking would therefore be problematic.
+// This is a problem since WebCrypto may be called from WebWorker threads,
+// which may be aborted at any time. Leaking would be undesirable, and
+// reachable in practice.
//
// * blink::WebArrayBuffer is NOT threadsafe, and should therefore be allocated
-// on the target Blink thread.
+// only on the target Blink thread.
//
// TODO(eroman): Is there any way around this? Copying the result between
// threads is silly.
//
-// * WebCryptoAlgorithm and WebCryptoKey are threadsafe (however the key's
-// handle(), which wraps an OpenSSL type, may not be and should only be
-// used from the webcrypto thread).
+// * WebCryptoAlgorithm and WebCryptoKey are threadsafe, by virtue of being
+// immutable. Internally asymmetric WebCryptoKeys wrap BoringSSL's EVP_PKEY.
+// These are safe to use for BoringSSL operations across threads, provided
+// the internals of the EVP_PKEY are not mutated (they never should be
+// following ImportKey()).
//
// * blink::WebCryptoResult is not threadsafe and should only be operated on
// the target Blink thread. HOWEVER, it is safe to delete it from any thread.
« no previous file with comments | « components/webcrypto/blink_key_handle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698