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 // 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> |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // TODO(phajdan.jr): Find some standard location for this, maintaining | 81 // TODO(phajdan.jr): Find some standard location for this, maintaining |
82 // the same value on all platforms. | 82 // the same value on all platforms. |
83 static const double PI = 3.141592653589793; | 83 static const double PI = 3.141592653589793; |
84 | 84 |
85 namespace download_util { | 85 namespace download_util { |
86 | 86 |
87 // How many times to cycle the complete animation. This should be an odd number | 87 // How many times to cycle the complete animation. This should be an odd number |
88 // so that the animation ends faded out. | 88 // so that the animation ends faded out. |
89 static const int kCompleteAnimationCycles = 5; | 89 static const int kCompleteAnimationCycles = 5; |
90 | 90 |
91 namespace { | |
92 | |
93 void GenerateFileNameInternal(const GURL& url, | |
94 const std::string& content_disposition, | |
95 const std::string& referrer_charset, | |
96 const std::string& suggested_name, | |
97 const std::string& mime_type, | |
98 FilePath* generated_name) { | |
99 std::string default_file_name( | |
100 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | |
101 | |
102 *generated_name = net::GenerateFileName(url, content_disposition, | |
103 referrer_charset, suggested_name, | |
104 mime_type, default_file_name); | |
105 } | |
106 | |
107 } // namespace | |
108 | |
109 // Download temporary file creation -------------------------------------------- | 91 // Download temporary file creation -------------------------------------------- |
110 | 92 |
111 class DefaultDownloadDirectory { | 93 class DefaultDownloadDirectory { |
112 public: | 94 public: |
113 const FilePath& path() const { return path_; } | 95 const FilePath& path() const { return path_; } |
114 private: | 96 private: |
115 DefaultDownloadDirectory() { | 97 DefaultDownloadDirectory() { |
116 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) { | 98 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) { |
117 NOTREACHED(); | 99 NOTREACHED(); |
118 } | 100 } |
(...skipping 18 matching lines...) Expand all Loading... |
137 FilePath desktop_dir; | 119 FilePath desktop_dir; |
138 if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) { | 120 if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) { |
139 NOTREACHED(); | 121 NOTREACHED(); |
140 return false; | 122 return false; |
141 } | 123 } |
142 return (download_path == desktop_dir); | 124 return (download_path == desktop_dir); |
143 } | 125 } |
144 | 126 |
145 void GenerateFileNameFromRequest(const DownloadItem& download_item, | 127 void GenerateFileNameFromRequest(const DownloadItem& download_item, |
146 FilePath* generated_name) { | 128 FilePath* generated_name) { |
147 GenerateFileNameInternal(download_item.GetURL(), | 129 std::string default_file_name( |
148 download_item.content_disposition(), | 130 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
149 download_item.referrer_charset(), | |
150 download_item.suggested_filename(), | |
151 download_item.mime_type(), | |
152 generated_name); | |
153 } | |
154 | 131 |
155 void GenerateFileNameFromSuggestedName(const GURL& url, | 132 *generated_name = net::GenerateFileName(download_item.GetURL(), |
156 const std::string& suggested_name, | 133 download_item.content_disposition(), |
157 const std::string& mime_type, | 134 download_item.referrer_charset(), |
158 FilePath* generated_name) { | 135 download_item.suggested_filename(), |
159 // TODO(asanka): We should pass in a valid referrer_charset here. | 136 download_item.mime_type(), |
160 GenerateFileNameInternal(url, std::string(), std::string(), | 137 default_file_name); |
161 suggested_name, mime_type, generated_name); | |
162 } | 138 } |
163 | 139 |
164 // Download progress painting -------------------------------------------------- | 140 // Download progress painting -------------------------------------------------- |
165 | 141 |
166 // Common bitmaps used for download progress animations. We load them once the | 142 // Common bitmaps used for download progress animations. We load them once the |
167 // first time we do a progress paint, then reuse them as they are always the | 143 // first time we do a progress paint, then reuse them as they are always the |
168 // same. | 144 // same. |
169 SkBitmap* g_foreground_16 = NULL; | 145 SkBitmap* g_foreground_16 = NULL; |
170 SkBitmap* g_background_16 = NULL; | 146 SkBitmap* g_background_16 = NULL; |
171 SkBitmap* g_foreground_32 = NULL; | 147 SkBitmap* g_foreground_32 = NULL; |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 return DownloadFile::GetUniquePathNumberWithSuffix( | 565 return DownloadFile::GetUniquePathNumberWithSuffix( |
590 path, FILE_PATH_LITERAL(".crdownload")); | 566 path, FILE_PATH_LITERAL(".crdownload")); |
591 } | 567 } |
592 | 568 |
593 FilePath GetCrDownloadPath(const FilePath& suggested_path) { | 569 FilePath GetCrDownloadPath(const FilePath& suggested_path) { |
594 return DownloadFile::AppendSuffixToPath( | 570 return DownloadFile::AppendSuffixToPath( |
595 suggested_path, FILE_PATH_LITERAL(".crdownload")); | 571 suggested_path, FILE_PATH_LITERAL(".crdownload")); |
596 } | 572 } |
597 | 573 |
598 } // namespace download_util | 574 } // namespace download_util |
OLD | NEW |