OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Download utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
11 #endif | 11 #endif |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "app/l10n_util.h" | 14 #include "app/l10n_util.h" |
15 #include "app/resource_bundle.h" | 15 #include "app/resource_bundle.h" |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/i18n/rtl.h" | 17 #include "base/i18n/rtl.h" |
18 #include "base/i18n/time_formatting.h" | 18 #include "base/i18n/time_formatting.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/singleton.h" | 20 #include "base/singleton.h" |
21 #include "base/string16.h" | 21 #include "base/string16.h" |
22 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
23 #include "base/sys_string_conversions.h" | 23 #include "base/sys_string_conversions.h" |
| 24 #include "base/thread_restrictions.h" |
24 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
25 #include "base/values.h" | 26 #include "base/values.h" |
26 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
27 #include "chrome/browser/browser.h" | 28 #include "chrome/browser/browser.h" |
28 #include "chrome/browser/browser_list.h" | 29 #include "chrome/browser/browser_list.h" |
29 #include "chrome/browser/browser_process.h" | 30 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/browser_thread.h" | 31 #include "chrome/browser/browser_thread.h" |
31 #include "chrome/browser/download/download_item.h" | 32 #include "chrome/browser/download/download_item.h" |
32 #include "chrome/browser/download/download_item_model.h" | 33 #include "chrome/browser/download/download_item_model.h" |
33 #include "chrome/browser/download/download_manager.h" | 34 #include "chrome/browser/download/download_manager.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 144 |
144 #if defined(OS_WIN) | 145 #if defined(OS_WIN) |
145 static const FilePath::CharType default_extension[] = | 146 static const FilePath::CharType default_extension[] = |
146 FILE_PATH_LITERAL("download"); | 147 FILE_PATH_LITERAL("download"); |
147 | 148 |
148 // Rename shell-integrated extensions. | 149 // Rename shell-integrated extensions. |
149 if (win_util::IsShellIntegratedExtension(extension)) | 150 if (win_util::IsShellIntegratedExtension(extension)) |
150 extension.assign(default_extension); | 151 extension.assign(default_extension); |
151 #endif | 152 #endif |
152 | 153 |
153 if (extension.empty()) | 154 if (extension.empty()) { |
| 155 // The GetPreferredExtensionForMimeType call will end up going to disk. Do |
| 156 // this on another thread to avoid slowing the IO thread. |
| 157 // http://crbug.com/61827 |
| 158 base::ThreadRestrictions::ScopedAllowIO allow_io; |
154 net::GetPreferredExtensionForMimeType(mime_type, &extension); | 159 net::GetPreferredExtensionForMimeType(mime_type, &extension); |
| 160 } |
155 | 161 |
156 generated_extension->swap(extension); | 162 generated_extension->swap(extension); |
157 } | 163 } |
158 | 164 |
159 void GenerateFileNameFromInfo(DownloadCreateInfo* info, | 165 void GenerateFileNameFromInfo(DownloadCreateInfo* info, |
160 FilePath* generated_name) { | 166 FilePath* generated_name) { |
161 GenerateFileName(GURL(info->url), | 167 GenerateFileName(GURL(info->url), |
162 info->content_disposition, | 168 info->content_disposition, |
163 info->referrer_charset, | 169 info->referrer_charset, |
164 info->mime_type, | 170 info->mime_type, |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 ExtensionsService* service = profile->GetExtensionsService(); | 731 ExtensionsService* service = profile->GetExtensionsService(); |
726 if (!service || | 732 if (!service || |
727 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { | 733 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { |
728 return true; | 734 return true; |
729 } | 735 } |
730 } | 736 } |
731 return false; | 737 return false; |
732 } | 738 } |
733 | 739 |
734 } // namespace download_util | 740 } // namespace download_util |
OLD | NEW |