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

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

Issue 14955004: [Resumption 11/12] Support resuming interrupted downloads from the downloads shelf. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Depend on https://codereview.chromium.org/16007017/ Created 7 years, 6 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
« no previous file with comments | « chrome/browser/download/download_shelf_context_menu.h ('k') | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_shelf_context_menu.h" 5 #include "chrome/browser/download/download_shelf_context_menu.h"
6 6
7 #include "base/command_line.h"
7 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/download/download_crx_util.h" 9 #include "chrome/browser/download/download_crx_util.h"
9 #include "chrome/browser/download/download_item_model.h" 10 #include "chrome/browser/download/download_item_model.h"
10 #include "chrome/browser/download/download_prefs.h" 11 #include "chrome/browser/download/download_prefs.h"
11 #include "chrome/browser/safe_browsing/download_protection_service.h" 12 #include "chrome/browser/safe_browsing/download_protection_service.h"
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
13 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
14 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
15 #include "content/public/browser/download_item.h" 16 #include "content/public/browser/download_item.h"
16 #include "content/public/browser/download_manager.h" 17 #include "content/public/browser/download_manager.h"
17 #include "content/public/browser/page_navigator.h" 18 #include "content/public/browser/page_navigator.h"
19 #include "content/public/common/content_switches.h"
18 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
20 22
21 using content::DownloadItem; 23 using content::DownloadItem;
22 using extensions::Extension; 24 using extensions::Extension;
23 25
26 namespace {
27
28 // Returns true if downloads resumption is enabled.
29 bool IsDownloadResumptionEnabled() {
30 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
31 return command_line.HasSwitch(switches::kEnableDownloadResumption);
32 }
33
34 } // namespace
35
24 DownloadShelfContextMenu::~DownloadShelfContextMenu() { 36 DownloadShelfContextMenu::~DownloadShelfContextMenu() {
25 DetachFromDownloadItem(); 37 DetachFromDownloadItem();
26 } 38 }
27 39
28 DownloadShelfContextMenu::DownloadShelfContextMenu( 40 DownloadShelfContextMenu::DownloadShelfContextMenu(
29 DownloadItem* download_item, 41 DownloadItem* download_item,
30 content::PageNavigator* navigator) 42 content::PageNavigator* navigator)
31 : download_item_(download_item), 43 : download_item_(download_item),
32 navigator_(navigator) { 44 navigator_(navigator) {
33 DCHECK(download_item_); 45 DCHECK(download_item_);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 case ALWAYS_OPEN_TYPE: 81 case ALWAYS_OPEN_TYPE:
70 // For temporary downloads, the target filename might be a temporary 82 // For temporary downloads, the target filename might be a temporary
71 // filename. Don't base an "Always open" decision based on it. Also 83 // filename. Don't base an "Always open" decision based on it. Also
72 // exclude extensions. 84 // exclude extensions.
73 return download_item_->CanOpenDownload() && 85 return download_item_->CanOpenDownload() &&
74 !download_crx_util::IsExtensionDownload(*download_item_); 86 !download_crx_util::IsExtensionDownload(*download_item_);
75 case CANCEL: 87 case CANCEL:
76 return download_item_->IsPartialDownload(); 88 return download_item_->IsPartialDownload();
77 case TOGGLE_PAUSE: 89 case TOGGLE_PAUSE:
78 return download_item_->GetState() == DownloadItem::IN_PROGRESS; 90 return download_item_->GetState() == DownloadItem::IN_PROGRESS;
91 case RESUME_INTERRUPTED:
92 return download_item_->IsInterrupted() && download_item_->CanResume();
Randy Smith (Not in Mondays) 2013/06/05 20:12:55 Actually, an extra high-level question: Why not ju
asanka 2013/06/05 20:29:17 Good question. I did it that way the first time ar
79 case DISCARD: 93 case DISCARD:
80 case KEEP: 94 case KEEP:
81 case LEARN_MORE_SCANNING: 95 case LEARN_MORE_SCANNING:
82 case LEARN_MORE_INTERRUPTED: 96 case LEARN_MORE_INTERRUPTED:
83 return true; 97 return true;
84 } 98 }
85 return false; 99 return false;
86 } 100 }
87 101
88 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { 102 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // It is possible for the download to complete before the user clicks the 143 // It is possible for the download to complete before the user clicks the
130 // menu item, recheck if the download is in progress state before toggling 144 // menu item, recheck if the download is in progress state before toggling
131 // pause. 145 // pause.
132 if (download_item_->GetState() == DownloadItem::IN_PROGRESS) { 146 if (download_item_->GetState() == DownloadItem::IN_PROGRESS) {
133 if (download_item_->IsPaused()) 147 if (download_item_->IsPaused())
134 download_item_->Resume(); 148 download_item_->Resume();
135 else 149 else
136 download_item_->Pause(); 150 download_item_->Pause();
137 } 151 }
138 break; 152 break;
153 case RESUME_INTERRUPTED:
154 download_item_->Resume();
155 break;
139 case DISCARD: 156 case DISCARD:
140 download_item_->Remove(); 157 download_item_->Remove();
141 break; 158 break;
142 case KEEP: 159 case KEEP:
143 download_item_->ValidateDangerousDownload(); 160 download_item_->ValidateDangerousDownload();
144 break; 161 break;
145 case LEARN_MORE_SCANNING: { 162 case LEARN_MORE_SCANNING: {
146 #if defined(FULL_SAFE_BROWSING) 163 #if defined(FULL_SAFE_BROWSING)
147 using safe_browsing::DownloadProtectionService; 164 using safe_browsing::DownloadProtectionService;
148 SafeBrowsingService* sb_service = 165 SafeBrowsingService* sb_service =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE); 204 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE);
188 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN); 205 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN);
189 case ALWAYS_OPEN_TYPE: 206 case ALWAYS_OPEN_TYPE:
190 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); 207 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE);
191 case CANCEL: 208 case CANCEL:
192 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL); 209 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL);
193 case TOGGLE_PAUSE: 210 case TOGGLE_PAUSE:
194 if (download_item_ && download_item_->IsPaused()) 211 if (download_item_ && download_item_->IsPaused())
195 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); 212 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM);
196 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); 213 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM);
214 case RESUME_INTERRUPTED:
215 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM);
197 case DISCARD: 216 case DISCARD:
198 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD); 217 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD);
199 case KEEP: 218 case KEEP:
200 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP); 219 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP);
201 case LEARN_MORE_SCANNING: 220 case LEARN_MORE_SCANNING:
202 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); 221 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING);
203 case LEARN_MORE_INTERRUPTED: 222 case LEARN_MORE_INTERRUPTED:
204 return l10n_util::GetStringUTF16( 223 return l10n_util::GetStringUTF16(
205 IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); 224 IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED);
206 } 225 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 finished_download_menu_model_->AddItemWithStringId( 276 finished_download_menu_model_->AddItemWithStringId(
258 SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW); 277 SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW);
259 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 278 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
260 finished_download_menu_model_->AddItemWithStringId( 279 finished_download_menu_model_->AddItemWithStringId(
261 CANCEL, IDS_DOWNLOAD_MENU_CANCEL); 280 CANCEL, IDS_DOWNLOAD_MENU_CANCEL);
262 281
263 return finished_download_menu_model_.get(); 282 return finished_download_menu_model_.get();
264 } 283 }
265 284
266 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() { 285 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() {
267 #if defined(OS_WIN) 286 #if !defined(OS_WIN)
268 // The Help Center article is currently Windows specific. 287 // If resumption isn't enabled and we aren't on Windows, then none of the
269 // TODO(asanka): Enable this for other platforms when the article is expanded 288 // options here are applicable.
270 // for other platforms. 289 if (!IsDownloadResumptionEnabled())
290 return GetInProgressMenuModel();
291 #endif
292
271 if (interrupted_download_menu_model_) 293 if (interrupted_download_menu_model_)
272 return interrupted_download_menu_model_.get(); 294 return interrupted_download_menu_model_.get();
273 295
274 interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this)); 296 interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this));
275 297
298 if (IsDownloadResumptionEnabled()) {
299 interrupted_download_menu_model_->AddItemWithStringId(
300 RESUME_INTERRUPTED, IDS_DOWNLOAD_MENU_RESUME_ITEM);
301 }
302 #if defined(OS_WIN)
303 // The Help Center article is currently Windows specific.
304 // TODO(asanka): Enable this for other platforms when the article is expanded
305 // for other platforms.
276 interrupted_download_menu_model_->AddItemWithStringId( 306 interrupted_download_menu_model_->AddItemWithStringId(
277 LEARN_MORE_INTERRUPTED, IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); 307 LEARN_MORE_INTERRUPTED, IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED);
308 #endif
309 if (IsDownloadResumptionEnabled()) {
310 interrupted_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
311 interrupted_download_menu_model_->AddItemWithStringId(
312 CANCEL, IDS_DOWNLOAD_MENU_CANCEL);
313 }
278 314
279 return interrupted_download_menu_model_.get(); 315 return interrupted_download_menu_model_.get();
280 #else
281 return GetInProgressMenuModel();
282 #endif
283 } 316 }
284 317
285 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() { 318 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() {
286 if (malicious_download_menu_model_) 319 if (malicious_download_menu_model_)
287 return malicious_download_menu_model_.get(); 320 return malicious_download_menu_model_.get();
288 321
289 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); 322 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this));
290 323
291 malicious_download_menu_model_->AddItemWithStringId( 324 malicious_download_menu_model_->AddItemWithStringId(
292 DISCARD, IDS_DOWNLOAD_MENU_DISCARD); 325 DISCARD, IDS_DOWNLOAD_MENU_DISCARD);
293 malicious_download_menu_model_->AddItemWithStringId( 326 malicious_download_menu_model_->AddItemWithStringId(
294 KEEP, IDS_DOWNLOAD_MENU_KEEP); 327 KEEP, IDS_DOWNLOAD_MENU_KEEP);
295 malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 328 malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
296 malicious_download_menu_model_->AddItemWithStringId( 329 malicious_download_menu_model_->AddItemWithStringId(
297 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); 330 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING);
298 331
299 return malicious_download_menu_model_.get(); 332 return malicious_download_menu_model_.get();
300 } 333 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_shelf_context_menu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698