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

Side by Side Diff: chrome/browser/download/chrome_download_manager_delegate.cc

Issue 324883006: Cleanup: Use PostTaskAndReplyWithResults instead of passing callbacks around in downloads code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/download/download_path_reservation_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/download/chrome_download_manager_delegate.h" 5 #include "chrome/browser/download/chrome_download_manager_delegate.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/prefs/pref_member.h" 14 #include "base/prefs/pref_member.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/task_runner.h" 19 #include "base/task_runner.h"
20 #include "base/task_runner_util.h"
20 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
21 #include "base/time/time.h" 22 #include "base/time/time.h"
22 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_notification_types.h" 24 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/download/download_completion_blocker.h" 25 #include "chrome/browser/download/download_completion_blocker.h"
25 #include "chrome/browser/download/download_crx_util.h" 26 #include "chrome/browser/download/download_crx_util.h"
26 #include "chrome/browser/download/download_file_picker.h" 27 #include "chrome/browser/download/download_file_picker.h"
27 #include "chrome/browser/download/download_history.h" 28 #include "chrome/browser/download/download_history.h"
28 #include "chrome/browser/download/download_item_model.h" 29 #include "chrome/browser/download/download_item_model.h"
29 #include "chrome/browser/download/download_path_reservation_tracker.h" 30 #include "chrome/browser/download/download_path_reservation_tracker.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // If the URL is malicious, we'll use that as the danger type. The results 171 // If the URL is malicious, we'll use that as the danger type. The results
171 // of the content check, if one is performed, will be ignored. 172 // of the content check, if one is performed, will be ignored.
172 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; 173 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL;
173 } 174 }
174 callback.Run(danger_type); 175 callback.Run(danger_type);
175 } 176 }
176 177
177 #endif // FULL_SAFE_BROWSING 178 #endif // FULL_SAFE_BROWSING
178 179
179 // Called on the blocking pool to determine the MIME type for |path|. 180 // Called on the blocking pool to determine the MIME type for |path|.
180 void GetMimeTypeAndReplyOnUIThread( 181 std::string GetMimeType(const base::FilePath& path) {
181 const base::FilePath& path,
182 const base::Callback<void(const std::string&)>& callback) {
183 std::string mime_type; 182 std::string mime_type;
184 net::GetMimeTypeFromFile(path, &mime_type); 183 net::GetMimeTypeFromFile(path, &mime_type);
185 BrowserThread::PostTask( 184 return mime_type;
186 BrowserThread::UI, FROM_HERE, base::Bind(callback, mime_type));
187 } 185 }
188 186
189 bool IsOpenInBrowserPreferreredForFile(const base::FilePath& path) { 187 bool IsOpenInBrowserPreferreredForFile(const base::FilePath& path) {
190 // On Android, always prefer opening with an external app. On ChromeOS, there 188 // On Android, always prefer opening with an external app. On ChromeOS, there
191 // are no external apps so just allow all opens to be handled by the "System." 189 // are no external apps so just allow all opens to be handled by the "System."
192 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && defined(ENABLE_PLUGINS) 190 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && defined(ENABLE_PLUGINS)
193 // TODO(asanka): Consider other file types and MIME types. 191 // TODO(asanka): Consider other file types and MIME types.
194 // http://crbug.com/323561 192 // http://crbug.com/323561
195 if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf")) || 193 if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf")) ||
196 path.MatchesExtension(FILE_PATH_LITERAL(".htm")) || 194 path.MatchesExtension(FILE_PATH_LITERAL(".htm")) ||
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 is_content_check_supported)); 627 is_content_check_supported));
630 return; 628 return;
631 } 629 }
632 #endif 630 #endif
633 callback.Run(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 631 callback.Run(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
634 } 632 }
635 633
636 void ChromeDownloadManagerDelegate::GetFileMimeType( 634 void ChromeDownloadManagerDelegate::GetFileMimeType(
637 const base::FilePath& path, 635 const base::FilePath& path,
638 const GetFileMimeTypeCallback& callback) { 636 const GetFileMimeTypeCallback& callback) {
639 BrowserThread::PostBlockingPoolTask( 637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
640 FROM_HERE, 638 base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(),
641 base::Bind(&GetMimeTypeAndReplyOnUIThread, path, callback)); 639 FROM_HERE,
640 base::Bind(&GetMimeType, path),
641 callback);
642 } 642 }
643 643
644 #if defined(FULL_SAFE_BROWSING) 644 #if defined(FULL_SAFE_BROWSING)
645 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( 645 void ChromeDownloadManagerDelegate::CheckClientDownloadDone(
646 uint32 download_id, 646 uint32 download_id,
647 DownloadProtectionService::DownloadCheckResult result) { 647 DownloadProtectionService::DownloadCheckResult result) {
648 DownloadItem* item = download_manager_->GetDownload(download_id); 648 DownloadItem* item = download_manager_->GetDownload(download_id);
649 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) 649 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS))
650 return; 650 return;
651 651
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 DownloadItem* item = download_manager_->GetDownload(download_id); 715 DownloadItem* item = download_manager_->GetDownload(download_id);
716 if (!target_info->target_path.empty() && item && 716 if (!target_info->target_path.empty() && item &&
717 IsOpenInBrowserPreferreredForFile(target_info->target_path) && 717 IsOpenInBrowserPreferreredForFile(target_info->target_path) &&
718 target_info->is_filetype_handled_safely) 718 target_info->is_filetype_handled_safely)
719 DownloadItemModel(item).SetShouldPreferOpeningInBrowser(true); 719 DownloadItemModel(item).SetShouldPreferOpeningInBrowser(true);
720 callback.Run(target_info->target_path, 720 callback.Run(target_info->target_path,
721 target_info->target_disposition, 721 target_info->target_disposition,
722 target_info->danger_type, 722 target_info->danger_type,
723 target_info->intermediate_path); 723 target_info->intermediate_path);
724 } 724 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_path_reservation_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698