| OLD | NEW |
| 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 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 scoped_ptr<extensions::api::downloads::Resume::Params> params( | 741 scoped_ptr<extensions::api::downloads::Resume::Params> params( |
| 742 extensions::api::downloads::Resume::Params::Create(*args_)); | 742 extensions::api::downloads::Resume::Params::Create(*args_)); |
| 743 EXTENSION_FUNCTION_VALIDATE(params.get()); | 743 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 744 DownloadItem* download_item = GetDownloadIfInProgress( | 744 DownloadItem* download_item = GetDownloadIfInProgress( |
| 745 profile(), include_incognito(), params->download_id); | 745 profile(), include_incognito(), params->download_id); |
| 746 if (download_item != NULL) | 746 if (download_item != NULL) |
| 747 download_item->Cancel(true); | 747 download_item->Cancel(true); |
| 748 // |download_item| can be NULL if the download ID was invalid or if the | 748 // |download_item| can be NULL if the download ID was invalid or if the |
| 749 // download is not currently active. Either way, we don't consider it a | 749 // download is not currently active. Either way, we don't consider it a |
| 750 // failure. | 750 // failure. |
| 751 if (error_.empty()) | 751 RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL); |
| 752 RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL); | 752 return true; |
| 753 return error_.empty(); | |
| 754 } | 753 } |
| 755 | 754 |
| 756 DownloadsEraseFunction::DownloadsEraseFunction() {} | 755 DownloadsEraseFunction::DownloadsEraseFunction() {} |
| 757 DownloadsEraseFunction::~DownloadsEraseFunction() {} | 756 DownloadsEraseFunction::~DownloadsEraseFunction() {} |
| 758 | 757 |
| 759 bool DownloadsEraseFunction::RunImpl() { | 758 bool DownloadsEraseFunction::RunImpl() { |
| 760 scoped_ptr<extensions::api::downloads::Erase::Params> params( | 759 scoped_ptr<extensions::api::downloads::Erase::Params> params( |
| 761 extensions::api::downloads::Erase::Params::Create(*args_)); | 760 extensions::api::downloads::Erase::Params::Create(*args_)); |
| 762 EXTENSION_FUNCTION_VALIDATE(params.get()); | 761 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 763 error_ = download_extension_errors::kNotImplementedError; | 762 DownloadManager* manager = NULL; |
| 764 if (error_.empty()) | 763 DownloadManager* incognito_manager = NULL; |
| 765 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); | 764 GetManagers(profile(), include_incognito(), &manager, &incognito_manager); |
| 766 return error_.empty(); | 765 DownloadQuery::DownloadVector results; |
| 766 RunDownloadQuery(params->query, |
| 767 manager, |
| 768 incognito_manager, |
| 769 &error_, |
| 770 &results); |
| 771 if (!error_.empty()) |
| 772 return false; |
| 773 base::ListValue* json_results = new base::ListValue(); |
| 774 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); |
| 775 it != results.end(); ++it) { |
| 776 json_results->Append(base::Value::CreateIntegerValue((*it)->GetId())); |
| 777 (*it)->Remove(); |
| 778 } |
| 779 SetResult(json_results); |
| 780 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); |
| 781 return true; |
| 767 } | 782 } |
| 768 | 783 |
| 769 DownloadsSetDestinationFunction::DownloadsSetDestinationFunction() {} | 784 DownloadsSetDestinationFunction::DownloadsSetDestinationFunction() {} |
| 770 DownloadsSetDestinationFunction::~DownloadsSetDestinationFunction() {} | 785 DownloadsSetDestinationFunction::~DownloadsSetDestinationFunction() {} |
| 771 | 786 |
| 772 bool DownloadsSetDestinationFunction::RunImpl() { | 787 bool DownloadsSetDestinationFunction::RunImpl() { |
| 773 scoped_ptr<extensions::api::downloads::SetDestination::Params> params( | 788 scoped_ptr<extensions::api::downloads::SetDestination::Params> params( |
| 774 extensions::api::downloads::SetDestination::Params::Create(*args_)); | 789 extensions::api::downloads::SetDestination::Params::Create(*args_)); |
| 775 EXTENSION_FUNCTION_VALIDATE(params.get()); | 790 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 776 error_ = download_extension_errors::kNotImplementedError; | 791 error_ = download_extension_errors::kNotImplementedError; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 if (profile_->HasOffTheRecordProfile() && | 1017 if (profile_->HasOffTheRecordProfile() && |
| 1003 !profile_->IsOffTheRecord()) { | 1018 !profile_->IsOffTheRecord()) { |
| 1004 DispatchEventInternal( | 1019 DispatchEventInternal( |
| 1005 profile_->GetOffTheRecordProfile(), | 1020 profile_->GetOffTheRecordProfile(), |
| 1006 event_name, | 1021 event_name, |
| 1007 json_args, | 1022 json_args, |
| 1008 scoped_ptr<base::ListValue>(args->DeepCopy())); | 1023 scoped_ptr<base::ListValue>(args->DeepCopy())); |
| 1009 } | 1024 } |
| 1010 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); | 1025 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); |
| 1011 } | 1026 } |
| OLD | NEW |