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

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

Issue 2890853002: Downloads: replace BrowserThread::FILE with task scheduler. (Closed)
Patch Set: Revert ScopedCOMInitializer invocations. Created 3 years, 5 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"
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 "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
15 #include "net/url_request/redirect_info.h" 15 #include "net/url_request/redirect_info.h"
16 #include "net/url_request/url_request_status.h" 16 #include "net/url_request/url_request_status.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 SaveFileResourceHandler::SaveFileResourceHandler( 20 SaveFileResourceHandler::SaveFileResourceHandler(
21 net::URLRequest* request, 21 net::URLRequest* request,
22 SaveItemId save_item_id, 22 SaveItemId save_item_id,
23 SavePackageId save_package_id, 23 SavePackageId save_package_id,
(...skipping 23 matching lines...) Expand all
47 } 47 }
48 48
49 void SaveFileResourceHandler::OnResponseStarted( 49 void SaveFileResourceHandler::OnResponseStarted(
50 ResourceResponse* response, 50 ResourceResponse* response,
51 std::unique_ptr<ResourceController> controller) { 51 std::unique_ptr<ResourceController> controller) {
52 // |save_manager_| consumes (deletes): 52 // |save_manager_| consumes (deletes):
53 SaveFileCreateInfo* info = new SaveFileCreateInfo( 53 SaveFileCreateInfo* info = new SaveFileCreateInfo(
54 url_, final_url_, save_item_id_, save_package_id_, render_process_id_, 54 url_, final_url_, save_item_id_, save_package_id_, render_process_id_,
55 render_frame_routing_id_, GetRequestID(), content_disposition_, 55 render_frame_routing_id_, GetRequestID(), content_disposition_,
56 content_length_); 56 content_length_);
57 BrowserThread::PostTask( 57 GetDownloadTaskRunner()->PostTask(
58 BrowserThread::FILE, FROM_HERE, 58 FROM_HERE, base::Bind(&SaveFileManager::StartSave, save_manager_, info));
59 base::Bind(&SaveFileManager::StartSave, save_manager_, info));
60 controller->Resume(); 59 controller->Resume();
61 } 60 }
62 61
63 void SaveFileResourceHandler::OnWillStart( 62 void SaveFileResourceHandler::OnWillStart(
64 const GURL& url, 63 const GURL& url,
65 std::unique_ptr<ResourceController> controller) { 64 std::unique_ptr<ResourceController> controller) {
66 if (authorization_state_ == AuthorizationState::AUTHORIZED) { 65 if (authorization_state_ == AuthorizationState::AUTHORIZED) {
67 controller->Resume(); 66 controller->Resume();
68 } else { 67 } else {
69 controller->Cancel(); 68 controller->Cancel();
(...skipping 15 matching lines...) Expand all
85 } 84 }
86 85
87 void SaveFileResourceHandler::OnReadCompleted( 86 void SaveFileResourceHandler::OnReadCompleted(
88 int bytes_read, 87 int bytes_read,
89 std::unique_ptr<ResourceController> controller) { 88 std::unique_ptr<ResourceController> controller) {
90 DCHECK_EQ(AuthorizationState::AUTHORIZED, authorization_state_); 89 DCHECK_EQ(AuthorizationState::AUTHORIZED, authorization_state_);
91 DCHECK(read_buffer_.get()); 90 DCHECK(read_buffer_.get());
92 // We are passing ownership of this buffer to the save file manager. 91 // We are passing ownership of this buffer to the save file manager.
93 scoped_refptr<net::IOBuffer> buffer; 92 scoped_refptr<net::IOBuffer> buffer;
94 read_buffer_.swap(buffer); 93 read_buffer_.swap(buffer);
95 BrowserThread::PostTask( 94 GetDownloadTaskRunner()->PostTask(
96 BrowserThread::FILE, FROM_HERE, 95 FROM_HERE,
97 base::Bind(&SaveFileManager::UpdateSaveProgress, save_manager_, 96 base::Bind(&SaveFileManager::UpdateSaveProgress, save_manager_,
98 save_item_id_, base::RetainedRef(buffer), bytes_read)); 97 save_item_id_, base::RetainedRef(buffer), bytes_read));
99 controller->Resume(); 98 controller->Resume();
100 } 99 }
101 100
102 void SaveFileResourceHandler::OnResponseCompleted( 101 void SaveFileResourceHandler::OnResponseCompleted(
103 const net::URLRequestStatus& status, 102 const net::URLRequestStatus& status,
104 std::unique_ptr<ResourceController> controller) { 103 std::unique_ptr<ResourceController> controller) {
105 if (authorization_state_ != AuthorizationState::AUTHORIZED) 104 if (authorization_state_ != AuthorizationState::AUTHORIZED)
106 DCHECK(!status.is_success()); 105 DCHECK(!status.is_success());
107 106
108 BrowserThread::PostTask( 107 GetDownloadTaskRunner()->PostTask(
109 BrowserThread::FILE, FROM_HERE, 108 FROM_HERE, base::Bind(&SaveFileManager::SaveFinished, save_manager_,
110 base::Bind(&SaveFileManager::SaveFinished, save_manager_, save_item_id_, 109 save_item_id_, save_package_id_,
111 save_package_id_, 110 status.is_success() && !status.is_io_pending()));
112 status.is_success() && !status.is_io_pending()));
113 read_buffer_ = nullptr; 111 read_buffer_ = nullptr;
114 controller->Resume(); 112 controller->Resume();
115 } 113 }
116 114
117 void SaveFileResourceHandler::OnDataDownloaded(int bytes_downloaded) { 115 void SaveFileResourceHandler::OnDataDownloaded(int bytes_downloaded) {
118 NOTREACHED(); 116 NOTREACHED();
119 } 117 }
120 118
121 void SaveFileResourceHandler::set_content_length( 119 void SaveFileResourceHandler::set_content_length(
122 const std::string& content_length) { 120 const std::string& content_length) {
123 base::StringToInt64(content_length, &content_length_); 121 base::StringToInt64(content_length, &content_length_);
124 } 122 }
125 123
126 } // namespace content 124 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698