| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/base/filename_util.h" | 5 #include "net/base/filename_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 bool ignore_extension, | 164 bool ignore_extension, |
| 165 base::FilePath* file_name) { | 165 base::FilePath* file_name) { |
| 166 // See if our file name already contains an extension. | 166 // See if our file name already contains an extension. |
| 167 base::FilePath::StringType extension = file_name->Extension(); | 167 base::FilePath::StringType extension = file_name->Extension(); |
| 168 if (!extension.empty()) | 168 if (!extension.empty()) |
| 169 extension.erase(extension.begin()); // Erase preceding '.'. | 169 extension.erase(extension.begin()); // Erase preceding '.'. |
| 170 | 170 |
| 171 if ((ignore_extension || extension.empty()) && !mime_type.empty()) { | 171 if ((ignore_extension || extension.empty()) && !mime_type.empty()) { |
| 172 base::FilePath::StringType preferred_mime_extension; | 172 base::FilePath::StringType preferred_mime_extension; |
| 173 std::vector<base::FilePath::StringType> all_mime_extensions; | 173 std::vector<base::FilePath::StringType> all_mime_extensions; |
| 174 // The GetPreferredExtensionForMimeType call will end up going to disk. Do | |
| 175 // this on another thread to avoid slowing the IO thread. | |
| 176 // http://crbug.com/61827 | |
| 177 // TODO(asanka): Remove this ScopedAllowIO once all callers have switched | |
| 178 // over to IO safe threads. | |
| 179 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 180 net::GetPreferredExtensionForMimeType(mime_type, &preferred_mime_extension); | 174 net::GetPreferredExtensionForMimeType(mime_type, &preferred_mime_extension); |
| 181 net::GetExtensionsForMimeType(mime_type, &all_mime_extensions); | 175 net::GetExtensionsForMimeType(mime_type, &all_mime_extensions); |
| 182 // If the existing extension is in the list of valid extensions for the | 176 // If the existing extension is in the list of valid extensions for the |
| 183 // given type, use it. This avoids doing things like pointlessly renaming | 177 // given type, use it. This avoids doing things like pointlessly renaming |
| 184 // "foo.jpg" to "foo.jpeg". | 178 // "foo.jpg" to "foo.jpeg". |
| 185 if (std::find(all_mime_extensions.begin(), | 179 if (std::find(all_mime_extensions.begin(), |
| 186 all_mime_extensions.end(), | 180 all_mime_extensions.end(), |
| 187 extension) != all_mime_extensions.end()) { | 181 extension) != all_mime_extensions.end()) { |
| 188 // leave |extension| alone | 182 // leave |extension| alone |
| 189 } else if (!preferred_mime_extension.empty()) { | 183 } else if (!preferred_mime_extension.empty()) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 base::FilePath generated_name( | 309 base::FilePath generated_name( |
| 316 base::SysWideToNativeMB(base::UTF16ToWide(file_name))); | 310 base::SysWideToNativeMB(base::UTF16ToWide(file_name))); |
| 317 #endif | 311 #endif |
| 318 | 312 |
| 319 DCHECK(!generated_name.empty()); | 313 DCHECK(!generated_name.empty()); |
| 320 | 314 |
| 321 return generated_name; | 315 return generated_name; |
| 322 } | 316 } |
| 323 | 317 |
| 324 } // namespace net | 318 } // namespace net |
| OLD | NEW |