| OLD | NEW |
| 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 "content/browser/loader/stream_writer.h" | 5 #include "content/browser/loader/stream_writer.h" |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "content/browser/streams/stream.h" | 8 #include "content/browser/streams/stream.h" |
| 9 #include "content/browser/streams/stream_registry.h" | 9 #include "content/browser/streams/stream_registry.h" |
| 10 #include "content/public/browser/resource_controller.h" | 10 #include "content/public/browser/resource_controller.h" |
| 11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 #include "url/url_constants.h" | 13 #include "url/url_constants.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 StreamWriter::StreamWriter() : controller_(nullptr), immediate_mode_(false) { | 17 StreamWriter::StreamWriter() : controller_(nullptr), immediate_mode_(false) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 StreamWriter::~StreamWriter() { | 20 StreamWriter::~StreamWriter() { |
| 21 if (stream_.get()) | 21 if (stream_.get()) |
| 22 Finalize(); | 22 Finalize(0); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void StreamWriter::InitializeStream(StreamRegistry* registry, | 25 void StreamWriter::InitializeStream(StreamRegistry* registry, |
| 26 const GURL& origin) { | 26 const GURL& origin) { |
| 27 DCHECK(!stream_.get()); | 27 DCHECK(!stream_.get()); |
| 28 | 28 |
| 29 // TODO(tyoshino): Find a way to share this with the blob URL creation in | 29 // TODO(tyoshino): Find a way to share this with the blob URL creation in |
| 30 // WebKit. | 30 // WebKit. |
| 31 GURL url(std::string(url::kBlobScheme) + ":" + origin.spec() + | 31 GURL url(std::string(url::kBlobScheme) + ":" + origin.spec() + |
| 32 base::GenerateGUID()); | 32 base::GenerateGUID()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 60 read_buffer_.swap(buffer); | 60 read_buffer_.swap(buffer); |
| 61 stream_->AddData(buffer, bytes_read); | 61 stream_->AddData(buffer, bytes_read); |
| 62 | 62 |
| 63 if (immediate_mode_) | 63 if (immediate_mode_) |
| 64 stream_->Flush(); | 64 stream_->Flush(); |
| 65 | 65 |
| 66 if (!stream_->can_add_data()) | 66 if (!stream_->can_add_data()) |
| 67 *defer = true; | 67 *defer = true; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void StreamWriter::Finalize() { | 70 void StreamWriter::Finalize(int status) { |
| 71 DCHECK(stream_.get()); | 71 DCHECK(stream_.get()); |
| 72 stream_->Finalize(); | 72 stream_->Finalize(status); |
| 73 stream_->RemoveWriteObserver(this); | 73 stream_->RemoveWriteObserver(this); |
| 74 stream_ = nullptr; | 74 stream_ = nullptr; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void StreamWriter::OnSpaceAvailable(Stream* stream) { | 77 void StreamWriter::OnSpaceAvailable(Stream* stream) { |
| 78 controller_->Resume(); | 78 controller_->Resume(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void StreamWriter::OnClose(Stream* stream) { | 81 void StreamWriter::OnClose(Stream* stream) { |
| 82 controller_->Cancel(); | 82 controller_->Cancel(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace content | 85 } // namespace content |
| OLD | NEW |