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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.cc

Issue 11711003: Remove the DownloadItem::TogglePause() interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to r175145. Created 7 years, 11 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
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/extensions/api/downloads/downloads_api.h" 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <iterator> 9 #include <iterator>
10 #include <set> 10 #include <set>
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 bool DownloadsPauseFunction::RunImpl() { 696 bool DownloadsPauseFunction::RunImpl() {
697 scoped_ptr<extensions::api::downloads::Pause::Params> params( 697 scoped_ptr<extensions::api::downloads::Pause::Params> params(
698 extensions::api::downloads::Pause::Params::Create(*args_)); 698 extensions::api::downloads::Pause::Params::Create(*args_));
699 EXTENSION_FUNCTION_VALIDATE(params.get()); 699 EXTENSION_FUNCTION_VALIDATE(params.get());
700 DownloadItem* download_item = GetDownloadIfInProgress( 700 DownloadItem* download_item = GetDownloadIfInProgress(
701 profile(), include_incognito(), params->download_id); 701 profile(), include_incognito(), params->download_id);
702 if (download_item == NULL) { 702 if (download_item == NULL) {
703 // This could be due to an invalid download ID, or it could be due to the 703 // This could be due to an invalid download ID, or it could be due to the
704 // download not being currently active. 704 // download not being currently active.
705 error_ = download_extension_errors::kInvalidOperationError; 705 error_ = download_extension_errors::kInvalidOperationError;
706 } else if (!download_item->IsPaused()) { 706 } else {
707 // If download_item->IsPaused() already then we treat it as a success. 707 // If the item is already paused, this is a no-op and the
708 download_item->TogglePause(); 708 // operation will silently succeed.
709 download_item->Pause();
709 } 710 }
710 if (error_.empty()) 711 if (error_.empty())
711 RecordApiFunctions(DOWNLOADS_FUNCTION_PAUSE); 712 RecordApiFunctions(DOWNLOADS_FUNCTION_PAUSE);
712 return error_.empty(); 713 return error_.empty();
713 } 714 }
714 715
715 DownloadsResumeFunction::DownloadsResumeFunction() {} 716 DownloadsResumeFunction::DownloadsResumeFunction() {}
716 DownloadsResumeFunction::~DownloadsResumeFunction() {} 717 DownloadsResumeFunction::~DownloadsResumeFunction() {}
717 718
718 bool DownloadsResumeFunction::RunImpl() { 719 bool DownloadsResumeFunction::RunImpl() {
719 scoped_ptr<extensions::api::downloads::Resume::Params> params( 720 scoped_ptr<extensions::api::downloads::Resume::Params> params(
720 extensions::api::downloads::Resume::Params::Create(*args_)); 721 extensions::api::downloads::Resume::Params::Create(*args_));
721 EXTENSION_FUNCTION_VALIDATE(params.get()); 722 EXTENSION_FUNCTION_VALIDATE(params.get());
722 DownloadItem* download_item = GetDownloadIfInProgress( 723 DownloadItem* download_item = GetDownloadIfInProgress(
723 profile(), include_incognito(), params->download_id); 724 profile(), include_incognito(), params->download_id);
724 if (download_item == NULL) { 725 if (download_item == NULL) {
725 // This could be due to an invalid download ID, or it could be due to the 726 // This could be due to an invalid download ID, or it could be due to the
726 // download not being currently active. 727 // download not being currently active.
727 error_ = download_extension_errors::kInvalidOperationError; 728 error_ = download_extension_errors::kInvalidOperationError;
728 } else if (download_item->IsPaused()) { 729 } else {
729 // If !download_item->IsPaused() already, then we treat it as a success. 730 // Note that if the item isn't paused, this will be a no-op, and
730 download_item->TogglePause(); 731 // we will silently treat the extension call as a success.
732 download_item->Resume();
731 } 733 }
732 if (error_.empty()) 734 if (error_.empty())
733 RecordApiFunctions(DOWNLOADS_FUNCTION_RESUME); 735 RecordApiFunctions(DOWNLOADS_FUNCTION_RESUME);
734 return error_.empty(); 736 return error_.empty();
735 } 737 }
736 738
737 DownloadsCancelFunction::DownloadsCancelFunction() {} 739 DownloadsCancelFunction::DownloadsCancelFunction() {}
738 DownloadsCancelFunction::~DownloadsCancelFunction() {} 740 DownloadsCancelFunction::~DownloadsCancelFunction() {}
739 741
740 bool DownloadsCancelFunction::RunImpl() { 742 bool DownloadsCancelFunction::RunImpl() {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 if (profile_->HasOffTheRecordProfile() && 1024 if (profile_->HasOffTheRecordProfile() &&
1023 !profile_->IsOffTheRecord()) { 1025 !profile_->IsOffTheRecord()) {
1024 DispatchEventInternal( 1026 DispatchEventInternal(
1025 profile_->GetOffTheRecordProfile(), 1027 profile_->GetOffTheRecordProfile(),
1026 event_name, 1028 event_name,
1027 json_args, 1029 json_args,
1028 scoped_ptr<base::ListValue>(args->DeepCopy())); 1030 scoped_ptr<base::ListValue>(args->DeepCopy()));
1029 } 1031 }
1030 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); 1032 DispatchEventInternal(profile_, event_name, json_args, args.Pass());
1031 } 1033 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_shelf_context_menu.cc ('k') | chrome/browser/resources/downloads/downloads.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698