| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/download/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 bool ChromeDownloadManagerDelegate::IsExtensionDownload( | 51 bool ChromeDownloadManagerDelegate::IsExtensionDownload( |
| 52 const DownloadItem* item) { | 52 const DownloadItem* item) { |
| 53 if (item->prompt_user_for_save_location()) | 53 if (item->prompt_user_for_save_location()) |
| 54 return false; | 54 return false; |
| 55 | 55 |
| 56 return (item->mime_type() == Extension::kMimeType) || | 56 return (item->mime_type() == Extension::kMimeType) || |
| 57 UserScript::IsURLUserScript(item->GetURL(), item->mime_type()); | 57 UserScript::IsURLUserScript(item->GetURL(), item->mime_type()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { | 60 void ChromeDownloadManagerDelegate::SetDownloadManager( |
| 61 DownloadManagerInterface* dm) { |
| 61 download_manager_ = dm; | 62 download_manager_ = dm; |
| 62 download_history_.reset(new DownloadHistory(profile_)); | 63 download_history_.reset(new DownloadHistory(profile_)); |
| 63 download_history_->Load( | 64 download_history_->Load( |
| 64 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, | 65 base::Bind(&DownloadManagerInterface::OnPersistentStoreQueryComplete, |
| 65 base::Unretained(dm))); | 66 base::Unretained(dm))); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void ChromeDownloadManagerDelegate::Shutdown() { | 69 void ChromeDownloadManagerDelegate::Shutdown() { |
| 69 download_history_.reset(); | 70 download_history_.reset(); |
| 70 download_prefs_.reset(); | 71 download_prefs_.reset(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 bool ChromeDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { | 74 bool ChromeDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { |
| 74 // We create a download item and store it in our download map, and inform the | 75 // We create a download item and store it in our download map, and inform the |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 state.prompt_user_for_save_location = true; | 382 state.prompt_user_for_save_location = true; |
| 382 } | 383 } |
| 383 if (download_prefs_->IsDownloadPathManaged()) { | 384 if (download_prefs_->IsDownloadPathManaged()) { |
| 384 state.prompt_user_for_save_location = false; | 385 state.prompt_user_for_save_location = false; |
| 385 } | 386 } |
| 386 | 387 |
| 387 // Determine the proper path for a download, by either one of the following: | 388 // Determine the proper path for a download, by either one of the following: |
| 388 // 1) using the default download directory. | 389 // 1) using the default download directory. |
| 389 // 2) prompting the user. | 390 // 2) prompting the user. |
| 390 if (state.prompt_user_for_save_location && | 391 if (state.prompt_user_for_save_location && |
| 391 !download_manager_->last_download_path().empty()) { | 392 !download_manager_->LastDownloadPath().empty()) { |
| 392 state.suggested_path = download_manager_->last_download_path(); | 393 state.suggested_path = download_manager_->LastDownloadPath(); |
| 393 } else { | 394 } else { |
| 394 state.suggested_path = download_prefs_->download_path(); | 395 state.suggested_path = download_prefs_->download_path(); |
| 395 } | 396 } |
| 396 state.suggested_path = state.suggested_path.Append(generated_name); | 397 state.suggested_path = state.suggested_path.Append(generated_name); |
| 397 } else { | 398 } else { |
| 398 state.suggested_path = state.force_file_name; | 399 state.suggested_path = state.force_file_name; |
| 399 } | 400 } |
| 400 | 401 |
| 401 if (!state.prompt_user_for_save_location && state.force_file_name.empty()) { | 402 if (!state.prompt_user_for_save_location && state.force_file_name.empty()) { |
| 402 state.is_dangerous_file = | 403 state.is_dangerous_file = |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 // TODO(noelutz): This function currently works as a callback place holder. | 563 // TODO(noelutz): This function currently works as a callback place holder. |
| 563 // Once we decide the hash check is reliable, we could move the | 564 // Once we decide the hash check is reliable, we could move the |
| 564 // MaybeCompleteDownload in OnAllDataSaved to this function. | 565 // MaybeCompleteDownload in OnAllDataSaved to this function. |
| 565 void ChromeDownloadManagerDelegate::CheckDownloadHashDone( | 566 void ChromeDownloadManagerDelegate::CheckDownloadHashDone( |
| 566 int32 download_id, | 567 int32 download_id, |
| 567 bool is_dangerous_hash) { | 568 bool is_dangerous_hash) { |
| 568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 569 DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id | 570 DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id |
| 570 << " is dangerous_hash: " << is_dangerous_hash; | 571 << " is dangerous_hash: " << is_dangerous_hash; |
| 571 } | 572 } |
| OLD | NEW |