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

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

Issue 1087843004: [Download Notification] Refine retry logic when interrupted or cancelled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/download/download_commands.h" 5 #include "chrome/browser/download/download_commands.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/download/download_crx_util.h" 8 #include "chrome/browser/download/download_crx_util.h"
9 #include "chrome/browser/download/download_item_model.h" 9 #include "chrome/browser/download/download_item_model.h"
10 #include "chrome/browser/download/download_prefs.h" 10 #include "chrome/browser/download/download_prefs.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/safe_browsing/download_protection_service.h" 12 #include "chrome/browser/safe_browsing/download_protection_service.h"
13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
14 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
16 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "content/public/browser/download_manager.h"
19 #include "content/public/browser/download_url_parameters.h"
18 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
21 23
22 #if defined(OS_WIN) 24 #if defined(OS_WIN)
23 #include "chrome/browser/download/download_target_determiner.h" 25 #include "chrome/browser/download/download_target_determiner.h"
24 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" 26 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
25 #endif 27 #endif
26 28
27 DownloadCommands::DownloadCommands(content::DownloadItem* download_item) 29 DownloadCommands::DownloadCommands(content::DownloadItem* download_item)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 131 }
130 132
131 bool DownloadCommands::IsCommandVisible(Command command) const { 133 bool DownloadCommands::IsCommandVisible(Command command) const {
132 if (command == PLATFORM_OPEN) 134 if (command == PLATFORM_OPEN)
133 return (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser()); 135 return (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser());
134 136
135 return true; 137 return true;
136 } 138 }
137 139
138 void DownloadCommands::ExecuteCommand(Command command) { 140 void DownloadCommands::ExecuteCommand(Command command) {
141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
142
139 switch (command) { 143 switch (command) {
140 case SHOW_IN_FOLDER: 144 case SHOW_IN_FOLDER:
141 download_item_->ShowDownloadInShell(); 145 download_item_->ShowDownloadInShell();
142 break; 146 break;
143 case OPEN_WHEN_COMPLETE: 147 case OPEN_WHEN_COMPLETE:
144 download_item_->OpenDownload(); 148 download_item_->OpenDownload();
145 break; 149 break;
146 case ALWAYS_OPEN_TYPE: { 150 case ALWAYS_OPEN_TYPE: {
147 bool is_checked = IsCommandChecked(ALWAYS_OPEN_TYPE); 151 bool is_checked = IsCommandChecked(ALWAYS_OPEN_TYPE);
148 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( 152 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 GetBrowser()->OpenURL(content::OpenURLParams( 200 GetBrowser()->OpenURL(content::OpenURLParams(
197 GURL(chrome::kDownloadInterruptedLearnMoreURL), content::Referrer(), 201 GURL(chrome::kDownloadInterruptedLearnMoreURL), content::Referrer(),
198 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, false)); 202 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, false));
199 break; 203 break;
200 case PAUSE: 204 case PAUSE:
201 download_item_->Pause(); 205 download_item_->Pause();
202 break; 206 break;
203 case RESUME: 207 case RESUME:
204 download_item_->Resume(); 208 download_item_->Resume();
205 break; 209 break;
206 case RETRY: 210 case RETRY: {
207 if (download_item_->CanResume()) { 211 content::DownloadManager* download_manager =
208 download_item_->Resume(); 212 content::BrowserContext::GetDownloadManager(
209 } else { 213 download_item_->GetBrowserContext());
210 // TODO(yoshiki): Implement retry logic. 214 scoped_ptr<content::DownloadUrlParameters> params(
211 } 215 content::DownloadUrlParameters::FromWebContents(
216 download_item_->GetWebContents(), download_item_->GetURL()));
asanka 2015/04/22 21:17:35 DownloadItem::GetWebContents() isn't guaranteed to
217 params->set_referrer(content::Referrer(download_item_->GetReferrerUrl(),
218 blink::WebReferrerPolicyDefault));
219
220 // Removes the previous donwload item.
221 download_item_->Remove();
222
223 // Starts new download.
224 download_manager->DownloadUrl(params.Pass());
212 break; 225 break;
226 }
213 } 227 }
214 } 228 }
215 229
216 Browser* DownloadCommands::GetBrowser() const { 230 Browser* DownloadCommands::GetBrowser() const {
217 Profile* profile = 231 Profile* profile =
218 Profile::FromBrowserContext(download_item_->GetBrowserContext()); 232 Profile::FromBrowserContext(download_item_->GetBrowserContext());
219 chrome::ScopedTabbedBrowserDisplayer browser_displayer( 233 chrome::ScopedTabbedBrowserDisplayer browser_displayer(
220 profile, chrome::GetActiveDesktop()); 234 profile, chrome::GetActiveDesktop());
221 DCHECK(browser_displayer.browser()); 235 DCHECK(browser_displayer.browser());
222 return browser_displayer.browser(); 236 return browser_displayer.browser();
(...skipping 13 matching lines...) Expand all
236 is_adobe_pdf_reader_up_to_date = 250 is_adobe_pdf_reader_up_to_date =
237 DownloadTargetDeterminer::IsAdobeReaderUpToDate(); 251 DownloadTargetDeterminer::IsAdobeReaderUpToDate();
238 } 252 }
239 return IsDownloadPdf() && 253 return IsDownloadPdf() &&
240 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date 254 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date
241 : true); 255 : true);
242 #elif defined(OS_MACOSX) || defined(OS_LINUX) 256 #elif defined(OS_MACOSX) || defined(OS_LINUX)
243 return IsDownloadPdf(); 257 return IsDownloadPdf();
244 #endif 258 #endif
245 } 259 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698