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

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

Issue 780793002: Make CryptoResultImpl not to use WeakPtr. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "core/dom/ExecutionContext.h" 43 #include "core/dom/ExecutionContext.h"
44 #include "modules/crypto/CryptoKey.h" 44 #include "modules/crypto/CryptoKey.h"
45 #include "modules/crypto/NormalizeAlgorithm.h" 45 #include "modules/crypto/NormalizeAlgorithm.h"
46 #include "public/platform/Platform.h" 46 #include "public/platform/Platform.h"
47 #include "public/platform/WebCryptoAlgorithm.h" 47 #include "public/platform/WebCryptoAlgorithm.h"
48 48
49 namespace blink { 49 namespace blink {
50 50
51 class CryptoResultImpl::WeakResolver : public ScriptPromiseResolver { 51 class CryptoResultImpl::WeakResolver : public ScriptPromiseResolver {
52 public: 52 public:
53 static WeakPtr<ScriptPromiseResolver> create(ScriptState* scriptState, Crypt oResultImpl* result) 53 static PassRefPtr<ScriptPromiseResolver> create(ScriptState* scriptState, Cr yptoResultImpl* result)
54 { 54 {
55 RefPtr<WeakResolver> p = adoptRef(new WeakResolver(scriptState, result)) ; 55 RefPtr<WeakResolver> p = adoptRef(new WeakResolver(scriptState, result)) ;
56 p->suspendIfNeeded(); 56 p->suspendIfNeeded();
57 p->keepAliveWhilePending(); 57 p->keepAliveWhilePending();
58 return p->m_weakPtrFactory.createWeakPtr(); 58 return p.release();
59 } 59 }
60 60
61 virtual ~WeakResolver() 61 private:
62 virtual void resolverCleared() override
62 { 63 {
63 m_result->cancel(); 64 m_result->cancel();
64 } 65 }
65 66
66 private:
67 WeakResolver(ScriptState* scriptState, CryptoResultImpl* result) 67 WeakResolver(ScriptState* scriptState, CryptoResultImpl* result)
68 : ScriptPromiseResolver(scriptState) 68 : ScriptPromiseResolver(scriptState)
69 , m_weakPtrFactory(this)
70 , m_result(result) { } 69 , m_result(result) { }
71 WeakPtrFactory<ScriptPromiseResolver> m_weakPtrFactory; 70 CryptoResultImpl* m_result;
72 RefPtr<CryptoResultImpl> m_result;
73 }; 71 };
74 72
75 ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType errorType) 73 ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType errorType)
76 { 74 {
77 switch (errorType) { 75 switch (errorType) {
78 case WebCryptoErrorTypeNotSupported: 76 case WebCryptoErrorTypeNotSupported:
79 return NotSupportedError; 77 return NotSupportedError;
80 case WebCryptoErrorTypeSyntax: 78 case WebCryptoErrorTypeSyntax:
81 return SyntaxError; 79 return SyntaxError;
82 case WebCryptoErrorTypeInvalidState: 80 case WebCryptoErrorTypeInvalidState:
(...skipping 12 matching lines...) Expand all
95 // revisited. 93 // revisited.
96 return DataError; 94 return DataError;
97 } 95 }
98 96
99 ASSERT_NOT_REACHED(); 97 ASSERT_NOT_REACHED();
100 return 0; 98 return 0;
101 } 99 }
102 100
103 CryptoResultImpl::~CryptoResultImpl() 101 CryptoResultImpl::~CryptoResultImpl()
104 { 102 {
103 ASSERT(!m_resolver || m_resolver->stopped());
tasak 2014/12/04 08:08:01 Check whether WeakResoler has been already stopped
105 } 104 }
106 105
107 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptState* scriptState) 106 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptState* scriptState)
108 { 107 {
109 return adoptRef(new CryptoResultImpl(scriptState)); 108 return adoptRef(new CryptoResultImpl(scriptState));
110 } 109 }
111 110
112 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web String& errorDetails) 111 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web String& errorDetails)
113 { 112 {
114 if (m_resolver) 113 if (m_resolver)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 171 }
173 172
174 bool CryptoResultImpl::cancelled() const 173 bool CryptoResultImpl::cancelled() const
175 { 174 {
176 return acquireLoad(&m_cancelled); 175 return acquireLoad(&m_cancelled);
177 } 176 }
178 177
179 void CryptoResultImpl::cancel() 178 void CryptoResultImpl::cancel()
180 { 179 {
181 releaseStore(&m_cancelled, 1); 180 releaseStore(&m_cancelled, 1);
181 m_resolver = nullptr;
tasak 2014/12/04 08:08:01 To avoid the following ASSERTION failure, CryptoRe
182 } 182 }
183 183
184 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState) 184 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState)
185 : m_cancelled(0) 185 : m_cancelled(0)
186 { 186 {
187 // Creating the WeakResolver may return nullptr if active dom objects have 187 // Creating the WeakResolver may return nullptr if active dom objects have
188 // been stopped. And in the process set m_cancelled to 1. 188 // been stopped. And in the process set m_cancelled to 1.
189 m_resolver = WeakResolver::create(scriptState, this); 189 m_resolver = WeakResolver::create(scriptState, this);
190 } 190 }
191 191
192 ScriptPromise CryptoResultImpl::promise() 192 ScriptPromise CryptoResultImpl::promise()
193 { 193 {
194 return m_resolver ? m_resolver->promise() : ScriptPromise(); 194 return m_resolver ? m_resolver->promise() : ScriptPromise();
195 } 195 }
196 196
197 } // namespace blink 197 } // namespace blink
OLDNEW
« Source/bindings/core/v8/ScriptPromiseResolver.h ('K') | « Source/modules/crypto/CryptoResultImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698