| OLD | NEW |
| 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 #include "content/browser/devtools/devtools_io_context.h" | 5 #include "content/browser/devtools/devtools_io_context.h" |
| 6 | 6 |
| 7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 return true; | 56 return true; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void Stream::Read(off_t position, size_t max_size, ReadCallback callback) { | 59 void Stream::Read(off_t position, size_t max_size, ReadCallback callback) { |
| 60 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 60 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 61 base::Bind(&Stream::ReadOnFileThread, this, position, max_size, | 61 base::Bind(&Stream::ReadOnFileThread, this, position, max_size, |
| 62 callback)); | 62 callback)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void Stream::Append(const scoped_refptr<base::RefCountedString>& data) { | 65 void Stream::Append(std::unique_ptr<std::string> data) { |
| 66 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 66 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 67 base::Bind(&Stream::AppendOnFileThread, this, data)); | 67 base::Bind(&Stream::AppendOnFileThread, this, |
| 68 base::Passed(std::move(data)))); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void Stream::ReadOnFileThread(off_t position, size_t max_size, | 71 void Stream::ReadOnFileThread(off_t position, size_t max_size, |
| 71 ReadCallback callback) { | 72 ReadCallback callback) { |
| 72 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 73 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 73 Status status = StatusFailure; | 74 Status status = StatusFailure; |
| 74 scoped_refptr<base::RefCountedString> data; | 75 scoped_refptr<base::RefCountedString> data; |
| 75 | 76 |
| 76 if (file_.IsValid()) { | 77 if (file_.IsValid()) { |
| 77 std::string buffer; | 78 std::string buffer; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 94 } | 95 } |
| 95 data = base::RefCountedString::TakeString(&buffer); | 96 data = base::RefCountedString::TakeString(&buffer); |
| 96 status = size_got ? StatusSuccess : StatusEOF; | 97 status = size_got ? StatusSuccess : StatusEOF; |
| 97 last_read_pos_ = position + size_got; | 98 last_read_pos_ = position + size_got; |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 101 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 101 base::Bind(callback, data, status)); | 102 base::Bind(callback, data, status)); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void Stream::AppendOnFileThread( | 105 void Stream::AppendOnFileThread(std::unique_ptr<std::string> data) { |
| 105 const scoped_refptr<base::RefCountedString>& data) { | |
| 106 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 106 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 107 if (!InitOnFileThreadIfNeeded()) | 107 if (!InitOnFileThreadIfNeeded()) |
| 108 return; | 108 return; |
| 109 const std::string& buffer = data->data(); | 109 int size_written = file_.WriteAtCurrentPos(data->data(), data->size()); |
| 110 int size_written = file_.WriteAtCurrentPos(&*buffer.begin(), buffer.size()); | 110 if (size_written != static_cast<int>(data->size())) { |
| 111 if (size_written != static_cast<int>(buffer.size())) { | |
| 112 LOG(ERROR) << "Failed to write temporary file"; | 111 LOG(ERROR) << "Failed to write temporary file"; |
| 113 had_errors_ = true; | 112 had_errors_ = true; |
| 114 file_.Close(); | 113 file_.Close(); |
| 115 } | 114 } |
| 116 } | 115 } |
| 117 | 116 |
| 118 DevToolsIOContext::DevToolsIOContext() {} | 117 DevToolsIOContext::DevToolsIOContext() {} |
| 119 | 118 |
| 120 DevToolsIOContext::~DevToolsIOContext() {} | 119 DevToolsIOContext::~DevToolsIOContext() {} |
| 121 | 120 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 136 bool DevToolsIOContext::Close(const std::string& handle) { | 135 bool DevToolsIOContext::Close(const std::string& handle) { |
| 137 return streams_.erase(handle) == 1; | 136 return streams_.erase(handle) == 1; |
| 138 } | 137 } |
| 139 | 138 |
| 140 void DevToolsIOContext::DiscardAllStreams() { | 139 void DevToolsIOContext::DiscardAllStreams() { |
| 141 return streams_.clear(); | 140 return streams_.clear(); |
| 142 } | 141 } |
| 143 | 142 |
| 144 } // namespace devtools | 143 } // namespace devtools |
| 145 } // namespace content | 144 } // namespace content |
| OLD | NEW |