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

Side by Side Diff: Source/modules/serviceworkers/FetchBodyStream.cpp

Issue 390673002: Replace uses of {un}setPendingActivity() in FetchBodyStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 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
« no previous file with comments | « Source/modules/serviceworkers/FetchBodyStream.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "modules/serviceworkers/FetchBodyStream.h" 6 #include "modules/serviceworkers/FetchBodyStream.h"
7 7
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/V8ThrowException.h" 10 #include "bindings/core/v8/V8ThrowException.h"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/fileapi/Blob.h" 12 #include "core/fileapi/Blob.h"
13 #include "core/fileapi/FileReaderLoader.h" 13 #include "core/fileapi/FileReaderLoader.h"
14 #include "core/fileapi/FileReaderLoaderClient.h" 14 #include "core/fileapi/FileReaderLoaderClient.h"
15 #include "modules/serviceworkers/ResponseInit.h" 15 #include "modules/serviceworkers/ResponseInit.h"
16 #include "platform/NotImplemented.h" 16 #include "platform/NotImplemented.h"
17 #include "public/platform/WebServiceWorkerResponse.h" 17 #include "public/platform/WebServiceWorkerResponse.h"
18 18
19 namespace WebCore { 19 namespace WebCore {
20 20
21 PassRefPtrWillBeRawPtr<FetchBodyStream> FetchBodyStream::create(ExecutionContext * context, PassRefPtr<BlobDataHandle> blobDataHandle) 21 PassRefPtrWillBeRawPtr<FetchBodyStream> FetchBodyStream::create(ExecutionContext * context, PassRefPtr<BlobDataHandle> blobDataHandle)
22 { 22 {
23 RefPtrWillBeRawPtr<FetchBodyStream> fetchBodyStream(adoptRefWillBeRefCounted GarbageCollected(new FetchBodyStream(context, blobDataHandle))); 23 RefPtrWillBeRawPtr<FetchBodyStream> fetchBodyStream(adoptRefWillBeNoop(new F etchBodyStream(context, blobDataHandle)));
24 fetchBodyStream->suspendIfNeeded(); 24 fetchBodyStream->suspendIfNeeded();
25 return fetchBodyStream.release(); 25 return fetchBodyStream.release();
26 } 26 }
27 27
28 ScriptPromise FetchBodyStream::readAsync(ScriptState* scriptState, ResponseType type) 28 ScriptPromise FetchBodyStream::readAsync(ScriptState* scriptState, ResponseType type)
29 { 29 {
30 if (m_hasRead) 30 if (m_hasRead)
31 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("Already read", scriptState->isolate())); 31 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("Already read", scriptState->isolate()));
32 32
33 m_hasRead = true; 33 m_hasRead = true;
(...skipping 17 matching lines...) Expand all
51 // FIXME: Implement this. 51 // FIXME: Implement this.
52 ASSERT_NOT_REACHED(); 52 ASSERT_NOT_REACHED();
53 break; 53 break;
54 case ResponseAsJSON: 54 case ResponseAsJSON:
55 case ResponseAsText: 55 case ResponseAsText:
56 break; 56 break;
57 default: 57 default:
58 ASSERT_NOT_REACHED(); 58 ASSERT_NOT_REACHED();
59 } 59 }
60 60
61 setPendingActivity(this);
62 m_loader = adoptPtr(new FileReaderLoader(readType, this)); 61 m_loader = adoptPtr(new FileReaderLoader(readType, this));
63 m_loader->start(scriptState->executionContext(), m_blobDataHandle); 62 m_loader->start(scriptState->executionContext(), m_blobDataHandle);
64 63
65 return promise; 64 return promise;
66 } 65 }
67 66
68 ScriptPromise FetchBodyStream::asArrayBuffer(ScriptState* scriptState) 67 ScriptPromise FetchBodyStream::asArrayBuffer(ScriptState* scriptState)
69 { 68 {
70 return readAsync(scriptState, ResponseAsArrayBuffer); 69 return readAsync(scriptState, ResponseAsArrayBuffer);
71 } 70 }
(...skipping 18 matching lines...) Expand all
90 return readAsync(scriptState, ResponseAsText); 89 return readAsync(scriptState, ResponseAsText);
91 } 90 }
92 91
93 void FetchBodyStream::stop() 92 void FetchBodyStream::stop()
94 { 93 {
95 // Canceling the load will call didFail which will remove the resolver. 94 // Canceling the load will call didFail which will remove the resolver.
96 if (m_resolver) 95 if (m_resolver)
97 m_loader->cancel(); 96 m_loader->cancel();
98 } 97 }
99 98
99 bool FetchBodyStream::hasPendingActivity() const
100 {
101 return m_resolver;
102 }
103
100 FetchBodyStream::FetchBodyStream(ExecutionContext* context, PassRefPtr<BlobDataH andle> blobDataHandle) 104 FetchBodyStream::FetchBodyStream(ExecutionContext* context, PassRefPtr<BlobDataH andle> blobDataHandle)
101 : ActiveDOMObject(context) 105 : ActiveDOMObject(context)
102 , m_blobDataHandle(blobDataHandle) 106 , m_blobDataHandle(blobDataHandle)
103 , m_hasRead(false) 107 , m_hasRead(false)
104 { 108 {
105 ScriptWrappable::init(this); 109 ScriptWrappable::init(this);
106 } 110 }
107 111
108 void FetchBodyStream::resolveJSON() 112 void FetchBodyStream::resolveJSON()
109 { 113 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 case ResponseAsJSON: 146 case ResponseAsJSON:
143 resolveJSON(); 147 resolveJSON();
144 break; 148 break;
145 case ResponseAsText: 149 case ResponseAsText:
146 m_resolver->resolve(m_loader->stringResult()); 150 m_resolver->resolve(m_loader->stringResult());
147 break; 151 break;
148 default: 152 default:
149 ASSERT_NOT_REACHED(); 153 ASSERT_NOT_REACHED();
150 } 154 }
151 m_resolver.clear(); 155 m_resolver.clear();
152 unsetPendingActivity(this);
153 return;
154 } 156 }
155 157
156 void FetchBodyStream::didFail(FileError::ErrorCode code) 158 void FetchBodyStream::didFail(FileError::ErrorCode code)
157 { 159 {
158 ASSERT(m_resolver); 160 ASSERT(m_resolver);
159 m_resolver->resolve(""); 161 m_resolver->resolve("");
160 m_resolver.clear(); 162 m_resolver.clear();
161 unsetPendingActivity(this);
162 } 163 }
163 164
164 } // namespace WebCore 165 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/FetchBodyStream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698