Chromium Code Reviews| Index: chrome/browser/download/download_shelf_context_menu.cc |
| diff --git a/chrome/browser/download/download_shelf_context_menu.cc b/chrome/browser/download/download_shelf_context_menu.cc |
| index f7555ea2ad481ee6482ce73038ba725ecd82f9e0..d376da843a251dc8fd1dd7ffac200de1daf6a170 100644 |
| --- a/chrome/browser/download/download_shelf_context_menu.cc |
| +++ b/chrome/browser/download/download_shelf_context_menu.cc |
| @@ -4,6 +4,7 @@ |
| #include "chrome/browser/download/download_shelf_context_menu.h" |
| +#include "base/command_line.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/download/download_crx_util.h" |
| #include "chrome/browser/download/download_item_model.h" |
| @@ -15,12 +16,23 @@ |
| #include "content/public/browser/download_item.h" |
| #include "content/public/browser/download_manager.h" |
| #include "content/public/browser/page_navigator.h" |
| +#include "content/public/common/content_switches.h" |
| #include "grit/generated_resources.h" |
| #include "ui/base/l10n/l10n_util.h" |
| using content::DownloadItem; |
| using extensions::Extension; |
| +namespace { |
| + |
| +// Returns true if downloads resumption is enabled. |
| +bool IsDownloadResumptionEnabled() { |
| + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| + return command_line.HasSwitch(switches::kEnableDownloadResumption); |
| +} |
| + |
| +} // namespace |
| + |
| DownloadShelfContextMenu::~DownloadShelfContextMenu() { |
| DetachFromDownloadItem(); |
| } |
| @@ -76,6 +88,8 @@ bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { |
| return download_item_->IsPartialDownload(); |
| case TOGGLE_PAUSE: |
| return download_item_->GetState() == DownloadItem::IN_PROGRESS; |
| + case RESUME_INTERRUPTED: |
| + 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
|
| case DISCARD: |
| case KEEP: |
| case LEARN_MORE_SCANNING: |
| @@ -136,6 +150,9 @@ void DownloadShelfContextMenu::ExecuteCommand(int command_id, int event_flags) { |
| download_item_->Pause(); |
| } |
| break; |
| + case RESUME_INTERRUPTED: |
| + download_item_->Resume(); |
| + break; |
| case DISCARD: |
| download_item_->Remove(); |
| break; |
| @@ -194,6 +211,8 @@ string16 DownloadShelfContextMenu::GetLabelForCommandId(int command_id) const { |
| if (download_item_ && download_item_->IsPaused()) |
| return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); |
| return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); |
| + case RESUME_INTERRUPTED: |
| + return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); |
| case DISCARD: |
| return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD); |
| case KEEP: |
| @@ -264,22 +283,36 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetFinishedMenuModel() { |
| } |
| ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() { |
| -#if defined(OS_WIN) |
| - // The Help Center article is currently Windows specific. |
| - // TODO(asanka): Enable this for other platforms when the article is expanded |
| - // for other platforms. |
| +#if !defined(OS_WIN) |
| + // If resumption isn't enabled and we aren't on Windows, then none of the |
| + // options here are applicable. |
| + if (!IsDownloadResumptionEnabled()) |
| + return GetInProgressMenuModel(); |
| +#endif |
| + |
| if (interrupted_download_menu_model_) |
| return interrupted_download_menu_model_.get(); |
| interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| + if (IsDownloadResumptionEnabled()) { |
| + interrupted_download_menu_model_->AddItemWithStringId( |
| + RESUME_INTERRUPTED, IDS_DOWNLOAD_MENU_RESUME_ITEM); |
| + } |
| +#if defined(OS_WIN) |
| + // The Help Center article is currently Windows specific. |
| + // TODO(asanka): Enable this for other platforms when the article is expanded |
| + // for other platforms. |
| interrupted_download_menu_model_->AddItemWithStringId( |
| LEARN_MORE_INTERRUPTED, IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); |
| +#endif |
| + if (IsDownloadResumptionEnabled()) { |
| + interrupted_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| + interrupted_download_menu_model_->AddItemWithStringId( |
| + CANCEL, IDS_DOWNLOAD_MENU_CANCEL); |
| + } |
| return interrupted_download_menu_model_.get(); |
| -#else |
| - return GetInProgressMenuModel(); |
| -#endif |
| } |
| ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() { |