OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/loader/stream_writer.h" | |
6 | |
7 #include "base/guid.h" | |
8 #include "content/browser/streams/stream.h" | |
9 #include "content/browser/streams/stream_registry.h" | |
10 #include "content/public/browser/resource_controller.h" | |
11 #include "net/base/io_buffer.h" | |
12 #include "url/gurl.h" | |
13 #include "url/url_constants.h" | |
14 | |
15 namespace content { | |
16 | |
17 StreamWriter::StreamWriter() { | |
18 } | |
19 | |
20 StreamWriter::~StreamWriter() { | |
21 if (stream_.get()) | |
22 Finalize(); | |
23 } | |
24 | |
25 void StreamWriter::InitializeStream(StreamRegistry* registry, | |
26 const GURL& origin) { | |
27 DCHECK(!stream_.get()); | |
28 | |
29 // TODO(tyoshino): Find a way to share this with the blob URL creation in | |
30 // WebKit. | |
31 GURL url(std::string(url::kBlobScheme) + ":" + origin.spec() + | |
32 base::GenerateGUID()); | |
mmenke
2014/09/23 17:22:45
Erm...Wait...So after navigation occurs, we redire
davidben
2014/10/03 16:27:53
Yeah. We're going to get the flow working this way
| |
33 stream_ = new Stream(registry, this, url); | |
34 } | |
35 | |
36 void StreamWriter::OnWillRead(scoped_refptr<net::IOBuffer>* buf, | |
37 int* buf_size, | |
38 int min_size) { | |
39 static const int kReadBufSize = 32768; | |
mmenke
2014/09/23 17:22:46
Can static const int result in something first bei
davidben
2014/10/03 16:27:53
I would expect it to be fine. At least, we do do i
| |
40 | |
41 DCHECK(buf && buf_size); | |
mmenke
2014/09/23 17:22:46
nit: Use two DCHECKs. The one for buf_size shoul
davidben
2014/10/03 16:27:53
Done. (Except buf_size is a pointer, so still just
| |
42 if (!read_buffer_.get()) | |
43 read_buffer_ = new net::IOBuffer(kReadBufSize); | |
44 *buf = read_buffer_.get(); | |
45 *buf_size = kReadBufSize; | |
46 } | |
47 | |
48 void StreamWriter::OnReadCompleted(int bytes_read, bool* defer) { | |
49 if (!bytes_read) | |
50 return; | |
51 | |
52 // We have more data to read. | |
53 DCHECK(read_buffer_.get()); | |
54 | |
55 // Release the ownership of the buffer, and store a reference | |
56 // to it. A new one will be allocated in OnWillRead(). | |
57 scoped_refptr<net::IOBuffer> buffer; | |
58 read_buffer_.swap(buffer); | |
59 stream_->AddData(buffer, bytes_read); | |
60 | |
61 if (!stream_->can_add_data()) | |
62 *defer = true; | |
63 } | |
64 | |
65 void StreamWriter::Finalize() { | |
66 DCHECK(stream_.get()); | |
67 stream_->Finalize(); | |
68 stream_->RemoveWriteObserver(this); | |
69 stream_ = NULL; | |
70 } | |
71 | |
72 void StreamWriter::OnSpaceAvailable(Stream* stream) { | |
73 controller_->Resume(); | |
74 } | |
75 | |
76 void StreamWriter::OnClose(Stream* stream) { | |
77 controller_->Cancel(); | |
78 } | |
79 | |
80 } // namespace content | |
OLD | NEW |