OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/download/save_file_manager.h" | 7 #include "chrome/browser/download/save_file_manager.h" |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 URLRequestContextGetter* request_context_getter, | 124 URLRequestContextGetter* request_context_getter, |
125 SavePackage* save_package) { | 125 SavePackage* save_package) { |
126 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 126 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
127 | 127 |
128 // Register a saving job. | 128 // Register a saving job. |
129 RegisterStartingRequest(url, save_package); | 129 RegisterStartingRequest(url, save_package); |
130 if (save_source == SaveFileCreateInfo::SAVE_FILE_FROM_NET) { | 130 if (save_source == SaveFileCreateInfo::SAVE_FILE_FROM_NET) { |
131 DCHECK(url.is_valid()); | 131 DCHECK(url.is_valid()); |
132 | 132 |
133 ChromeThread::PostTask( | 133 ChromeThread::PostTask( |
134 ChromeThread::IO, | 134 ChromeThread::IO, FROM_HERE, |
135 FROM_HERE, | 135 NewRunnableMethod(this, |
136 NewRunnableMethod( | 136 &SaveFileManager::OnSaveURL, |
137 this, | 137 url, |
138 &SaveFileManager::OnSaveURL, | 138 referrer, |
139 url, | 139 render_process_host_id, |
140 referrer, | 140 render_view_id, |
141 render_process_host_id, | 141 request_context_getter)); |
142 render_view_id, | |
143 make_scoped_refptr(request_context_getter))); | |
144 } else { | 142 } else { |
145 // We manually start the save job. | 143 // We manually start the save job. |
146 SaveFileCreateInfo* info = new SaveFileCreateInfo(file_full_path, | 144 SaveFileCreateInfo* info = new SaveFileCreateInfo(file_full_path, |
147 url, | 145 url, |
148 save_source, | 146 save_source, |
149 -1); | 147 -1); |
150 info->render_process_id = render_process_host_id; | 148 info->render_process_id = render_process_host_id; |
151 info->render_view_id = render_view_id; | 149 info->render_view_id = render_view_id; |
152 | 150 |
153 // Since the data will come from render process, so we need to start | 151 // Since the data will come from render process, so we need to start |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 243 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
246 SaveFile* save_file = LookupSaveFile(save_id); | 244 SaveFile* save_file = LookupSaveFile(save_id); |
247 if (save_file) { | 245 if (save_file) { |
248 bool write_success = save_file->AppendDataToFile(data->data(), data_len); | 246 bool write_success = save_file->AppendDataToFile(data->data(), data_len); |
249 ChromeThread::PostTask( | 247 ChromeThread::PostTask( |
250 ChromeThread::UI, FROM_HERE, | 248 ChromeThread::UI, FROM_HERE, |
251 NewRunnableMethod( | 249 NewRunnableMethod( |
252 this, &SaveFileManager::OnUpdateSaveProgress, save_file->save_id(), | 250 this, &SaveFileManager::OnUpdateSaveProgress, save_file->save_id(), |
253 save_file->bytes_so_far(), write_success)); | 251 save_file->bytes_so_far(), write_success)); |
254 } | 252 } |
| 253 data->Release(); |
255 } | 254 } |
256 | 255 |
257 // The IO thread will call this when saving is completed or it got error when | 256 // The IO thread will call this when saving is completed or it got error when |
258 // fetching data. In the former case, we forward the message to OnSaveFinished | 257 // fetching data. In the former case, we forward the message to OnSaveFinished |
259 // in UI thread. In the latter case, the save ID will be -1, which means the | 258 // in UI thread. In the latter case, the save ID will be -1, which means the |
260 // saving action did not even start, so we need to call OnErrorFinished in UI | 259 // saving action did not even start, so we need to call OnErrorFinished in UI |
261 // thread, which will use the save URL to find corresponding request record and | 260 // thread, which will use the save URL to find corresponding request record and |
262 // delete it. | 261 // delete it. |
263 void SaveFileManager::SaveFinished(int save_id, | 262 void SaveFileManager::SaveFinished(int save_id, |
264 GURL save_url, | 263 GURL save_url, |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 SaveFileMap::iterator it = save_file_map_.find(*i); | 524 SaveFileMap::iterator it = save_file_map_.find(*i); |
526 if (it != save_file_map_.end()) { | 525 if (it != save_file_map_.end()) { |
527 SaveFile* save_file = it->second; | 526 SaveFile* save_file = it->second; |
528 DCHECK(!save_file->in_progress()); | 527 DCHECK(!save_file->in_progress()); |
529 file_util::Delete(save_file->full_path(), false); | 528 file_util::Delete(save_file->full_path(), false); |
530 delete save_file; | 529 delete save_file; |
531 save_file_map_.erase(it); | 530 save_file_map_.erase(it); |
532 } | 531 } |
533 } | 532 } |
534 } | 533 } |
OLD | NEW |