Chromium Code Reviews| Index: Source/modules/crypto/CryptoResultImpl.h |
| diff --git a/Source/modules/crypto/CryptoResultImpl.h b/Source/modules/crypto/CryptoResultImpl.h |
| index b6cb6e90126c8290fdfbbd3a2172afc230868247..a06d1687d7455f467cbec95e604ec2490f433bc4 100644 |
| --- a/Source/modules/crypto/CryptoResultImpl.h |
| +++ b/Source/modules/crypto/CryptoResultImpl.h |
| @@ -37,10 +37,10 @@ |
| #include "platform/CryptoResult.h" |
| #include "public/platform/WebCrypto.h" |
| #include "wtf/Forward.h" |
| +#include "wtf/ThreadingPrimitives.h" |
| namespace blink { |
| -class ScriptPromiseResolver; |
| MODULES_EXPORT ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType); |
| // Wrapper around a Promise to notify completion of the crypto operation. |
| @@ -50,40 +50,71 @@ MODULES_EXPORT ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType); |
| // |
| // * At creation time there must be an active ExecutionContext. |
| // * The CryptoResult interface must only be called from the origin thread. |
| -// * ref(), deref(), cancelled() and cancel() can be called from any thread. |
| +// * cancel() can only be called from the origin thread. |
|
eroman
2015/07/31 23:40:30
I suggest generalizing this comment, by replacing
sof
2015/08/01 06:44:31
Reworded.
|
| +// * ref(), deref() can be called from any thread. |
| // * One of the completeWith***() functions must be called, or the |
| // m_resolver will be leaked until the ExecutionContext is destroyed. |
| class CryptoResultImpl final : public CryptoResult { |
| public: |
| - ~CryptoResultImpl(); |
| - |
| static PassRefPtrWillBeRawPtr<CryptoResultImpl> create(ScriptState*); |
| + ~CryptoResultImpl(); |
| + |
| void completeWithError(WebCryptoErrorType, const WebString&) override; |
| void completeWithBuffer(const void* bytes, unsigned bytesSize) override; |
| void completeWithJson(const char* utf8Data, unsigned length) override; |
| void completeWithBoolean(bool) override; |
| void completeWithKey(const WebCryptoKey&) override; |
| void completeWithKeyPair(const WebCryptoKey& publicKey, const WebCryptoKey& privateKey) override; |
| - bool cancelled() const override; |
| // If called after completion (including cancellation) will return an empty |
| // ScriptPromise. |
| ScriptPromise promise(); |
| + WebCryptoResult result() |
| + { |
| + return WebCryptoResult(this, m_cancel.get()); |
| + } |
| + |
| + DECLARE_VIRTUAL_TRACE(); |
| + |
| private: |
| - class Resolver; |
| explicit CryptoResultImpl(ScriptState*); |
| - void clearResolver(); |
| + class Resolver; |
|
eroman
2015/07/31 23:40:30
style nit: I thought these declarations were expec
sof
2015/08/01 06:44:31
Swapped the ordering back to what it was.
|
| + class ResultCancel : public CryptoResultCancel { |
| + public: |
| + static PassRefPtr<ResultCancel> create() |
| + { |
| + return adoptRef(new ResultCancel); |
| + } |
| + |
| + bool cancelled() const override; |
| + |
| + void cancel(); |
| + private: |
| + ResultCancel(); |
| + |
| + int m_cancelled; |
| + }; |
| + |
| void cancel(); |
| + void clearResolver(); |
| + |
| + RawPtrWillBeMember<Resolver> m_resolver; |
| - // FIXME: ScriptPromiseResolver should not be exported. |
| - // Instead, use ScriptPromise. |
| - ScriptPromiseResolver* m_resolver; |
| - volatile int m_cancelled; |
| + // Separately communicate cancellation to WebCryptoResults so as to |
| + // allow this result object, which will be on the Oilpan heap, to be |
| + // GCed and destructed as needed. That is, it may end being GCed while |
| + // the thread owning the heap is detached and shut down, which will |
| + // in some cases happen before corresponding webcrypto operations have |
| + // all been processed. Hence these webcrypto operations cannot reliably |
| + // check cancellation status via this result object. So, keep a separate |
| + // cancellation status object for the purpose, which will outlive the |
| + // result object and can be safely accessed by multiple threads. |
| + RefPtr<ResultCancel> m_cancel; |
| }; |
| } // namespace blink |
| -#endif |
| +#endif // CryptoResultImpl_h |