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

Side by Side Diff: content/browser/download/save_file_resource_handler.cc

Issue 2668603003: Make ResourceHandler::OnWillRead able to complete asynchronously. (Closed)
Patch Set: Response to comments Created 3 years, 9 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
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « content/browser/download/save_file_resource_handler.h ('k') | content/browser/loader/async_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698