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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 16018005: Use DownloadItem::GetState() in chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Stopping complete_animation_ when download is cancelled 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/download_handler.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 2594 matching lines...) Expand 10 before | Expand all | Expand 10 after
2605 2605
2606 DownloadManager* download_manager = 2606 DownloadManager* download_manager =
2607 BrowserContext::GetDownloadManager(browser->profile()); 2607 BrowserContext::GetDownloadManager(browser->profile());
2608 DownloadItem* selected_item = download_manager->GetDownload(id); 2608 DownloadItem* selected_item = download_manager->GetDownload(id);
2609 if (!selected_item) { 2609 if (!selected_item) {
2610 AutomationJSONReply(this, reply_message) 2610 AutomationJSONReply(this, reply_message)
2611 .SendError(base::StringPrintf("No download with an id of %d\n", id)); 2611 .SendError(base::StringPrintf("No download with an id of %d\n", id));
2612 return; 2612 return;
2613 } 2613 }
2614 2614
2615 DownloadItem::DownloadState download_state = selected_item->GetState();
2616
2615 // We need to be IN_PROGRESS for these actions. 2617 // We need to be IN_PROGRESS for these actions.
2616 if ((action == "pause" || action == "resume" || action == "cancel") && 2618 if ((action == "pause" || action == "resume" || action == "cancel") &&
2617 !selected_item->IsInProgress()) { 2619 download_state != DownloadItem::IN_PROGRESS) {
2618 AutomationJSONReply(this, reply_message) 2620 AutomationJSONReply(this, reply_message)
2619 .SendError("Selected DownloadItem is not in progress."); 2621 .SendError(base::StringPrintf(
2622 "Action '%s' called on download that is not in progress.",
2623 action.c_str()));
2624 return;
2620 } 2625 }
2621 2626
2622 if (action == "open") { 2627 if (action == "open") {
2623 selected_item->AddObserver( 2628 selected_item->AddObserver(
2624 new AutomationProviderDownloadUpdatedObserver( 2629 new AutomationProviderDownloadUpdatedObserver(
2625 this, reply_message, true, browser->profile()->IsOffTheRecord())); 2630 this, reply_message, true, browser->profile()->IsOffTheRecord()));
2626 selected_item->OpenDownload(); 2631 selected_item->OpenDownload();
2627 } else if (action == "toggle_open_files_like_this") { 2632 } else if (action == "toggle_open_files_like_this") {
2628 DownloadPrefs* prefs = 2633 DownloadPrefs* prefs =
2629 DownloadPrefs::FromBrowserContext(selected_item->GetBrowserContext()); 2634 DownloadPrefs::FromBrowserContext(selected_item->GetBrowserContext());
2630 base::FilePath path = selected_item->GetTargetFilePath(); 2635 base::FilePath path = selected_item->GetTargetFilePath();
2631 if (!selected_item->ShouldOpenFileBasedOnExtension()) 2636 if (!selected_item->ShouldOpenFileBasedOnExtension())
2632 prefs->EnableAutoOpenBasedOnExtension(path); 2637 prefs->EnableAutoOpenBasedOnExtension(path);
2633 else 2638 else
2634 prefs->DisableAutoOpenBasedOnExtension(path); 2639 prefs->DisableAutoOpenBasedOnExtension(path);
2635 AutomationJSONReply(this, reply_message).SendSuccess(NULL); 2640 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
2636 } else if (action == "remove") { 2641 } else if (action == "remove") {
2637 new AutomationProviderDownloadModelChangedObserver( 2642 new AutomationProviderDownloadModelChangedObserver(
2638 this, reply_message, download_manager); 2643 this, reply_message, download_manager);
2639 selected_item->Remove(); 2644 selected_item->Remove();
2640 } else if (action == "decline_dangerous_download") { 2645 } else if (action == "decline_dangerous_download") {
2641 new AutomationProviderDownloadModelChangedObserver( 2646 new AutomationProviderDownloadModelChangedObserver(
2642 this, reply_message, download_manager); 2647 this, reply_message, download_manager);
2643 selected_item->Remove(); 2648 selected_item->Remove();
2644 } else if (action == "save_dangerous_download") { 2649 } else if (action == "save_dangerous_download") {
2645 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2650 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2646 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2651 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2647 selected_item->ValidateDangerousDownload(); 2652 selected_item->ValidateDangerousDownload();
2648 } else if (action == "pause") { 2653 } else if (action == "pause") {
2649 if (!selected_item->IsInProgress() || selected_item->IsPaused()) { 2654 if (selected_item->IsPaused()) {
2650 // Action would be a no-op; respond right from here. No-op implies 2655 // Action would be a no-op; respond right from here. No-op implies
2651 // the test is poorly written or failing, so make it an error return. 2656 // the test is poorly written or failing, so make it an error return.
2652 if (!selected_item->IsInProgress()) { 2657 AutomationJSONReply(this, reply_message)
2653 AutomationJSONReply(this, reply_message) 2658 .SendError("Action 'pause' called on already paused download.");
2654 .SendError("Action 'pause' called on download in termal state.");
2655 } else {
2656 AutomationJSONReply(this, reply_message)
2657 .SendError("Action 'pause' called on already paused download.");
2658 }
2659 } else { 2659 } else {
2660 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2660 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2661 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2661 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2662 selected_item->Pause(); 2662 selected_item->Pause();
2663 } 2663 }
2664 } else if (action == "resume") { 2664 } else if (action == "resume") {
2665 if (!selected_item->IsInProgress() || !selected_item->IsPaused()) { 2665 if (!selected_item->IsPaused()) {
2666 // Action would be a no-op; respond right from here. No-op implies 2666 // Action would be a no-op; respond right from here. No-op implies
2667 // the test is poorly written or failing, so make it an error return. 2667 // the test is poorly written or failing, so make it an error return.
2668 if (!selected_item->IsInProgress()) { 2668 AutomationJSONReply(this, reply_message)
2669 AutomationJSONReply(this, reply_message) 2669 .SendError("Action 'resume' called on unpaused download.");
2670 .SendError("Action 'resume' called on download in termal state.");
2671 } else {
2672 AutomationJSONReply(this, reply_message)
2673 .SendError("Action 'resume' called on unpaused download.");
2674 }
2675 } else { 2670 } else {
2676 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2671 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2677 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2672 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2678 selected_item->Resume(); 2673 selected_item->Resume();
2679 } 2674 }
2680 } else if (action == "cancel") { 2675 } else if (action == "cancel") {
2681 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2676 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2682 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2677 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2683 selected_item->Cancel(true); 2678 selected_item->Cancel(true);
2684 } else { 2679 } else {
(...skipping 3000 matching lines...) Expand 10 before | Expand all | Expand 10 after
5685 if (g_browser_process) 5680 if (g_browser_process)
5686 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 5681 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
5687 } 5682 }
5688 5683
5689 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 5684 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
5690 WebContents* tab) { 5685 WebContents* tab) {
5691 TabStripModel* tab_strip = browser->tab_strip_model(); 5686 TabStripModel* tab_strip = browser->tab_strip_model();
5692 if (tab_strip->GetActiveWebContents() != tab) 5687 if (tab_strip->GetActiveWebContents() != tab)
5693 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); 5688 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true);
5694 } 5689 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/download_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698