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

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

Issue 3029025: Download code cleanup: (Closed)
Patch Set: rebase'n'final Created 10 years, 5 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
« no previous file with comments | « chrome/browser/download/download_util.h ('k') | chrome/browser/download/save_package.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 11 matching lines...) Expand all
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/chrome_thread.h" 25 #include "chrome/browser/chrome_thread.h"
26 #include "chrome/browser/download/download_item.h" 26 #include "chrome/browser/download/download_item.h"
27 #include "chrome/browser/download/download_item_model.h" 27 #include "chrome/browser/download/download_item_model.h"
28 #include "chrome/browser/download/download_manager.h" 28 #include "chrome/browser/download/download_manager.h"
29 #include "chrome/browser/net/chrome_url_request_context.h" 29 #include "chrome/browser/net/chrome_url_request_context.h"
30 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 30 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
31 #include "chrome/common/chrome_paths.h" 31 #include "chrome/common/chrome_paths.h"
32 #include "chrome/common/extensions/extension.h"
33 #include "chrome/common/time_format.h" 32 #include "chrome/common/time_format.h"
34 #include "gfx/canvas_skia.h" 33 #include "gfx/canvas_skia.h"
35 #include "gfx/rect.h" 34 #include "gfx/rect.h"
36 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
37 #include "grit/locale_settings.h" 36 #include "grit/locale_settings.h"
38 #include "grit/theme_resources.h" 37 #include "grit/theme_resources.h"
39 #include "net/base/mime_util.h" 38 #include "net/base/mime_util.h"
40 #include "skia/ext/image_operations.h" 39 #include "skia/ext/image_operations.h"
41 #include "third_party/skia/include/core/SkPath.h" 40 #include "third_party/skia/include/core/SkPath.h"
42 #include "third_party/skia/include/core/SkShader.h" 41 #include "third_party/skia/include/core/SkShader.h"
(...skipping 20 matching lines...) Expand all
63 #include "chrome/browser/browser_list.h" 62 #include "chrome/browser/browser_list.h"
64 #include "chrome/browser/views/frame/browser_view.h" 63 #include "chrome/browser/views/frame/browser_view.h"
65 #endif 64 #endif
66 65
67 namespace download_util { 66 namespace download_util {
68 67
69 // How many times to cycle the complete animation. This should be an odd number 68 // How many times to cycle the complete animation. This should be an odd number
70 // so that the animation ends faded out. 69 // so that the animation ends faded out.
71 static const int kCompleteAnimationCycles = 5; 70 static const int kCompleteAnimationCycles = 5;
72 71
73 // Download opening ------------------------------------------------------------
74
75 bool CanOpenDownload(DownloadItem* download) {
76 FilePath file_to_use = download->full_path();
77 if (!download->original_name().value().empty())
78 file_to_use = download->original_name();
79
80 return !Extension::IsExtension(file_to_use) &&
81 !download->manager()->IsExecutableFile(file_to_use);
82 }
83
84 void OpenDownload(DownloadItem* download) {
85 if (download->state() == DownloadItem::IN_PROGRESS) {
86 download->set_open_when_complete(!download->open_when_complete());
87 } else if (download->state() == DownloadItem::COMPLETE) {
88 download->NotifyObserversDownloadOpened();
89 download->manager()->OpenDownload(download, NULL);
90 }
91 }
92
93 // Download temporary file creation -------------------------------------------- 72 // Download temporary file creation --------------------------------------------
94 73
95 class DefaultDownloadDirectory { 74 class DefaultDownloadDirectory {
96 public: 75 public:
97 const FilePath& path() const { return path_; } 76 const FilePath& path() const { return path_; }
98 private: 77 private:
99 DefaultDownloadDirectory() { 78 DefaultDownloadDirectory() {
100 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) { 79 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) {
101 NOTREACHED(); 80 NOTREACHED();
102 } 81 }
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 } 548 }
570 549
571 FilePath GetCrDownloadPath(const FilePath& suggested_path) { 550 FilePath GetCrDownloadPath(const FilePath& suggested_path) {
572 FilePath::StringType file_name; 551 FilePath::StringType file_name;
573 SStringPrintf(&file_name, PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), 552 SStringPrintf(&file_name, PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"),
574 suggested_path.value().c_str()); 553 suggested_path.value().c_str());
575 return FilePath(file_name); 554 return FilePath(file_name);
576 } 555 }
577 556
578 } // namespace download_util 557 } // namespace download_util
OLDNEW
« no previous file with comments | « chrome/browser/download/download_util.h ('k') | chrome/browser/download/save_package.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698