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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 std::string TimeToISO8601(const base::Time& t) { | 239 std::string TimeToISO8601(const base::Time& t) { |
240 base::Time::Exploded exploded; | 240 base::Time::Exploded exploded; |
241 t.UTCExplode(&exploded); | 241 t.UTCExplode(&exploded); |
242 return base::StringPrintf( | 242 return base::StringPrintf( |
243 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month, | 243 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month, |
244 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, | 244 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, |
245 exploded.millisecond); | 245 exploded.millisecond); |
246 } | 246 } |
247 | 247 |
248 scoped_ptr<base::DictionaryValue> DownloadItemToJSON( | 248 std::unique_ptr<base::DictionaryValue> DownloadItemToJSON( |
249 DownloadItem* download_item, | 249 DownloadItem* download_item, |
250 Profile* profile) { | 250 Profile* profile) { |
251 base::DictionaryValue* json = new base::DictionaryValue(); | 251 base::DictionaryValue* json = new base::DictionaryValue(); |
252 json->SetBoolean(kExistsKey, !download_item->GetFileExternallyRemoved()); | 252 json->SetBoolean(kExistsKey, !download_item->GetFileExternallyRemoved()); |
253 json->SetInteger(kIdKey, download_item->GetId()); | 253 json->SetInteger(kIdKey, download_item->GetId()); |
254 const GURL& url = download_item->GetOriginalUrl(); | 254 const GURL& url = download_item->GetOriginalUrl(); |
255 json->SetString(kUrlKey, (url.is_valid() ? url.spec() : std::string())); | 255 json->SetString(kUrlKey, (url.is_valid() ? url.spec() : std::string())); |
256 const GURL& referrer = download_item->GetReferrerUrl(); | 256 const GURL& referrer = download_item->GetReferrerUrl(); |
257 json->SetString(kReferrerUrlKey, (referrer.is_valid() ? referrer.spec() | 257 json->SetString(kReferrerUrlKey, (referrer.is_valid() ? referrer.spec() |
258 : std::string())); | 258 : std::string())); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 // language. This won't work if the extension was uninstalled, so the name | 291 // language. This won't work if the extension was uninstalled, so the name |
292 // might be the wrong language. | 292 // might be the wrong language. |
293 const Extension* extension = | 293 const Extension* extension = |
294 ExtensionRegistry::Get(profile) | 294 ExtensionRegistry::Get(profile) |
295 ->GetExtensionById(by_ext->id(), ExtensionRegistry::EVERYTHING); | 295 ->GetExtensionById(by_ext->id(), ExtensionRegistry::EVERYTHING); |
296 if (extension) | 296 if (extension) |
297 json->SetString(kByExtensionNameKey, extension->name()); | 297 json->SetString(kByExtensionNameKey, extension->name()); |
298 } | 298 } |
299 // TODO(benjhayden): Implement fileSize. | 299 // TODO(benjhayden): Implement fileSize. |
300 json->SetDouble(kFileSizeKey, download_item->GetTotalBytes()); | 300 json->SetDouble(kFileSizeKey, download_item->GetTotalBytes()); |
301 return scoped_ptr<base::DictionaryValue>(json); | 301 return std::unique_ptr<base::DictionaryValue>(json); |
302 } | 302 } |
303 | 303 |
304 class DownloadFileIconExtractorImpl : public DownloadFileIconExtractor { | 304 class DownloadFileIconExtractorImpl : public DownloadFileIconExtractor { |
305 public: | 305 public: |
306 DownloadFileIconExtractorImpl() {} | 306 DownloadFileIconExtractorImpl() {} |
307 | 307 |
308 ~DownloadFileIconExtractorImpl() override {} | 308 ~DownloadFileIconExtractorImpl() override {} |
309 | 309 |
310 bool ExtractIconURLForPath(const base::FilePath& path, | 310 bool ExtractIconURLForPath(const base::FilePath& path, |
311 float scale, | 311 float scale, |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 return; | 533 return; |
534 } | 534 } |
535 query_out.AddFilter(danger_type); | 535 query_out.AddFilter(danger_type); |
536 } | 536 } |
537 if (query_in.order_by.get()) { | 537 if (query_in.order_by.get()) { |
538 CompileDownloadQueryOrderBy(*query_in.order_by.get(), error, &query_out); | 538 CompileDownloadQueryOrderBy(*query_in.order_by.get(), error, &query_out); |
539 if (!error->empty()) | 539 if (!error->empty()) |
540 return; | 540 return; |
541 } | 541 } |
542 | 542 |
543 scoped_ptr<base::DictionaryValue> query_in_value(query_in.ToValue()); | 543 std::unique_ptr<base::DictionaryValue> query_in_value(query_in.ToValue()); |
544 for (base::DictionaryValue::Iterator query_json_field(*query_in_value.get()); | 544 for (base::DictionaryValue::Iterator query_json_field(*query_in_value.get()); |
545 !query_json_field.IsAtEnd(); query_json_field.Advance()) { | 545 !query_json_field.IsAtEnd(); query_json_field.Advance()) { |
546 FilterTypeMap::const_iterator filter_type = | 546 FilterTypeMap::const_iterator filter_type = |
547 filter_types.Get().find(query_json_field.key()); | 547 filter_types.Get().find(query_json_field.key()); |
548 if (filter_type != filter_types.Get().end()) { | 548 if (filter_type != filter_types.Get().end()) { |
549 if (!query_out.AddFilter(filter_type->second, query_json_field.value())) { | 549 if (!query_out.AddFilter(filter_type->second, query_json_field.value())) { |
550 *error = errors::kInvalidFilter; | 550 *error = errors::kInvalidFilter; |
551 return; | 551 return; |
552 } | 552 } |
553 } | 553 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 return (data == NULL) ? NULL : | 591 return (data == NULL) ? NULL : |
592 static_cast<ExtensionDownloadsEventRouterData*>(data); | 592 static_cast<ExtensionDownloadsEventRouterData*>(data); |
593 } | 593 } |
594 | 594 |
595 static void Remove(DownloadItem* download_item) { | 595 static void Remove(DownloadItem* download_item) { |
596 download_item->RemoveUserData(kKey); | 596 download_item->RemoveUserData(kKey); |
597 } | 597 } |
598 | 598 |
599 explicit ExtensionDownloadsEventRouterData( | 599 explicit ExtensionDownloadsEventRouterData( |
600 DownloadItem* download_item, | 600 DownloadItem* download_item, |
601 scoped_ptr<base::DictionaryValue> json_item) | 601 std::unique_ptr<base::DictionaryValue> json_item) |
602 : updated_(0), | 602 : updated_(0), |
603 changed_fired_(0), | 603 changed_fired_(0), |
604 json_(std::move(json_item)), | 604 json_(std::move(json_item)), |
605 creator_conflict_action_(downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY), | 605 creator_conflict_action_(downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY), |
606 determined_conflict_action_( | 606 determined_conflict_action_( |
607 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY) { | 607 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY) { |
608 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 608 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
609 download_item->SetUserData(kKey, this); | 609 download_item->SetUserData(kKey, this); |
610 } | 610 } |
611 | 611 |
612 ~ExtensionDownloadsEventRouterData() override { | 612 ~ExtensionDownloadsEventRouterData() override { |
613 if (updated_ > 0) { | 613 if (updated_ > 0) { |
614 UMA_HISTOGRAM_PERCENTAGE("Download.OnChanged", | 614 UMA_HISTOGRAM_PERCENTAGE("Download.OnChanged", |
615 (changed_fired_ * 100 / updated_)); | 615 (changed_fired_ * 100 / updated_)); |
616 } | 616 } |
617 } | 617 } |
618 | 618 |
619 const base::DictionaryValue& json() const { return *json_.get(); } | 619 const base::DictionaryValue& json() const { return *json_.get(); } |
620 void set_json(scoped_ptr<base::DictionaryValue> json_item) { | 620 void set_json(std::unique_ptr<base::DictionaryValue> json_item) { |
621 json_ = std::move(json_item); | 621 json_ = std::move(json_item); |
622 } | 622 } |
623 | 623 |
624 void OnItemUpdated() { ++updated_; } | 624 void OnItemUpdated() { ++updated_; } |
625 void OnChangedFired() { ++changed_fired_; } | 625 void OnChangedFired() { ++changed_fired_; } |
626 | 626 |
627 static void SetDetermineFilenameTimeoutSecondsForTesting(int s) { | 627 static void SetDetermineFilenameTimeoutSecondsForTesting(int s) { |
628 determine_filename_timeout_s_ = s; | 628 determine_filename_timeout_s_ = s; |
629 } | 629 } |
630 | 630 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 } | 829 } |
830 } | 830 } |
831 // Clear the callbacks immediately in case they aren't idempotent. | 831 // Clear the callbacks immediately in case they aren't idempotent. |
832 filename_no_change_ = base::Closure(); | 832 filename_no_change_ = base::Closure(); |
833 filename_change_ = ExtensionDownloadsEventRouter::FilenameChangedCallback(); | 833 filename_change_ = ExtensionDownloadsEventRouter::FilenameChangedCallback(); |
834 } | 834 } |
835 | 835 |
836 | 836 |
837 int updated_; | 837 int updated_; |
838 int changed_fired_; | 838 int changed_fired_; |
839 scoped_ptr<base::DictionaryValue> json_; | 839 std::unique_ptr<base::DictionaryValue> json_; |
840 | 840 |
841 base::Closure filename_no_change_; | 841 base::Closure filename_no_change_; |
842 ExtensionDownloadsEventRouter::FilenameChangedCallback filename_change_; | 842 ExtensionDownloadsEventRouter::FilenameChangedCallback filename_change_; |
843 | 843 |
844 DeterminerInfoVector determiners_; | 844 DeterminerInfoVector determiners_; |
845 | 845 |
846 base::FilePath creator_suggested_filename_; | 846 base::FilePath creator_suggested_filename_; |
847 downloads::FilenameConflictAction | 847 downloads::FilenameConflictAction |
848 creator_conflict_action_; | 848 creator_conflict_action_; |
849 base::FilePath determined_filename_; | 849 base::FilePath determined_filename_; |
850 downloads::FilenameConflictAction | 850 downloads::FilenameConflictAction |
851 determined_conflict_action_; | 851 determined_conflict_action_; |
852 DeterminerInfo determiner_; | 852 DeterminerInfo determiner_; |
853 | 853 |
854 scoped_ptr<base::WeakPtrFactory<ExtensionDownloadsEventRouterData> > | 854 std::unique_ptr<base::WeakPtrFactory<ExtensionDownloadsEventRouterData>> |
855 weak_ptr_factory_; | 855 weak_ptr_factory_; |
856 | 856 |
857 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouterData); | 857 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouterData); |
858 }; | 858 }; |
859 | 859 |
860 int ExtensionDownloadsEventRouterData::determine_filename_timeout_s_ = 15; | 860 int ExtensionDownloadsEventRouterData::determine_filename_timeout_s_ = 15; |
861 | 861 |
862 ExtensionDownloadsEventRouterData::DeterminerInfo::DeterminerInfo( | 862 ExtensionDownloadsEventRouterData::DeterminerInfo::DeterminerInfo( |
863 const std::string& e_id, | 863 const std::string& e_id, |
864 const base::Time& installed) | 864 const base::Time& installed) |
865 : extension_id(e_id), | 865 : extension_id(e_id), |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 : id_(id), | 938 : id_(id), |
939 name_(name) { | 939 name_(name) { |
940 item->SetUserData(kKey, this); | 940 item->SetUserData(kKey, this); |
941 } | 941 } |
942 | 942 |
943 DownloadsDownloadFunction::DownloadsDownloadFunction() {} | 943 DownloadsDownloadFunction::DownloadsDownloadFunction() {} |
944 | 944 |
945 DownloadsDownloadFunction::~DownloadsDownloadFunction() {} | 945 DownloadsDownloadFunction::~DownloadsDownloadFunction() {} |
946 | 946 |
947 bool DownloadsDownloadFunction::RunAsync() { | 947 bool DownloadsDownloadFunction::RunAsync() { |
948 scoped_ptr<downloads::Download::Params> params( | 948 std::unique_ptr<downloads::Download::Params> params( |
949 downloads::Download::Params::Create(*args_)); | 949 downloads::Download::Params::Create(*args_)); |
950 EXTENSION_FUNCTION_VALIDATE(params.get()); | 950 EXTENSION_FUNCTION_VALIDATE(params.get()); |
951 const downloads::DownloadOptions& options = params->options; | 951 const downloads::DownloadOptions& options = params->options; |
952 GURL download_url(options.url); | 952 GURL download_url(options.url); |
953 if (Fault(!download_url.is_valid(), errors::kInvalidURL, &error_)) | 953 if (Fault(!download_url.is_valid(), errors::kInvalidURL, &error_)) |
954 return false; | 954 return false; |
955 | 955 |
956 Profile* current_profile = GetProfile(); | 956 Profile* current_profile = GetProfile(); |
957 if (include_incognito() && GetProfile()->HasOffTheRecordProfile()) | 957 if (include_incognito() && GetProfile()->HasOffTheRecordProfile()) |
958 current_profile = GetProfile()->GetOffTheRecordProfile(); | 958 current_profile = GetProfile()->GetOffTheRecordProfile(); |
959 | 959 |
960 scoped_ptr<content::DownloadUrlParameters> download_params( | 960 std::unique_ptr<content::DownloadUrlParameters> download_params( |
961 new content::DownloadUrlParameters( | 961 new content::DownloadUrlParameters( |
962 download_url, render_frame_host()->GetProcess()->GetID(), | 962 download_url, render_frame_host()->GetProcess()->GetID(), |
963 render_view_host_do_not_use()->GetRoutingID(), | 963 render_view_host_do_not_use()->GetRoutingID(), |
964 render_frame_host()->GetRoutingID(), | 964 render_frame_host()->GetRoutingID(), |
965 current_profile->GetResourceContext())); | 965 current_profile->GetResourceContext())); |
966 | 966 |
967 base::FilePath creator_suggested_filename; | 967 base::FilePath creator_suggested_filename; |
968 if (options.filename.get()) { | 968 if (options.filename.get()) { |
969 #if defined(OS_WIN) | 969 #if defined(OS_WIN) |
970 // Can't get filename16 from options.ToValue() because that converts it from | 970 // Can't get filename16 from options.ToValue() because that converts it from |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 if (item) { | 1035 if (item) { |
1036 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 1036 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
1037 SetResult(new base::FundamentalValue(static_cast<int>(item->GetId()))); | 1037 SetResult(new base::FundamentalValue(static_cast<int>(item->GetId()))); |
1038 if (!creator_suggested_filename.empty() || | 1038 if (!creator_suggested_filename.empty() || |
1039 (creator_conflict_action != | 1039 (creator_conflict_action != |
1040 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)) { | 1040 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)) { |
1041 ExtensionDownloadsEventRouterData* data = | 1041 ExtensionDownloadsEventRouterData* data = |
1042 ExtensionDownloadsEventRouterData::Get(item); | 1042 ExtensionDownloadsEventRouterData::Get(item); |
1043 if (!data) { | 1043 if (!data) { |
1044 data = new ExtensionDownloadsEventRouterData( | 1044 data = new ExtensionDownloadsEventRouterData( |
1045 item, | 1045 item, std::unique_ptr<base::DictionaryValue>( |
1046 scoped_ptr<base::DictionaryValue>(new base::DictionaryValue())); | 1046 new base::DictionaryValue())); |
1047 } | 1047 } |
1048 data->CreatorSuggestedFilename( | 1048 data->CreatorSuggestedFilename( |
1049 creator_suggested_filename, creator_conflict_action); | 1049 creator_suggested_filename, creator_conflict_action); |
1050 } | 1050 } |
1051 new DownloadedByExtension(item, extension()->id(), extension()->name()); | 1051 new DownloadedByExtension(item, extension()->id(), extension()->name()); |
1052 item->UpdateObservers(); | 1052 item->UpdateObservers(); |
1053 } else { | 1053 } else { |
1054 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 1054 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
1055 error_ = content::DownloadInterruptReasonToString(interrupt_reason); | 1055 error_ = content::DownloadInterruptReasonToString(interrupt_reason); |
1056 } | 1056 } |
1057 SendResponse(error_.empty()); | 1057 SendResponse(error_.empty()); |
1058 } | 1058 } |
1059 | 1059 |
1060 DownloadsSearchFunction::DownloadsSearchFunction() {} | 1060 DownloadsSearchFunction::DownloadsSearchFunction() {} |
1061 | 1061 |
1062 DownloadsSearchFunction::~DownloadsSearchFunction() {} | 1062 DownloadsSearchFunction::~DownloadsSearchFunction() {} |
1063 | 1063 |
1064 bool DownloadsSearchFunction::RunSync() { | 1064 bool DownloadsSearchFunction::RunSync() { |
1065 scoped_ptr<downloads::Search::Params> params( | 1065 std::unique_ptr<downloads::Search::Params> params( |
1066 downloads::Search::Params::Create(*args_)); | 1066 downloads::Search::Params::Create(*args_)); |
1067 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1067 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1068 DownloadManager* manager = NULL; | 1068 DownloadManager* manager = NULL; |
1069 DownloadManager* incognito_manager = NULL; | 1069 DownloadManager* incognito_manager = NULL; |
1070 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); | 1070 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); |
1071 ExtensionDownloadsEventRouter* router = | 1071 ExtensionDownloadsEventRouter* router = |
1072 DownloadServiceFactory::GetForBrowserContext( | 1072 DownloadServiceFactory::GetForBrowserContext( |
1073 manager->GetBrowserContext())->GetExtensionEventRouter(); | 1073 manager->GetBrowserContext())->GetExtensionEventRouter(); |
1074 router->CheckForHistoryFilesRemoval(); | 1074 router->CheckForHistoryFilesRemoval(); |
1075 if (incognito_manager) { | 1075 if (incognito_manager) { |
(...skipping 11 matching lines...) Expand all Loading... |
1087 if (!error_.empty()) | 1087 if (!error_.empty()) |
1088 return false; | 1088 return false; |
1089 | 1089 |
1090 base::ListValue* json_results = new base::ListValue(); | 1090 base::ListValue* json_results = new base::ListValue(); |
1091 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); | 1091 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); |
1092 it != results.end(); ++it) { | 1092 it != results.end(); ++it) { |
1093 DownloadItem* download_item = *it; | 1093 DownloadItem* download_item = *it; |
1094 uint32_t download_id = download_item->GetId(); | 1094 uint32_t download_id = download_item->GetId(); |
1095 bool off_record = ((incognito_manager != NULL) && | 1095 bool off_record = ((incognito_manager != NULL) && |
1096 (incognito_manager->GetDownload(download_id) != NULL)); | 1096 (incognito_manager->GetDownload(download_id) != NULL)); |
1097 scoped_ptr<base::DictionaryValue> json_item( | 1097 std::unique_ptr<base::DictionaryValue> json_item(DownloadItemToJSON( |
1098 DownloadItemToJSON(*it, | 1098 *it, off_record ? GetProfile()->GetOffTheRecordProfile() |
1099 off_record ? GetProfile()->GetOffTheRecordProfile() | 1099 : GetProfile()->GetOriginalProfile())); |
1100 : GetProfile()->GetOriginalProfile())); | |
1101 json_results->Append(json_item.release()); | 1100 json_results->Append(json_item.release()); |
1102 } | 1101 } |
1103 SetResult(json_results); | 1102 SetResult(json_results); |
1104 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); | 1103 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); |
1105 return true; | 1104 return true; |
1106 } | 1105 } |
1107 | 1106 |
1108 DownloadsPauseFunction::DownloadsPauseFunction() {} | 1107 DownloadsPauseFunction::DownloadsPauseFunction() {} |
1109 | 1108 |
1110 DownloadsPauseFunction::~DownloadsPauseFunction() {} | 1109 DownloadsPauseFunction::~DownloadsPauseFunction() {} |
1111 | 1110 |
1112 bool DownloadsPauseFunction::RunSync() { | 1111 bool DownloadsPauseFunction::RunSync() { |
1113 scoped_ptr<downloads::Pause::Params> params( | 1112 std::unique_ptr<downloads::Pause::Params> params( |
1114 downloads::Pause::Params::Create(*args_)); | 1113 downloads::Pause::Params::Create(*args_)); |
1115 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1114 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1116 DownloadItem* download_item = | 1115 DownloadItem* download_item = |
1117 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1116 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1118 if (InvalidId(download_item, &error_) || | 1117 if (InvalidId(download_item, &error_) || |
1119 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, | 1118 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, |
1120 errors::kNotInProgress, &error_)) | 1119 errors::kNotInProgress, &error_)) |
1121 return false; | 1120 return false; |
1122 // If the item is already paused, this is a no-op and the operation will | 1121 // If the item is already paused, this is a no-op and the operation will |
1123 // silently succeed. | 1122 // silently succeed. |
1124 download_item->Pause(); | 1123 download_item->Pause(); |
1125 RecordApiFunctions(DOWNLOADS_FUNCTION_PAUSE); | 1124 RecordApiFunctions(DOWNLOADS_FUNCTION_PAUSE); |
1126 return true; | 1125 return true; |
1127 } | 1126 } |
1128 | 1127 |
1129 DownloadsResumeFunction::DownloadsResumeFunction() {} | 1128 DownloadsResumeFunction::DownloadsResumeFunction() {} |
1130 | 1129 |
1131 DownloadsResumeFunction::~DownloadsResumeFunction() {} | 1130 DownloadsResumeFunction::~DownloadsResumeFunction() {} |
1132 | 1131 |
1133 bool DownloadsResumeFunction::RunSync() { | 1132 bool DownloadsResumeFunction::RunSync() { |
1134 scoped_ptr<downloads::Resume::Params> params( | 1133 std::unique_ptr<downloads::Resume::Params> params( |
1135 downloads::Resume::Params::Create(*args_)); | 1134 downloads::Resume::Params::Create(*args_)); |
1136 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1135 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1137 DownloadItem* download_item = | 1136 DownloadItem* download_item = |
1138 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1137 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1139 if (InvalidId(download_item, &error_) || | 1138 if (InvalidId(download_item, &error_) || |
1140 Fault(download_item->IsPaused() && !download_item->CanResume(), | 1139 Fault(download_item->IsPaused() && !download_item->CanResume(), |
1141 errors::kNotResumable, &error_)) | 1140 errors::kNotResumable, &error_)) |
1142 return false; | 1141 return false; |
1143 // Note that if the item isn't paused, this will be a no-op, and the extension | 1142 // Note that if the item isn't paused, this will be a no-op, and the extension |
1144 // call will seem successful. | 1143 // call will seem successful. |
1145 download_item->Resume(); | 1144 download_item->Resume(); |
1146 RecordApiFunctions(DOWNLOADS_FUNCTION_RESUME); | 1145 RecordApiFunctions(DOWNLOADS_FUNCTION_RESUME); |
1147 return true; | 1146 return true; |
1148 } | 1147 } |
1149 | 1148 |
1150 DownloadsCancelFunction::DownloadsCancelFunction() {} | 1149 DownloadsCancelFunction::DownloadsCancelFunction() {} |
1151 | 1150 |
1152 DownloadsCancelFunction::~DownloadsCancelFunction() {} | 1151 DownloadsCancelFunction::~DownloadsCancelFunction() {} |
1153 | 1152 |
1154 bool DownloadsCancelFunction::RunSync() { | 1153 bool DownloadsCancelFunction::RunSync() { |
1155 scoped_ptr<downloads::Resume::Params> params( | 1154 std::unique_ptr<downloads::Resume::Params> params( |
1156 downloads::Resume::Params::Create(*args_)); | 1155 downloads::Resume::Params::Create(*args_)); |
1157 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1156 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1158 DownloadItem* download_item = | 1157 DownloadItem* download_item = |
1159 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1158 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1160 if (download_item && | 1159 if (download_item && |
1161 (download_item->GetState() == DownloadItem::IN_PROGRESS)) | 1160 (download_item->GetState() == DownloadItem::IN_PROGRESS)) |
1162 download_item->Cancel(true); | 1161 download_item->Cancel(true); |
1163 // |download_item| can be NULL if the download ID was invalid or if the | 1162 // |download_item| can be NULL if the download ID was invalid or if the |
1164 // download is not currently active. Either way, it's not a failure. | 1163 // download is not currently active. Either way, it's not a failure. |
1165 RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL); | 1164 RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL); |
1166 return true; | 1165 return true; |
1167 } | 1166 } |
1168 | 1167 |
1169 DownloadsEraseFunction::DownloadsEraseFunction() {} | 1168 DownloadsEraseFunction::DownloadsEraseFunction() {} |
1170 | 1169 |
1171 DownloadsEraseFunction::~DownloadsEraseFunction() {} | 1170 DownloadsEraseFunction::~DownloadsEraseFunction() {} |
1172 | 1171 |
1173 bool DownloadsEraseFunction::RunSync() { | 1172 bool DownloadsEraseFunction::RunSync() { |
1174 scoped_ptr<downloads::Erase::Params> params( | 1173 std::unique_ptr<downloads::Erase::Params> params( |
1175 downloads::Erase::Params::Create(*args_)); | 1174 downloads::Erase::Params::Create(*args_)); |
1176 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1175 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1177 DownloadManager* manager = NULL; | 1176 DownloadManager* manager = NULL; |
1178 DownloadManager* incognito_manager = NULL; | 1177 DownloadManager* incognito_manager = NULL; |
1179 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); | 1178 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); |
1180 DownloadQuery::DownloadVector results; | 1179 DownloadQuery::DownloadVector results; |
1181 RunDownloadQuery(params->query, | 1180 RunDownloadQuery(params->query, |
1182 manager, | 1181 manager, |
1183 incognito_manager, | 1182 incognito_manager, |
1184 &error_, | 1183 &error_, |
(...skipping 12 matching lines...) Expand all Loading... |
1197 return true; | 1196 return true; |
1198 } | 1197 } |
1199 | 1198 |
1200 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() { | 1199 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() { |
1201 } | 1200 } |
1202 | 1201 |
1203 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { | 1202 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { |
1204 } | 1203 } |
1205 | 1204 |
1206 bool DownloadsRemoveFileFunction::RunAsync() { | 1205 bool DownloadsRemoveFileFunction::RunAsync() { |
1207 scoped_ptr<downloads::RemoveFile::Params> params( | 1206 std::unique_ptr<downloads::RemoveFile::Params> params( |
1208 downloads::RemoveFile::Params::Create(*args_)); | 1207 downloads::RemoveFile::Params::Create(*args_)); |
1209 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1208 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1210 DownloadItem* download_item = | 1209 DownloadItem* download_item = |
1211 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1210 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1212 if (InvalidId(download_item, &error_) || | 1211 if (InvalidId(download_item, &error_) || |
1213 Fault((download_item->GetState() != DownloadItem::COMPLETE), | 1212 Fault((download_item->GetState() != DownloadItem::COMPLETE), |
1214 errors::kNotComplete, &error_) || | 1213 errors::kNotComplete, &error_) || |
1215 Fault(download_item->GetFileExternallyRemoved(), | 1214 Fault(download_item->GetFileExternallyRemoved(), |
1216 errors::kFileAlreadyDeleted, &error_)) | 1215 errors::kFileAlreadyDeleted, &error_)) |
1217 return false; | 1216 return false; |
(...skipping 12 matching lines...) Expand all Loading... |
1230 } | 1229 } |
1231 | 1230 |
1232 DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {} | 1231 DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {} |
1233 | 1232 |
1234 DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {} | 1233 DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {} |
1235 | 1234 |
1236 DownloadsAcceptDangerFunction::OnPromptCreatedCallback* | 1235 DownloadsAcceptDangerFunction::OnPromptCreatedCallback* |
1237 DownloadsAcceptDangerFunction::on_prompt_created_ = NULL; | 1236 DownloadsAcceptDangerFunction::on_prompt_created_ = NULL; |
1238 | 1237 |
1239 bool DownloadsAcceptDangerFunction::RunAsync() { | 1238 bool DownloadsAcceptDangerFunction::RunAsync() { |
1240 scoped_ptr<downloads::AcceptDanger::Params> params( | 1239 std::unique_ptr<downloads::AcceptDanger::Params> params( |
1241 downloads::AcceptDanger::Params::Create(*args_)); | 1240 downloads::AcceptDanger::Params::Create(*args_)); |
1242 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1241 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1243 PromptOrWait(params->download_id, 10); | 1242 PromptOrWait(params->download_id, 10); |
1244 return true; | 1243 return true; |
1245 } | 1244 } |
1246 | 1245 |
1247 void DownloadsAcceptDangerFunction::PromptOrWait(int download_id, int retries) { | 1246 void DownloadsAcceptDangerFunction::PromptOrWait(int download_id, int retries) { |
1248 DownloadItem* download_item = | 1247 DownloadItem* download_item = |
1249 GetDownload(GetProfile(), include_incognito(), download_id); | 1248 GetDownload(GetProfile(), include_incognito(), download_id); |
1250 content::WebContents* web_contents = dispatcher()->GetVisibleWebContents(); | 1249 content::WebContents* web_contents = dispatcher()->GetVisibleWebContents(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 break; | 1303 break; |
1305 } | 1304 } |
1306 SendResponse(error_.empty()); | 1305 SendResponse(error_.empty()); |
1307 } | 1306 } |
1308 | 1307 |
1309 DownloadsShowFunction::DownloadsShowFunction() {} | 1308 DownloadsShowFunction::DownloadsShowFunction() {} |
1310 | 1309 |
1311 DownloadsShowFunction::~DownloadsShowFunction() {} | 1310 DownloadsShowFunction::~DownloadsShowFunction() {} |
1312 | 1311 |
1313 bool DownloadsShowFunction::RunAsync() { | 1312 bool DownloadsShowFunction::RunAsync() { |
1314 scoped_ptr<downloads::Show::Params> params( | 1313 std::unique_ptr<downloads::Show::Params> params( |
1315 downloads::Show::Params::Create(*args_)); | 1314 downloads::Show::Params::Create(*args_)); |
1316 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1315 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1317 DownloadItem* download_item = | 1316 DownloadItem* download_item = |
1318 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1317 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1319 if (InvalidId(download_item, &error_)) | 1318 if (InvalidId(download_item, &error_)) |
1320 return false; | 1319 return false; |
1321 download_item->ShowDownloadInShell(); | 1320 download_item->ShowDownloadInShell(); |
1322 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW); | 1321 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW); |
1323 return true; | 1322 return true; |
1324 } | 1323 } |
(...skipping 11 matching lines...) Expand all Loading... |
1336 platform_util::OPEN_FOLDER, platform_util::OpenOperationCallback()); | 1335 platform_util::OPEN_FOLDER, platform_util::OpenOperationCallback()); |
1337 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER); | 1336 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER); |
1338 return true; | 1337 return true; |
1339 } | 1338 } |
1340 | 1339 |
1341 DownloadsOpenFunction::DownloadsOpenFunction() {} | 1340 DownloadsOpenFunction::DownloadsOpenFunction() {} |
1342 | 1341 |
1343 DownloadsOpenFunction::~DownloadsOpenFunction() {} | 1342 DownloadsOpenFunction::~DownloadsOpenFunction() {} |
1344 | 1343 |
1345 bool DownloadsOpenFunction::RunSync() { | 1344 bool DownloadsOpenFunction::RunSync() { |
1346 scoped_ptr<downloads::Open::Params> params( | 1345 std::unique_ptr<downloads::Open::Params> params( |
1347 downloads::Open::Params::Create(*args_)); | 1346 downloads::Open::Params::Create(*args_)); |
1348 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1347 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1349 DownloadItem* download_item = | 1348 DownloadItem* download_item = |
1350 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1349 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1351 if (InvalidId(download_item, &error_) || | 1350 if (InvalidId(download_item, &error_) || |
1352 Fault(!user_gesture(), errors::kUserGesture, &error_) || | 1351 Fault(!user_gesture(), errors::kUserGesture, &error_) || |
1353 Fault(download_item->GetState() != DownloadItem::COMPLETE, | 1352 Fault(download_item->GetState() != DownloadItem::COMPLETE, |
1354 errors::kNotComplete, | 1353 errors::kNotComplete, |
1355 &error_) || | 1354 &error_) || |
1356 Fault(!extension()->permissions_data()->HasAPIPermission( | 1355 Fault(!extension()->permissions_data()->HasAPIPermission( |
1357 APIPermission::kDownloadsOpen), | 1356 APIPermission::kDownloadsOpen), |
1358 errors::kOpenPermission, | 1357 errors::kOpenPermission, |
1359 &error_)) | 1358 &error_)) |
1360 return false; | 1359 return false; |
1361 download_item->OpenDownload(); | 1360 download_item->OpenDownload(); |
1362 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); | 1361 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); |
1363 return true; | 1362 return true; |
1364 } | 1363 } |
1365 | 1364 |
1366 DownloadsDragFunction::DownloadsDragFunction() {} | 1365 DownloadsDragFunction::DownloadsDragFunction() {} |
1367 | 1366 |
1368 DownloadsDragFunction::~DownloadsDragFunction() {} | 1367 DownloadsDragFunction::~DownloadsDragFunction() {} |
1369 | 1368 |
1370 bool DownloadsDragFunction::RunAsync() { | 1369 bool DownloadsDragFunction::RunAsync() { |
1371 scoped_ptr<downloads::Drag::Params> params( | 1370 std::unique_ptr<downloads::Drag::Params> params( |
1372 downloads::Drag::Params::Create(*args_)); | 1371 downloads::Drag::Params::Create(*args_)); |
1373 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1372 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1374 DownloadItem* download_item = | 1373 DownloadItem* download_item = |
1375 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1374 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1376 content::WebContents* web_contents = | 1375 content::WebContents* web_contents = |
1377 dispatcher()->GetVisibleWebContents(); | 1376 dispatcher()->GetVisibleWebContents(); |
1378 if (InvalidId(download_item, &error_) || | 1377 if (InvalidId(download_item, &error_) || |
1379 Fault(!web_contents, errors::kInvisibleContext, &error_)) | 1378 Fault(!web_contents, errors::kInvisibleContext, &error_)) |
1380 return false; | 1379 return false; |
1381 RecordApiFunctions(DOWNLOADS_FUNCTION_DRAG); | 1380 RecordApiFunctions(DOWNLOADS_FUNCTION_DRAG); |
1382 gfx::Image* icon = g_browser_process->icon_manager()->LookupIconFromFilepath( | 1381 gfx::Image* icon = g_browser_process->icon_manager()->LookupIconFromFilepath( |
1383 download_item->GetTargetFilePath(), IconLoader::NORMAL); | 1382 download_item->GetTargetFilePath(), IconLoader::NORMAL); |
1384 gfx::NativeView view = web_contents->GetNativeView(); | 1383 gfx::NativeView view = web_contents->GetNativeView(); |
1385 { | 1384 { |
1386 // Enable nested tasks during DnD, while |DragDownload()| blocks. | 1385 // Enable nested tasks during DnD, while |DragDownload()| blocks. |
1387 base::MessageLoop::ScopedNestableTaskAllower allow( | 1386 base::MessageLoop::ScopedNestableTaskAllower allow( |
1388 base::MessageLoop::current()); | 1387 base::MessageLoop::current()); |
1389 DragDownloadItem(download_item, icon, view); | 1388 DragDownloadItem(download_item, icon, view); |
1390 } | 1389 } |
1391 return true; | 1390 return true; |
1392 } | 1391 } |
1393 | 1392 |
1394 DownloadsSetShelfEnabledFunction::DownloadsSetShelfEnabledFunction() {} | 1393 DownloadsSetShelfEnabledFunction::DownloadsSetShelfEnabledFunction() {} |
1395 | 1394 |
1396 DownloadsSetShelfEnabledFunction::~DownloadsSetShelfEnabledFunction() {} | 1395 DownloadsSetShelfEnabledFunction::~DownloadsSetShelfEnabledFunction() {} |
1397 | 1396 |
1398 bool DownloadsSetShelfEnabledFunction::RunSync() { | 1397 bool DownloadsSetShelfEnabledFunction::RunSync() { |
1399 scoped_ptr<downloads::SetShelfEnabled::Params> params( | 1398 std::unique_ptr<downloads::SetShelfEnabled::Params> params( |
1400 downloads::SetShelfEnabled::Params::Create(*args_)); | 1399 downloads::SetShelfEnabled::Params::Create(*args_)); |
1401 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1400 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1402 if (!extension()->permissions_data()->HasAPIPermission( | 1401 if (!extension()->permissions_data()->HasAPIPermission( |
1403 APIPermission::kDownloadsShelf)) { | 1402 APIPermission::kDownloadsShelf)) { |
1404 error_ = download_extension_errors::kShelfPermission; | 1403 error_ = download_extension_errors::kShelfPermission; |
1405 return false; | 1404 return false; |
1406 } | 1405 } |
1407 | 1406 |
1408 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); | 1407 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); |
1409 DownloadManager* manager = NULL; | 1408 DownloadManager* manager = NULL; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 | 1454 |
1456 DownloadsGetFileIconFunction::~DownloadsGetFileIconFunction() {} | 1455 DownloadsGetFileIconFunction::~DownloadsGetFileIconFunction() {} |
1457 | 1456 |
1458 void DownloadsGetFileIconFunction::SetIconExtractorForTesting( | 1457 void DownloadsGetFileIconFunction::SetIconExtractorForTesting( |
1459 DownloadFileIconExtractor* extractor) { | 1458 DownloadFileIconExtractor* extractor) { |
1460 DCHECK(extractor); | 1459 DCHECK(extractor); |
1461 icon_extractor_.reset(extractor); | 1460 icon_extractor_.reset(extractor); |
1462 } | 1461 } |
1463 | 1462 |
1464 bool DownloadsGetFileIconFunction::RunAsync() { | 1463 bool DownloadsGetFileIconFunction::RunAsync() { |
1465 scoped_ptr<downloads::GetFileIcon::Params> params( | 1464 std::unique_ptr<downloads::GetFileIcon::Params> params( |
1466 downloads::GetFileIcon::Params::Create(*args_)); | 1465 downloads::GetFileIcon::Params::Create(*args_)); |
1467 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1466 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1468 const downloads::GetFileIconOptions* options = | 1467 const downloads::GetFileIconOptions* options = |
1469 params->options.get(); | 1468 params->options.get(); |
1470 int icon_size = kDefaultIconSize; | 1469 int icon_size = kDefaultIconSize; |
1471 if (options && options->size.get()) | 1470 if (options && options->size.get()) |
1472 icon_size = *options->size.get(); | 1471 icon_size = *options->size.get(); |
1473 DownloadItem* download_item = | 1472 DownloadItem* download_item = |
1474 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1473 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1475 if (InvalidId(download_item, &error_) || | 1474 if (InvalidId(download_item, &error_) || |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1747 EventRouter* router = EventRouter::Get(profile_); | 1746 EventRouter* router = EventRouter::Get(profile_); |
1748 // Avoid allocating a bunch of memory in DownloadItemToJSON if it isn't going | 1747 // Avoid allocating a bunch of memory in DownloadItemToJSON if it isn't going |
1749 // to be used. | 1748 // to be used. |
1750 if (!router || | 1749 if (!router || |
1751 (!router->HasEventListener(downloads::OnCreated::kEventName) && | 1750 (!router->HasEventListener(downloads::OnCreated::kEventName) && |
1752 !router->HasEventListener(downloads::OnChanged::kEventName) && | 1751 !router->HasEventListener(downloads::OnChanged::kEventName) && |
1753 !router->HasEventListener( | 1752 !router->HasEventListener( |
1754 downloads::OnDeterminingFilename::kEventName))) { | 1753 downloads::OnDeterminingFilename::kEventName))) { |
1755 return; | 1754 return; |
1756 } | 1755 } |
1757 scoped_ptr<base::DictionaryValue> json_item( | 1756 std::unique_ptr<base::DictionaryValue> json_item( |
1758 DownloadItemToJSON(download_item, profile_)); | 1757 DownloadItemToJSON(download_item, profile_)); |
1759 DispatchEvent(events::DOWNLOADS_ON_CREATED, downloads::OnCreated::kEventName, | 1758 DispatchEvent(events::DOWNLOADS_ON_CREATED, downloads::OnCreated::kEventName, |
1760 true, Event::WillDispatchCallback(), json_item->DeepCopy()); | 1759 true, Event::WillDispatchCallback(), json_item->DeepCopy()); |
1761 if (!ExtensionDownloadsEventRouterData::Get(download_item) && | 1760 if (!ExtensionDownloadsEventRouterData::Get(download_item) && |
1762 (router->HasEventListener(downloads::OnChanged::kEventName) || | 1761 (router->HasEventListener(downloads::OnChanged::kEventName) || |
1763 router->HasEventListener( | 1762 router->HasEventListener( |
1764 downloads::OnDeterminingFilename::kEventName))) { | 1763 downloads::OnDeterminingFilename::kEventName))) { |
1765 new ExtensionDownloadsEventRouterData(download_item, std::move(json_item)); | 1764 new ExtensionDownloadsEventRouterData(download_item, std::move(json_item)); |
1766 } | 1765 } |
1767 } | 1766 } |
1768 | 1767 |
1769 void ExtensionDownloadsEventRouter::OnDownloadUpdated( | 1768 void ExtensionDownloadsEventRouter::OnDownloadUpdated( |
1770 DownloadManager* manager, DownloadItem* download_item) { | 1769 DownloadManager* manager, DownloadItem* download_item) { |
1771 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1770 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1772 EventRouter* router = EventRouter::Get(profile_); | 1771 EventRouter* router = EventRouter::Get(profile_); |
1773 ExtensionDownloadsEventRouterData* data = | 1772 ExtensionDownloadsEventRouterData* data = |
1774 ExtensionDownloadsEventRouterData::Get(download_item); | 1773 ExtensionDownloadsEventRouterData::Get(download_item); |
1775 if (download_item->IsTemporary() || | 1774 if (download_item->IsTemporary() || |
1776 !router->HasEventListener(downloads::OnChanged::kEventName)) { | 1775 !router->HasEventListener(downloads::OnChanged::kEventName)) { |
1777 return; | 1776 return; |
1778 } | 1777 } |
1779 if (!data) { | 1778 if (!data) { |
1780 // The download_item probably transitioned from temporary to not temporary, | 1779 // The download_item probably transitioned from temporary to not temporary, |
1781 // or else an event listener was added. | 1780 // or else an event listener was added. |
1782 data = new ExtensionDownloadsEventRouterData( | 1781 data = new ExtensionDownloadsEventRouterData( |
1783 download_item, | 1782 download_item, |
1784 scoped_ptr<base::DictionaryValue>(new base::DictionaryValue())); | 1783 std::unique_ptr<base::DictionaryValue>(new base::DictionaryValue())); |
1785 } | 1784 } |
1786 scoped_ptr<base::DictionaryValue> new_json(DownloadItemToJSON( | 1785 std::unique_ptr<base::DictionaryValue> new_json( |
1787 download_item, profile_)); | 1786 DownloadItemToJSON(download_item, profile_)); |
1788 scoped_ptr<base::DictionaryValue> delta(new base::DictionaryValue()); | 1787 std::unique_ptr<base::DictionaryValue> delta(new base::DictionaryValue()); |
1789 delta->SetInteger(kIdKey, download_item->GetId()); | 1788 delta->SetInteger(kIdKey, download_item->GetId()); |
1790 std::set<std::string> new_fields; | 1789 std::set<std::string> new_fields; |
1791 bool changed = false; | 1790 bool changed = false; |
1792 | 1791 |
1793 // For each field in the new json representation of the download_item except | 1792 // For each field in the new json representation of the download_item except |
1794 // the bytesReceived field, if the field has changed from the previous old | 1793 // the bytesReceived field, if the field has changed from the previous old |
1795 // json, set the differences in the |delta| object and remember that something | 1794 // json, set the differences in the |delta| object and remember that something |
1796 // significant changed. | 1795 // significant changed. |
1797 for (base::DictionaryValue::Iterator iter(*new_json.get()); | 1796 for (base::DictionaryValue::Iterator iter(*new_json.get()); |
1798 !iter.IsAtEnd(); iter.Advance()) { | 1797 !iter.IsAtEnd(); iter.Advance()) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 | 1846 |
1848 void ExtensionDownloadsEventRouter::DispatchEvent( | 1847 void ExtensionDownloadsEventRouter::DispatchEvent( |
1849 events::HistogramValue histogram_value, | 1848 events::HistogramValue histogram_value, |
1850 const std::string& event_name, | 1849 const std::string& event_name, |
1851 bool include_incognito, | 1850 bool include_incognito, |
1852 const Event::WillDispatchCallback& will_dispatch_callback, | 1851 const Event::WillDispatchCallback& will_dispatch_callback, |
1853 base::Value* arg) { | 1852 base::Value* arg) { |
1854 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1853 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1855 if (!EventRouter::Get(profile_)) | 1854 if (!EventRouter::Get(profile_)) |
1856 return; | 1855 return; |
1857 scoped_ptr<base::ListValue> args(new base::ListValue()); | 1856 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
1858 args->Append(arg); | 1857 args->Append(arg); |
1859 std::string json_args; | 1858 std::string json_args; |
1860 base::JSONWriter::Write(*args, &json_args); | 1859 base::JSONWriter::Write(*args, &json_args); |
1861 scoped_ptr<Event> event( | 1860 std::unique_ptr<Event> event( |
1862 new Event(histogram_value, event_name, std::move(args))); | 1861 new Event(histogram_value, event_name, std::move(args))); |
1863 // The downloads system wants to share on-record events with off-record | 1862 // The downloads system wants to share on-record events with off-record |
1864 // extension renderers even in incognito_split_mode because that's how | 1863 // extension renderers even in incognito_split_mode because that's how |
1865 // chrome://downloads works. The "restrict_to_profile" mechanism does not | 1864 // chrome://downloads works. The "restrict_to_profile" mechanism does not |
1866 // anticipate this, so it does not automatically prevent sharing off-record | 1865 // anticipate this, so it does not automatically prevent sharing off-record |
1867 // events with on-record extension renderers. | 1866 // events with on-record extension renderers. |
1868 event->restrict_to_browser_context = | 1867 event->restrict_to_browser_context = |
1869 (include_incognito && !profile_->IsOffTheRecord()) ? NULL : profile_; | 1868 (include_incognito && !profile_->IsOffTheRecord()) ? NULL : profile_; |
1870 event->will_dispatch_callback = will_dispatch_callback; | 1869 event->will_dispatch_callback = will_dispatch_callback; |
1871 EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); | 1870 EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); |
(...skipping 26 matching lines...) Expand all Loading... |
1898 return; | 1897 return; |
1899 base::Time now(base::Time::Now()); | 1898 base::Time now(base::Time::Now()); |
1900 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); | 1899 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); |
1901 if (delta <= kFileExistenceRateLimitSeconds) | 1900 if (delta <= kFileExistenceRateLimitSeconds) |
1902 return; | 1901 return; |
1903 last_checked_removal_ = now; | 1902 last_checked_removal_ = now; |
1904 manager->CheckForHistoryFilesRemoval(); | 1903 manager->CheckForHistoryFilesRemoval(); |
1905 } | 1904 } |
1906 | 1905 |
1907 } // namespace extensions | 1906 } // namespace extensions |
OLD | NEW |