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" |
| 11 #include "content/browser/download/download_task_runner.h" |
11 #include "content/browser/download/save_file_manager.h" | 12 #include "content/browser/download/save_file_manager.h" |
12 #include "content/browser/loader/resource_controller.h" | 13 #include "content/browser/loader/resource_controller.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
15 #include "net/url_request/redirect_info.h" | 16 #include "net/url_request/redirect_info.h" |
16 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 SaveFileResourceHandler::SaveFileResourceHandler( | 21 SaveFileResourceHandler::SaveFileResourceHandler( |
(...skipping 26 matching lines...) Expand all Loading... |
47 } | 48 } |
48 | 49 |
49 void SaveFileResourceHandler::OnResponseStarted( | 50 void SaveFileResourceHandler::OnResponseStarted( |
50 ResourceResponse* response, | 51 ResourceResponse* response, |
51 std::unique_ptr<ResourceController> controller) { | 52 std::unique_ptr<ResourceController> controller) { |
52 // |save_manager_| consumes (deletes): | 53 // |save_manager_| consumes (deletes): |
53 SaveFileCreateInfo* info = new SaveFileCreateInfo( | 54 SaveFileCreateInfo* info = new SaveFileCreateInfo( |
54 url_, final_url_, save_item_id_, save_package_id_, render_process_id_, | 55 url_, final_url_, save_item_id_, save_package_id_, render_process_id_, |
55 render_frame_routing_id_, GetRequestID(), content_disposition_, | 56 render_frame_routing_id_, GetRequestID(), content_disposition_, |
56 content_length_); | 57 content_length_); |
57 BrowserThread::PostTask( | 58 GetDownloadTaskRunner()->PostTask( |
58 BrowserThread::FILE, FROM_HERE, | 59 FROM_HERE, base::Bind(&SaveFileManager::StartSave, save_manager_, info)); |
59 base::Bind(&SaveFileManager::StartSave, save_manager_, info)); | |
60 controller->Resume(); | 60 controller->Resume(); |
61 } | 61 } |
62 | 62 |
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(); |
(...skipping 15 matching lines...) Expand all Loading... |
85 } | 85 } |
86 | 86 |
87 void SaveFileResourceHandler::OnReadCompleted( | 87 void SaveFileResourceHandler::OnReadCompleted( |
88 int bytes_read, | 88 int bytes_read, |
89 std::unique_ptr<ResourceController> controller) { | 89 std::unique_ptr<ResourceController> controller) { |
90 DCHECK_EQ(AuthorizationState::AUTHORIZED, authorization_state_); | 90 DCHECK_EQ(AuthorizationState::AUTHORIZED, authorization_state_); |
91 DCHECK(read_buffer_.get()); | 91 DCHECK(read_buffer_.get()); |
92 // 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. |
93 scoped_refptr<net::IOBuffer> buffer; | 93 scoped_refptr<net::IOBuffer> buffer; |
94 read_buffer_.swap(buffer); | 94 read_buffer_.swap(buffer); |
95 BrowserThread::PostTask( | 95 GetDownloadTaskRunner()->PostTask( |
96 BrowserThread::FILE, FROM_HERE, | 96 FROM_HERE, |
97 base::Bind(&SaveFileManager::UpdateSaveProgress, save_manager_, | 97 base::Bind(&SaveFileManager::UpdateSaveProgress, save_manager_, |
98 save_item_id_, base::RetainedRef(buffer), bytes_read)); | 98 save_item_id_, base::RetainedRef(buffer), bytes_read)); |
99 controller->Resume(); | 99 controller->Resume(); |
100 } | 100 } |
101 | 101 |
102 void SaveFileResourceHandler::OnResponseCompleted( | 102 void SaveFileResourceHandler::OnResponseCompleted( |
103 const net::URLRequestStatus& status, | 103 const net::URLRequestStatus& status, |
104 std::unique_ptr<ResourceController> controller) { | 104 std::unique_ptr<ResourceController> controller) { |
105 if (authorization_state_ != AuthorizationState::AUTHORIZED) | 105 if (authorization_state_ != AuthorizationState::AUTHORIZED) |
106 DCHECK(!status.is_success()); | 106 DCHECK(!status.is_success()); |
107 | 107 |
108 BrowserThread::PostTask( | 108 GetDownloadTaskRunner()->PostTask( |
109 BrowserThread::FILE, FROM_HERE, | 109 FROM_HERE, base::Bind(&SaveFileManager::SaveFinished, save_manager_, |
110 base::Bind(&SaveFileManager::SaveFinished, save_manager_, save_item_id_, | 110 save_item_id_, save_package_id_, |
111 save_package_id_, | 111 status.is_success() && !status.is_io_pending())); |
112 status.is_success() && !status.is_io_pending())); | |
113 read_buffer_ = nullptr; | 112 read_buffer_ = nullptr; |
114 controller->Resume(); | 113 controller->Resume(); |
115 } | 114 } |
116 | 115 |
117 void SaveFileResourceHandler::OnDataDownloaded(int bytes_downloaded) { | 116 void SaveFileResourceHandler::OnDataDownloaded(int bytes_downloaded) { |
118 NOTREACHED(); | 117 NOTREACHED(); |
119 } | 118 } |
120 | 119 |
121 void SaveFileResourceHandler::set_content_length( | 120 void SaveFileResourceHandler::set_content_length( |
122 const std::string& content_length) { | 121 const std::string& content_length) { |
123 base::StringToInt64(content_length, &content_length_); | 122 base::StringToInt64(content_length, &content_length_); |
124 } | 123 } |
125 | 124 |
126 } // namespace content | 125 } // namespace content |
OLD | NEW |