| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/download/save_file_resource_handler.h" | 5 #include "content/browser/download/save_file_resource_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 void SaveFileResourceHandler::OnWillStart( | 63 void SaveFileResourceHandler::OnWillStart( |
| 64 const GURL& url, | 64 const GURL& url, |
| 65 std::unique_ptr<ResourceController> controller) { | 65 std::unique_ptr<ResourceController> controller) { |
| 66 if (authorization_state_ == AuthorizationState::AUTHORIZED) { | 66 if (authorization_state_ == AuthorizationState::AUTHORIZED) { |
| 67 controller->Resume(); | 67 controller->Resume(); |
| 68 } else { | 68 } else { |
| 69 controller->Cancel(); | 69 controller->Cancel(); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool SaveFileResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 73 void SaveFileResourceHandler::OnWillRead( |
| 74 int* buf_size) { | 74 scoped_refptr<net::IOBuffer>* buf, |
| 75 int* buf_size, |
| 76 std::unique_ptr<ResourceController> controller) { |
| 75 DCHECK_EQ(AuthorizationState::AUTHORIZED, authorization_state_); | 77 DCHECK_EQ(AuthorizationState::AUTHORIZED, authorization_state_); |
| 76 DCHECK(buf && buf_size); | 78 DCHECK(buf && buf_size); |
| 77 if (!read_buffer_.get()) { | 79 if (!read_buffer_.get()) { |
| 78 *buf_size = kReadBufSize; | 80 *buf_size = kReadBufSize; |
| 79 read_buffer_ = new net::IOBuffer(*buf_size); | 81 read_buffer_ = new net::IOBuffer(*buf_size); |
| 80 } | 82 } |
| 81 *buf = read_buffer_.get(); | 83 *buf = read_buffer_.get(); |
| 82 return true; | 84 controller->Resume(); |
| 83 } | 85 } |
| 84 | 86 |
| 85 void SaveFileResourceHandler::OnReadCompleted( | 87 void SaveFileResourceHandler::OnReadCompleted( |
| 86 int bytes_read, | 88 int bytes_read, |
| 87 std::unique_ptr<ResourceController> controller) { | 89 std::unique_ptr<ResourceController> controller) { |
| 88 DCHECK_EQ(AuthorizationState::AUTHORIZED, authorization_state_); | 90 DCHECK_EQ(AuthorizationState::AUTHORIZED, authorization_state_); |
| 89 DCHECK(read_buffer_.get()); | 91 DCHECK(read_buffer_.get()); |
| 90 // We are passing ownership of this buffer to the save file manager. | 92 // We are passing ownership of this buffer to the save file manager. |
| 91 scoped_refptr<net::IOBuffer> buffer; | 93 scoped_refptr<net::IOBuffer> buffer; |
| 92 read_buffer_.swap(buffer); | 94 read_buffer_.swap(buffer); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 115 void SaveFileResourceHandler::OnDataDownloaded(int bytes_downloaded) { | 117 void SaveFileResourceHandler::OnDataDownloaded(int bytes_downloaded) { |
| 116 NOTREACHED(); | 118 NOTREACHED(); |
| 117 } | 119 } |
| 118 | 120 |
| 119 void SaveFileResourceHandler::set_content_length( | 121 void SaveFileResourceHandler::set_content_length( |
| 120 const std::string& content_length) { | 122 const std::string& content_length) { |
| 121 base::StringToInt64(content_length, &content_length_); | 123 base::StringToInt64(content_length, &content_length_); |
| 122 } | 124 } |
| 123 | 125 |
| 124 } // namespace content | 126 } // namespace content |
| OLD | NEW |