| 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/lazy_instance.h" |
| 19 #include "base/path_service.h" | 20 #include "base/path_service.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/stringprintf.h" | 23 #include "base/stringprintf.h" |
| 24 #include "base/sys_string_conversions.h" | 24 #include "base/sys_string_conversions.h" |
| 25 #include "base/thread_restrictions.h" | 25 #include "base/thread_restrictions.h" |
| 26 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
| 27 #include "base/values.h" | 27 #include "base/values.h" |
| 28 #include "base/win/windows_version.h" | 28 #include "base/win/windows_version.h" |
| 29 #include "chrome/browser/browser_thread.h" | 29 #include "chrome/browser/browser_thread.h" |
| 30 #include "chrome/browser/download/download_extensions.h" | 30 #include "chrome/browser/download/download_extensions.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 DefaultDownloadDirectory() { | 101 DefaultDownloadDirectory() { |
| 102 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) { | 102 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) { |
| 103 NOTREACHED(); | 103 NOTREACHED(); |
| 104 } | 104 } |
| 105 if (DownloadPathIsDangerous(path_)) { | 105 if (DownloadPathIsDangerous(path_)) { |
| 106 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &path_)) { | 106 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &path_)) { |
| 107 NOTREACHED(); | 107 NOTREACHED(); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 friend struct DefaultSingletonTraits<DefaultDownloadDirectory>; | 111 friend struct base::DefaultLazyInstanceTraits<DefaultDownloadDirectory>; |
| 112 FilePath path_; | 112 FilePath path_; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 static base::LazyInstance<DefaultDownloadDirectory> |
| 116 g_default_download_directory(base::LINKER_INITIALIZED); |
| 117 |
| 115 const FilePath& GetDefaultDownloadDirectory() { | 118 const FilePath& GetDefaultDownloadDirectory() { |
| 116 return Singleton<DefaultDownloadDirectory>::get()->path(); | 119 return g_default_download_directory.Get().path(); |
| 117 } | 120 } |
| 118 | 121 |
| 119 bool CreateTemporaryFileForDownload(FilePath* temp_file) { | 122 bool CreateTemporaryFileForDownload(FilePath* temp_file) { |
| 120 if (file_util::CreateTemporaryFileInDir(GetDefaultDownloadDirectory(), | 123 if (file_util::CreateTemporaryFileInDir(GetDefaultDownloadDirectory(), |
| 121 temp_file)) | 124 temp_file)) |
| 122 return true; | 125 return true; |
| 123 return file_util::CreateTemporaryFile(temp_file); | 126 return file_util::CreateTemporaryFile(temp_file); |
| 124 } | 127 } |
| 125 | 128 |
| 126 bool DownloadPathIsDangerous(const FilePath& download_path) { | 129 bool DownloadPathIsDangerous(const FilePath& download_path) { |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { | 736 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { |
| 734 // Extensions that are not from the gallery are considered dangerous. | 737 // Extensions that are not from the gallery are considered dangerous. |
| 735 return true; | 738 return true; |
| 736 } | 739 } |
| 737 } | 740 } |
| 738 | 741 |
| 739 return false; | 742 return false; |
| 740 } | 743 } |
| 741 | 744 |
| 742 } // namespace download_util | 745 } // namespace download_util |
| OLD | NEW |