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

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

Issue 6969009: Reduced the lifetime of DownloadCreateInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed structure accessors from DownloadItem, per request. Created 9 years, 7 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
OLDNEW
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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // The GetPreferredExtensionForMimeType call will end up going to disk. Do 242 // The GetPreferredExtensionForMimeType call will end up going to disk. Do
243 // this on another thread to avoid slowing the IO thread. 243 // this on another thread to avoid slowing the IO thread.
244 // http://crbug.com/61827 244 // http://crbug.com/61827
245 base::ThreadRestrictions::ScopedAllowIO allow_io; 245 base::ThreadRestrictions::ScopedAllowIO allow_io;
246 net::GetPreferredExtensionForMimeType(mime_type, &extension); 246 net::GetPreferredExtensionForMimeType(mime_type, &extension);
247 } 247 }
248 248
249 generated_extension->swap(extension); 249 generated_extension->swap(extension);
250 } 250 }
251 251
252 void GenerateFileNameFromInfo(DownloadCreateInfo* info, 252 void GenerateFileNameFromRequest(const GURL& url,
253 FilePath* generated_name) { 253 const std::string& content_disposition,
254 GenerateFileName(GURL(info->url()), 254 const std::string& referrer_charset,
255 info->content_disposition, 255 const std::string& mime_type,
256 info->referrer_charset, 256 FilePath* generated_name) {
257 info->mime_type, 257 GenerateFileName(url,
258 content_disposition,
259 referrer_charset,
260 mime_type,
258 generated_name); 261 generated_name);
259 } 262 }
260 263
261 void GenerateFileName(const GURL& url, 264 void GenerateFileName(const GURL& url,
262 const std::string& content_disposition, 265 const std::string& content_disposition,
263 const std::string& referrer_charset, 266 const std::string& referrer_charset,
264 const std::string& mime_type, 267 const std::string& mime_type,
265 FilePath* generated_name) { 268 FilePath* generated_name) {
266 string16 default_file_name( 269 string16 default_file_name(
267 l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME)); 270 l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME));
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 FilePath GetCrDownloadPath(const FilePath& suggested_path) { 886 FilePath GetCrDownloadPath(const FilePath& suggested_path) {
884 FilePath::StringType file_name; 887 FilePath::StringType file_name;
885 base::SStringPrintf( 888 base::SStringPrintf(
886 &file_name, 889 &file_name,
887 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), 890 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"),
888 suggested_path.value().c_str()); 891 suggested_path.value().c_str());
889 return FilePath(file_name); 892 return FilePath(file_name);
890 } 893 }
891 894
892 // TODO(erikkay,phajdan.jr): This is apparently not being exercised in tests. 895 // TODO(erikkay,phajdan.jr): This is apparently not being exercised in tests.
893 bool IsDangerous(DownloadCreateInfo* info, Profile* profile, bool auto_open) { 896 bool IsDangerous(const GURL& url,
897 const GURL& referrer_url,
898 const FilePath& suggested_path,
899 bool has_user_gesture,
900 bool is_extension_install,
901 Profile* profile,
902 bool auto_open) {
894 DownloadDangerLevel danger_level = GetFileDangerLevel( 903 DownloadDangerLevel danger_level = GetFileDangerLevel(
895 info->suggested_path.BaseName()); 904 suggested_path.BaseName());
896 if (danger_level == Dangerous) 905 if (danger_level == Dangerous)
897 return !(auto_open && info->has_user_gesture); 906 return !(auto_open && has_user_gesture);
898 if (danger_level == AllowOnUserGesture && !info->has_user_gesture) 907 if (danger_level == AllowOnUserGesture && !has_user_gesture)
899 return true; 908 return true;
900 if (info->is_extension_install) { 909 if (is_extension_install) {
901 // Extensions that are not from the gallery are considered dangerous. 910 // Extensions that are not from the gallery are considered dangerous.
902 ExtensionService* service = profile->GetExtensionService(); 911 ExtensionService* service = profile->GetExtensionService();
903 if (!service || 912 if (!service || !service->IsDownloadFromGallery(url, referrer_url))
904 !service->IsDownloadFromGallery(info->url(), info->referrer_url))
905 return true; 913 return true;
906 } 914 }
907 return false; 915 return false;
908 } 916 }
909 917
910 } // namespace download_util 918 } // namespace download_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698