| 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" |
| 11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/task.h" | 13 #include "base/task.h" |
| 14 #include "base/thread.h" | 14 #include "base/thread.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/download/save_file.h" | 16 #include "chrome/browser/download/save_file.h" |
| 17 #include "chrome/browser/download/save_package.h" | 17 #include "chrome/browser/download/save_package.h" |
| 18 #include "chrome/browser/net/url_request_context_getter.h" |
| 18 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 19 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 19 #include "chrome/browser/tab_contents/tab_contents.h" | 20 #include "chrome/browser/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
| 21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/platform_util.h" | 23 #include "chrome/common/platform_util.h" |
| 23 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 24 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 25 #include "net/base/io_buffer.h" | 26 #include "net/base/io_buffer.h" |
| 26 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
| 27 | 28 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 return NULL; | 147 return NULL; |
| 147 } | 148 } |
| 148 | 149 |
| 149 // Call from SavePackage for starting a saving job | 150 // Call from SavePackage for starting a saving job |
| 150 void SaveFileManager::SaveURL(const GURL& url, | 151 void SaveFileManager::SaveURL(const GURL& url, |
| 151 const GURL& referrer, | 152 const GURL& referrer, |
| 152 int render_process_host_id, | 153 int render_process_host_id, |
| 153 int render_view_id, | 154 int render_view_id, |
| 154 SaveFileCreateInfo::SaveFileSource save_source, | 155 SaveFileCreateInfo::SaveFileSource save_source, |
| 155 const FilePath& file_full_path, | 156 const FilePath& file_full_path, |
| 156 URLRequestContext* request_context, | 157 URLRequestContextGetter* request_context_getter, |
| 157 SavePackage* save_package) { | 158 SavePackage* save_package) { |
| 158 DCHECK_EQ(MessageLoop::current(), ui_loop_); | 159 DCHECK_EQ(MessageLoop::current(), ui_loop_); |
| 159 if (!io_loop_) { | 160 if (!io_loop_) { |
| 160 NOTREACHED(); // Net IO thread must exist. | 161 NOTREACHED(); // Net IO thread must exist. |
| 161 return; | 162 return; |
| 162 } | 163 } |
| 163 | 164 |
| 164 // Register a saving job. | 165 // Register a saving job. |
| 165 RegisterStartingRequest(url, save_package); | 166 RegisterStartingRequest(url, save_package); |
| 166 if (save_source == SaveFileCreateInfo::SAVE_FILE_FROM_NET) { | 167 if (save_source == SaveFileCreateInfo::SAVE_FILE_FROM_NET) { |
| 167 DCHECK(url.is_valid()); | 168 DCHECK(url.is_valid()); |
| 168 | 169 |
| 169 io_loop_->PostTask(FROM_HERE, | 170 io_loop_->PostTask(FROM_HERE, |
| 170 NewRunnableMethod(this, | 171 NewRunnableMethod(this, |
| 171 &SaveFileManager::OnSaveURL, | 172 &SaveFileManager::OnSaveURL, |
| 172 url, | 173 url, |
| 173 referrer, | 174 referrer, |
| 174 render_process_host_id, | 175 render_process_host_id, |
| 175 render_view_id, | 176 render_view_id, |
| 176 request_context)); | 177 request_context_getter)); |
| 177 } else { | 178 } else { |
| 178 // We manually start the save job. | 179 // We manually start the save job. |
| 179 SaveFileCreateInfo* info = new SaveFileCreateInfo(file_full_path, | 180 SaveFileCreateInfo* info = new SaveFileCreateInfo(file_full_path, |
| 180 url, | 181 url, |
| 181 save_source, | 182 save_source, |
| 182 -1); | 183 -1); |
| 183 info->render_process_id = render_process_host_id; | 184 info->render_process_id = render_process_host_id; |
| 184 info->render_view_id = render_view_id; | 185 info->render_view_id = render_view_id; |
| 185 RequireSaveJobFromOtherSource(info); | 186 RequireSaveJobFromOtherSource(info); |
| 186 } | 187 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 DCHECK(io_loop_); | 387 DCHECK(io_loop_); |
| 387 io_loop_->PostTask(FROM_HERE, | 388 io_loop_->PostTask(FROM_HERE, |
| 388 NewRunnableMethod(this, | 389 NewRunnableMethod(this, |
| 389 &SaveFileManager::ExecuteCancelSaveRequest, | 390 &SaveFileManager::ExecuteCancelSaveRequest, |
| 390 render_process_id, | 391 render_process_id, |
| 391 request_id)); | 392 request_id)); |
| 392 } | 393 } |
| 393 | 394 |
| 394 // Notifications sent from the UI thread and run on the IO thread. | 395 // Notifications sent from the UI thread and run on the IO thread. |
| 395 | 396 |
| 396 void SaveFileManager::OnSaveURL(const GURL& url, | 397 void SaveFileManager::OnSaveURL( |
| 397 const GURL& referrer, | 398 const GURL& url, |
| 398 int render_process_host_id, | 399 const GURL& referrer, |
| 399 int render_view_id, | 400 int render_process_host_id, |
| 400 URLRequestContext* request_context) { | 401 int render_view_id, |
| 402 URLRequestContextGetter* request_context_getter) { |
| 401 DCHECK_EQ(MessageLoop::current(), io_loop_); | 403 DCHECK_EQ(MessageLoop::current(), io_loop_); |
| 404 URLRequestContext* context = request_context_getter->GetURLRequestContext(); |
| 402 resource_dispatcher_host_->BeginSaveFile(url, | 405 resource_dispatcher_host_->BeginSaveFile(url, |
| 403 referrer, | 406 referrer, |
| 404 render_process_host_id, | 407 render_process_host_id, |
| 405 render_view_id, | 408 render_view_id, |
| 406 request_context); | 409 context); |
| 407 } | 410 } |
| 408 | 411 |
| 409 void SaveFileManager::OnRequireSaveJobFromOtherSource( | 412 void SaveFileManager::OnRequireSaveJobFromOtherSource( |
| 410 SaveFileCreateInfo* info) { | 413 SaveFileCreateInfo* info) { |
| 411 DCHECK_EQ(MessageLoop::current(), io_loop_); | 414 DCHECK_EQ(MessageLoop::current(), io_loop_); |
| 412 DCHECK_EQ(info->save_id, -1); | 415 DCHECK_EQ(info->save_id, -1); |
| 413 // Generate a unique save id. | 416 // Generate a unique save id. |
| 414 info->save_id = GetNextId(); | 417 info->save_id = GetNextId(); |
| 415 // Start real saving action. | 418 // Start real saving action. |
| 416 MessageLoop* loop = file_loop(); | 419 MessageLoop* loop = file_loop(); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 SaveFileMap::iterator it = save_file_map_.find(*i); | 573 SaveFileMap::iterator it = save_file_map_.find(*i); |
| 571 if (it != save_file_map_.end()) { | 574 if (it != save_file_map_.end()) { |
| 572 SaveFile* save_file = it->second; | 575 SaveFile* save_file = it->second; |
| 573 DCHECK(!save_file->in_progress()); | 576 DCHECK(!save_file->in_progress()); |
| 574 file_util::Delete(save_file->full_path(), false); | 577 file_util::Delete(save_file->full_path(), false); |
| 575 delete save_file; | 578 delete save_file; |
| 576 save_file_map_.erase(it); | 579 save_file_map_.erase(it); |
| 577 } | 580 } |
| 578 } | 581 } |
| 579 } | 582 } |
| OLD | NEW |