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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 current_profile); | 549 current_profile); |
550 manager->DownloadUrl(download_params.Pass()); | 550 manager->DownloadUrl(download_params.Pass()); |
551 RecordApiFunctions(DOWNLOADS_FUNCTION_DOWNLOAD); | 551 RecordApiFunctions(DOWNLOADS_FUNCTION_DOWNLOAD); |
552 return true; | 552 return true; |
553 } | 553 } |
554 | 554 |
555 void DownloadsDownloadFunction::OnStarted(DownloadId dl_id, net::Error error) { | 555 void DownloadsDownloadFunction::OnStarted(DownloadId dl_id, net::Error error) { |
556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
557 VLOG(1) << __FUNCTION__ << " " << dl_id << " " << error; | 557 VLOG(1) << __FUNCTION__ << " " << dl_id << " " << error; |
558 if (dl_id.local() >= 0) { | 558 if (dl_id.local() >= 0) { |
559 result_.reset(base::Value::CreateIntegerValue(dl_id.local())); | 559 SetResult(base::Value::CreateIntegerValue(dl_id.local())); |
560 } else { | 560 } else { |
561 error_ = net::ErrorToString(error); | 561 error_ = net::ErrorToString(error); |
562 } | 562 } |
563 SendResponse(error_.empty()); | 563 SendResponse(error_.empty()); |
564 } | 564 } |
565 | 565 |
566 DownloadsSearchFunction::DownloadsSearchFunction() {} | 566 DownloadsSearchFunction::DownloadsSearchFunction() {} |
567 DownloadsSearchFunction::~DownloadsSearchFunction() {} | 567 DownloadsSearchFunction::~DownloadsSearchFunction() {} |
568 | 568 |
569 bool DownloadsSearchFunction::RunImpl() { | 569 bool DownloadsSearchFunction::RunImpl() { |
570 scoped_ptr<extensions::api::downloads::Search::Params> params( | 570 scoped_ptr<extensions::api::downloads::Search::Params> params( |
571 extensions::api::downloads::Search::Params::Create(*args_)); | 571 extensions::api::downloads::Search::Params::Create(*args_)); |
572 EXTENSION_FUNCTION_VALIDATE(params.get()); | 572 EXTENSION_FUNCTION_VALIDATE(params.get()); |
573 DownloadQuery::DownloadVector results; | 573 DownloadQuery::DownloadVector results; |
574 RunDownloadQuery(params->query, profile(), include_incognito(), | 574 RunDownloadQuery(params->query, profile(), include_incognito(), |
575 &error_, &results); | 575 &error_, &results); |
576 if (!error_.empty()) | 576 if (!error_.empty()) |
577 return false; | 577 return false; |
578 base::ListValue* json_results = new base::ListValue(); | 578 base::ListValue* json_results = new base::ListValue(); |
579 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); | 579 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); |
580 it != results.end(); ++it) { | 580 it != results.end(); ++it) { |
581 scoped_ptr<base::DictionaryValue> item(DownloadItemToJSON(*it)); | 581 scoped_ptr<base::DictionaryValue> item(DownloadItemToJSON(*it)); |
582 json_results->Append(item.release()); | 582 json_results->Append(item.release()); |
583 } | 583 } |
584 result_.reset(json_results); | 584 SetResult(json_results); |
585 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); | 585 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); |
586 return true; | 586 return true; |
587 } | 587 } |
588 | 588 |
589 DownloadsPauseFunction::DownloadsPauseFunction() {} | 589 DownloadsPauseFunction::DownloadsPauseFunction() {} |
590 DownloadsPauseFunction::~DownloadsPauseFunction() {} | 590 DownloadsPauseFunction::~DownloadsPauseFunction() {} |
591 | 591 |
592 bool DownloadsPauseFunction::RunImpl() { | 592 bool DownloadsPauseFunction::RunImpl() { |
593 scoped_ptr<extensions::api::downloads::Pause::Params> params( | 593 scoped_ptr<extensions::api::downloads::Pause::Params> params( |
594 extensions::api::downloads::Pause::Params::Create(*args_)); | 594 extensions::api::downloads::Pause::Params::Create(*args_)); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this))); | 774 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this))); |
775 return true; | 775 return true; |
776 } | 776 } |
777 | 777 |
778 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { | 778 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { |
779 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 779 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
780 if (url.empty()) { | 780 if (url.empty()) { |
781 error_ = download_extension_errors::kIconNotFoundError; | 781 error_ = download_extension_errors::kIconNotFoundError; |
782 } else { | 782 } else { |
783 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); | 783 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); |
784 result_.reset(base::Value::CreateStringValue(url)); | 784 SetResult(base::Value::CreateStringValue(url)); |
785 } | 785 } |
786 SendResponse(error_.empty()); | 786 SendResponse(error_.empty()); |
787 } | 787 } |
788 | 788 |
789 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( | 789 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( |
790 Profile* profile, | 790 Profile* profile, |
791 DownloadManager* manager) | 791 DownloadManager* manager) |
792 : profile_(profile), | 792 : profile_(profile), |
793 manager_(manager) { | 793 manager_(manager) { |
794 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 794 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 extensions::EventFilteringInfo()); | 965 extensions::EventFilteringInfo()); |
966 | 966 |
967 DownloadsNotificationSource notification_source; | 967 DownloadsNotificationSource notification_source; |
968 notification_source.event_name = event_name; | 968 notification_source.event_name = event_name; |
969 notification_source.profile = profile_; | 969 notification_source.profile = profile_; |
970 content::NotificationService::current()->Notify( | 970 content::NotificationService::current()->Notify( |
971 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, | 971 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, |
972 content::Source<DownloadsNotificationSource>(¬ification_source), | 972 content::Source<DownloadsNotificationSource>(¬ification_source), |
973 content::Details<std::string>(&json_args)); | 973 content::Details<std::string>(&json_args)); |
974 } | 974 } |
OLD | NEW |