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

Side by Side Diff: content/browser/service_worker/service_worker_cache_writer.h

Issue 1704293002: ServiceWorker: Stop asynchronously creating response accessors to fix crash due to null context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | content/browser/service_worker/service_worker_cache_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_WRITER_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_WRITER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_WRITER_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_WRITER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 23 matching lines...) Expand all
34 // Note that writes done by this class cannot be "short" - ie, if they succeed, 34 // Note that writes done by this class cannot be "short" - ie, if they succeed,
35 // they always write all the supplied data back. Therefore completions are 35 // they always write all the supplied data back. Therefore completions are
36 // signalled with net::Error without a count of bytes written. 36 // signalled with net::Error without a count of bytes written.
37 // 37 //
38 // This class's behavior is modelled as a state machine; see the DoLoop function 38 // This class's behavior is modelled as a state machine; see the DoLoop function
39 // for comments about this. 39 // for comments about this.
40 class CONTENT_EXPORT ServiceWorkerCacheWriter { 40 class CONTENT_EXPORT ServiceWorkerCacheWriter {
41 public: 41 public:
42 using OnWriteCompleteCallback = base::Callback<void(net::Error)>; 42 using OnWriteCompleteCallback = base::Callback<void(net::Error)>;
43 43
44 // The types for the factory functions passed into the constructor. These are
45 // responsible for creating readers from the existing cache entry and writers
46 // to the new cache entry when called. These are passed in as factories
47 // instead of passing readers and writers in directly to avoid creating
48 // writers to entries that won't be updated, and because this class may need
49 // multiple readers internally.
nhiroki 2016/02/18 04:21:53 Creating unused readers and writers wouldn't cost
falken 2016/02/18 04:43:59 Thanks for this comment, I was wondering why it wa
50 using ResponseReaderCreator =
51 base::Callback<scoped_ptr<ServiceWorkerResponseReader>(void)>;
52 using ResponseWriterCreator =
53 base::Callback<scoped_ptr<ServiceWorkerResponseWriter>(void)>;
54
55 // The existing reader may be null, in which case this instance will 44 // The existing reader may be null, in which case this instance will
falken 2016/02/18 04:43:59 change "existing reader" to |compare_reader|
nhiroki 2016/02/18 07:09:48 Done.
56 // unconditionally write back data supplied to |MaybeWriteHeaders| and 45 // unconditionally write back data supplied to |MaybeWriteHeaders| and
57 // |MaybeWriteData|. 46 // |MaybeWriteData|.
58 ServiceWorkerCacheWriter(const ResponseReaderCreator& reader_creator, 47 ServiceWorkerCacheWriter(
59 const ResponseWriterCreator& writer_creator); 48 scoped_ptr<ServiceWorkerResponseReader> compare_reader,
49 scoped_ptr<ServiceWorkerResponseReader> copy_reader,
50 scoped_ptr<ServiceWorkerResponseWriter> writer);
60 51
61 ~ServiceWorkerCacheWriter(); 52 ~ServiceWorkerCacheWriter();
62 53
63 // Writes the supplied |headers| back to the cache. Returns ERR_IO_PENDING if 54 // Writes the supplied |headers| back to the cache. Returns ERR_IO_PENDING if
64 // the write will complete asynchronously, in which case |callback| will be 55 // the write will complete asynchronously, in which case |callback| will be
65 // called when it completes. Otherwise, returns a code other than 56 // called when it completes. Otherwise, returns a code other than
66 // ERR_IO_PENDING and does not invoke |callback|. Note that this method will 57 // ERR_IO_PENDING and does not invoke |callback|. Note that this method will
67 // not necessarily write data back to the cache if the incoming data is 58 // not necessarily write data back to the cache if the incoming data is
68 // equivalent to the existing cached data. See the source of this function for 59 // equivalent to the existing cached data. See the source of this function for
69 // details about how this function drives the state machine. 60 // details about how this function drives the state machine.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 size_t cached_length_; 203 size_t cached_length_;
213 204
214 size_t bytes_compared_; 205 size_t bytes_compared_;
215 size_t bytes_copied_; 206 size_t bytes_copied_;
216 size_t bytes_written_; 207 size_t bytes_written_;
217 208
218 bool did_replace_; 209 bool did_replace_;
219 210
220 size_t compare_offset_; 211 size_t compare_offset_;
221 212
222 ResponseReaderCreator reader_creator_;
223 ResponseWriterCreator writer_creator_;
224 scoped_ptr<ServiceWorkerResponseReader> compare_reader_; 213 scoped_ptr<ServiceWorkerResponseReader> compare_reader_;
225 scoped_ptr<ServiceWorkerResponseReader> copy_reader_; 214 scoped_ptr<ServiceWorkerResponseReader> copy_reader_;
226 scoped_ptr<ServiceWorkerResponseWriter> writer_; 215 scoped_ptr<ServiceWorkerResponseWriter> writer_;
227 base::WeakPtrFactory<ServiceWorkerCacheWriter> weak_factory_; 216 base::WeakPtrFactory<ServiceWorkerCacheWriter> weak_factory_;
228 }; 217 };
229 218
230 } // namespace content 219 } // namespace content
231 220
232 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_WRITER_H_ 221 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_WRITER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_cache_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698