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

Side by Side Diff: Source/modules/crypto/CryptoResultImpl.h

Issue 1228373006: Reliably cancel in-progress CryptoResult(Impl) upon shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Separate out cancellation handling (+rebase) Created 5 years, 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 30
31 #ifndef CryptoResultImpl_h 31 #ifndef CryptoResultImpl_h
32 #define CryptoResultImpl_h 32 #define CryptoResultImpl_h
33 33
34 #include "bindings/core/v8/ScriptPromise.h" 34 #include "bindings/core/v8/ScriptPromise.h"
35 #include "core/dom/ExceptionCode.h" 35 #include "core/dom/ExceptionCode.h"
36 #include "modules/ModulesExport.h" 36 #include "modules/ModulesExport.h"
37 #include "platform/CryptoResult.h" 37 #include "platform/CryptoResult.h"
38 #include "public/platform/WebCrypto.h" 38 #include "public/platform/WebCrypto.h"
39 #include "wtf/Forward.h" 39 #include "wtf/Forward.h"
40 #include "wtf/ThreadingPrimitives.h"
40 41
41 namespace blink { 42 namespace blink {
42 43
43 class ScriptPromiseResolver;
44 MODULES_EXPORT ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType); 44 MODULES_EXPORT ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType);
45 45
46 // Wrapper around a Promise to notify completion of the crypto operation. 46 // Wrapper around a Promise to notify completion of the crypto operation.
47 // 47 //
48 // The thread on which CryptoResultImpl was created on is referred to as the 48 // The thread on which CryptoResultImpl was created on is referred to as the
49 // "origin thread". 49 // "origin thread".
50 // 50 //
51 // * At creation time there must be an active ExecutionContext. 51 // * At creation time there must be an active ExecutionContext.
52 // * The CryptoResult interface must only be called from the origin thread. 52 // * The CryptoResult interface must only be called from the origin thread.
53 // * ref(), deref(), cancelled() and cancel() can be called from any thread. 53 // * 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.
54 // * ref(), deref() can be called from any thread.
54 // * One of the completeWith***() functions must be called, or the 55 // * One of the completeWith***() functions must be called, or the
55 // m_resolver will be leaked until the ExecutionContext is destroyed. 56 // m_resolver will be leaked until the ExecutionContext is destroyed.
56 class CryptoResultImpl final : public CryptoResult { 57 class CryptoResultImpl final : public CryptoResult {
57 public: 58 public:
59 static PassRefPtrWillBeRawPtr<CryptoResultImpl> create(ScriptState*);
60
58 ~CryptoResultImpl(); 61 ~CryptoResultImpl();
59 62
60 static PassRefPtrWillBeRawPtr<CryptoResultImpl> create(ScriptState*);
61
62 void completeWithError(WebCryptoErrorType, const WebString&) override; 63 void completeWithError(WebCryptoErrorType, const WebString&) override;
63 void completeWithBuffer(const void* bytes, unsigned bytesSize) override; 64 void completeWithBuffer(const void* bytes, unsigned bytesSize) override;
64 void completeWithJson(const char* utf8Data, unsigned length) override; 65 void completeWithJson(const char* utf8Data, unsigned length) override;
65 void completeWithBoolean(bool) override; 66 void completeWithBoolean(bool) override;
66 void completeWithKey(const WebCryptoKey&) override; 67 void completeWithKey(const WebCryptoKey&) override;
67 void completeWithKeyPair(const WebCryptoKey& publicKey, const WebCryptoKey& privateKey) override; 68 void completeWithKeyPair(const WebCryptoKey& publicKey, const WebCryptoKey& privateKey) override;
68 bool cancelled() const override;
69 69
70 // If called after completion (including cancellation) will return an empty 70 // If called after completion (including cancellation) will return an empty
71 // ScriptPromise. 71 // ScriptPromise.
72 ScriptPromise promise(); 72 ScriptPromise promise();
73 73
74 WebCryptoResult result()
75 {
76 return WebCryptoResult(this, m_cancel.get());
77 }
78
79 DECLARE_VIRTUAL_TRACE();
80
74 private: 81 private:
75 class Resolver;
76 explicit CryptoResultImpl(ScriptState*); 82 explicit CryptoResultImpl(ScriptState*);
77 83
84 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.
85 class ResultCancel : public CryptoResultCancel {
86 public:
87 static PassRefPtr<ResultCancel> create()
88 {
89 return adoptRef(new ResultCancel);
90 }
91
92 bool cancelled() const override;
93
94 void cancel();
95 private:
96 ResultCancel();
97
98 int m_cancelled;
99 };
100
101 void cancel();
78 void clearResolver(); 102 void clearResolver();
79 void cancel();
80 103
81 // FIXME: ScriptPromiseResolver should not be exported. 104 RawPtrWillBeMember<Resolver> m_resolver;
82 // Instead, use ScriptPromise. 105
83 ScriptPromiseResolver* m_resolver; 106 // Separately communicate cancellation to WebCryptoResults so as to
84 volatile int m_cancelled; 107 // allow this result object, which will be on the Oilpan heap, to be
108 // GCed and destructed as needed. That is, it may end being GCed while
109 // the thread owning the heap is detached and shut down, which will
110 // in some cases happen before corresponding webcrypto operations have
111 // all been processed. Hence these webcrypto operations cannot reliably
112 // check cancellation status via this result object. So, keep a separate
113 // cancellation status object for the purpose, which will outlive the
114 // result object and can be safely accessed by multiple threads.
115 RefPtr<ResultCancel> m_cancel;
85 }; 116 };
86 117
87 } // namespace blink 118 } // namespace blink
88 119
89 #endif 120 #endif // CryptoResultImpl_h
OLDNEW
« no previous file with comments | « no previous file | Source/modules/crypto/CryptoResultImpl.cpp » ('j') | Source/modules/crypto/CryptoResultImpl.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698