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

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: Re-use TOGGLE_PAUSE 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 !download_crx_util::IsExtensionDownload(*download_item_); 80 !download_crx_util::IsExtensionDownload(*download_item_);
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_->IsDone(); 88 return !download_item_->IsDone();
77 case TOGGLE_PAUSE: 89 case TOGGLE_PAUSE:
78 return download_item_->GetState() == DownloadItem::IN_PROGRESS; 90 return !download_item_->IsDone();
79 case DISCARD: 91 case DISCARD:
80 case KEEP: 92 case KEEP:
81 case LEARN_MORE_SCANNING: 93 case LEARN_MORE_SCANNING:
82 case LEARN_MORE_INTERRUPTED: 94 case LEARN_MORE_INTERRUPTED:
83 return true; 95 return true;
84 } 96 }
85 return false; 97 return false;
86 } 98 }
87 99
88 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { 100 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const {
(...skipping 30 matching lines...) Expand all
119 if (!IsCommandIdChecked(ALWAYS_OPEN_TYPE)) 131 if (!IsCommandIdChecked(ALWAYS_OPEN_TYPE))
120 prefs->EnableAutoOpenBasedOnExtension(path); 132 prefs->EnableAutoOpenBasedOnExtension(path);
121 else 133 else
122 prefs->DisableAutoOpenBasedOnExtension(path); 134 prefs->DisableAutoOpenBasedOnExtension(path);
123 break; 135 break;
124 } 136 }
125 case CANCEL: 137 case CANCEL:
126 download_item_->Cancel(true /* Cancelled by user */); 138 download_item_->Cancel(true /* Cancelled by user */);
127 break; 139 break;
128 case TOGGLE_PAUSE: 140 case TOGGLE_PAUSE:
129 // It is possible for the download to complete before the user clicks the 141 if (download_item_->GetState() == DownloadItem::IN_PROGRESS &&
130 // menu item, recheck if the download is in progress state before toggling 142 !download_item_->IsPaused()) {
131 // pause. 143 download_item_->Pause();
132 if (download_item_->GetState() == DownloadItem::IN_PROGRESS) { 144 } else {
133 if (download_item_->IsPaused()) 145 download_item_->Resume();
134 download_item_->Resume();
135 else
136 download_item_->Pause();
137 } 146 }
138 break; 147 break;
139 case DISCARD: 148 case DISCARD:
140 download_item_->Remove(); 149 download_item_->Remove();
141 break; 150 break;
142 case KEEP: 151 case KEEP:
143 download_item_->ValidateDangerousDownload(); 152 download_item_->ValidateDangerousDownload();
144 break; 153 break;
145 case LEARN_MORE_SCANNING: { 154 case LEARN_MORE_SCANNING: {
146 #if defined(FULL_SAFE_BROWSING) 155 #if defined(FULL_SAFE_BROWSING)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW); 193 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW);
185 case OPEN_WHEN_COMPLETE: 194 case OPEN_WHEN_COMPLETE:
186 if (download_item_ && !download_item_->IsDone()) 195 if (download_item_ && !download_item_->IsDone())
187 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE); 196 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE);
188 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN); 197 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN);
189 case ALWAYS_OPEN_TYPE: 198 case ALWAYS_OPEN_TYPE:
190 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); 199 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE);
191 case CANCEL: 200 case CANCEL:
192 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL); 201 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL);
193 case TOGGLE_PAUSE: 202 case TOGGLE_PAUSE:
194 if (download_item_ && download_item_->IsPaused()) 203 if (download_item_ &&
195 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); 204 download_item_->GetState() == DownloadItem::IN_PROGRESS &&
196 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); 205 !download_item_->IsPaused())
206 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM);
207 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM);
197 case DISCARD: 208 case DISCARD:
198 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD); 209 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD);
199 case KEEP: 210 case KEEP:
200 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP); 211 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP);
201 case LEARN_MORE_SCANNING: 212 case LEARN_MORE_SCANNING:
202 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); 213 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING);
203 case LEARN_MORE_INTERRUPTED: 214 case LEARN_MORE_INTERRUPTED:
204 return l10n_util::GetStringUTF16( 215 return l10n_util::GetStringUTF16(
205 IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); 216 IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED);
206 } 217 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 finished_download_menu_model_->AddItemWithStringId( 268 finished_download_menu_model_->AddItemWithStringId(
258 SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW); 269 SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW);
259 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 270 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
260 finished_download_menu_model_->AddItemWithStringId( 271 finished_download_menu_model_->AddItemWithStringId(
261 CANCEL, IDS_DOWNLOAD_MENU_CANCEL); 272 CANCEL, IDS_DOWNLOAD_MENU_CANCEL);
262 273
263 return finished_download_menu_model_.get(); 274 return finished_download_menu_model_.get();
264 } 275 }
265 276
266 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() { 277 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() {
267 #if defined(OS_WIN) 278 #if !defined(OS_WIN)
268 // The Help Center article is currently Windows specific. 279 // 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 280 // options here are applicable.
270 // for other platforms. 281 if (!IsDownloadResumptionEnabled())
282 return GetInProgressMenuModel();
283 #endif
284
271 if (interrupted_download_menu_model_) 285 if (interrupted_download_menu_model_)
272 return interrupted_download_menu_model_.get(); 286 return interrupted_download_menu_model_.get();
273 287
274 interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this)); 288 interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this));
275 289
290 if (IsDownloadResumptionEnabled()) {
291 interrupted_download_menu_model_->AddItemWithStringId(
292 TOGGLE_PAUSE, IDS_DOWNLOAD_MENU_RESUME_ITEM);
293 }
294 #if defined(OS_WIN)
295 // The Help Center article is currently Windows specific.
296 // TODO(asanka): Enable this for other platforms when the article is expanded
297 // for other platforms.
276 interrupted_download_menu_model_->AddItemWithStringId( 298 interrupted_download_menu_model_->AddItemWithStringId(
277 LEARN_MORE_INTERRUPTED, IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); 299 LEARN_MORE_INTERRUPTED, IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED);
300 #endif
301 if (IsDownloadResumptionEnabled()) {
302 interrupted_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
303 interrupted_download_menu_model_->AddItemWithStringId(
304 CANCEL, IDS_DOWNLOAD_MENU_CANCEL);
305 }
278 306
279 return interrupted_download_menu_model_.get(); 307 return interrupted_download_menu_model_.get();
280 #else
281 return GetInProgressMenuModel();
282 #endif
283 } 308 }
284 309
285 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() { 310 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() {
286 if (malicious_download_menu_model_) 311 if (malicious_download_menu_model_)
287 return malicious_download_menu_model_.get(); 312 return malicious_download_menu_model_.get();
288 313
289 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); 314 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this));
290 315
291 malicious_download_menu_model_->AddItemWithStringId( 316 malicious_download_menu_model_->AddItemWithStringId(
292 DISCARD, IDS_DOWNLOAD_MENU_DISCARD); 317 DISCARD, IDS_DOWNLOAD_MENU_DISCARD);
293 malicious_download_menu_model_->AddItemWithStringId( 318 malicious_download_menu_model_->AddItemWithStringId(
294 KEEP, IDS_DOWNLOAD_MENU_KEEP); 319 KEEP, IDS_DOWNLOAD_MENU_KEEP);
295 malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 320 malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
296 malicious_download_menu_model_->AddItemWithStringId( 321 malicious_download_menu_model_->AddItemWithStringId(
297 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); 322 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING);
298 323
299 return malicious_download_menu_model_.get(); 324 return malicious_download_menu_model_.get();
300 } 325 }
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