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 <memory> | |
9 #include <set> | 10 #include <set> |
10 #include <string> | 11 #include <string> |
11 #include <utility> | 12 #include <utility> |
12 | 13 |
13 #include "base/bind.h" | 14 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 16 #include "base/callback.h" |
16 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
17 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
18 #include "base/json/json_writer.h" | 19 #include "base/json/json_writer.h" |
19 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
20 #include "base/location.h" | 21 #include "base/location.h" |
21 #include "base/logging.h" | 22 #include "base/logging.h" |
22 #include "base/macros.h" | 23 #include "base/macros.h" |
24 #include "base/memory/ptr_util.h" | |
23 #include "base/memory/weak_ptr.h" | 25 #include "base/memory/weak_ptr.h" |
24 #include "base/metrics/histogram.h" | 26 #include "base/metrics/histogram.h" |
25 #include "base/single_thread_task_runner.h" | 27 #include "base/single_thread_task_runner.h" |
26 #include "base/stl_util.h" | 28 #include "base/stl_util.h" |
27 #include "base/strings/string16.h" | 29 #include "base/strings/string16.h" |
28 #include "base/strings/string_split.h" | 30 #include "base/strings/string_split.h" |
29 #include "base/strings/string_util.h" | 31 #include "base/strings/string_util.h" |
30 #include "base/strings/stringprintf.h" | 32 #include "base/strings/stringprintf.h" |
31 #include "base/task/cancelable_task_tracker.h" | 33 #include "base/task/cancelable_task_tracker.h" |
32 #include "base/threading/thread_task_runner_handle.h" | 34 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1030 | 1032 |
1031 void DownloadsDownloadFunction::OnStarted( | 1033 void DownloadsDownloadFunction::OnStarted( |
1032 const base::FilePath& creator_suggested_filename, | 1034 const base::FilePath& creator_suggested_filename, |
1033 downloads::FilenameConflictAction creator_conflict_action, | 1035 downloads::FilenameConflictAction creator_conflict_action, |
1034 DownloadItem* item, | 1036 DownloadItem* item, |
1035 content::DownloadInterruptReason interrupt_reason) { | 1037 content::DownloadInterruptReason interrupt_reason) { |
1036 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1038 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1037 VLOG(1) << __FUNCTION__ << " " << item << " " << interrupt_reason; | 1039 VLOG(1) << __FUNCTION__ << " " << item << " " << interrupt_reason; |
1038 if (item) { | 1040 if (item) { |
1039 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 1041 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
1040 SetResult(new base::FundamentalValue(static_cast<int>(item->GetId()))); | 1042 SetResult(base::MakeUnique<base::FundamentalValue>( |
1043 static_cast<int>(item->GetId()))); | |
1041 if (!creator_suggested_filename.empty() || | 1044 if (!creator_suggested_filename.empty() || |
1042 (creator_conflict_action != | 1045 (creator_conflict_action != |
1043 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)) { | 1046 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY)) { |
1044 ExtensionDownloadsEventRouterData* data = | 1047 ExtensionDownloadsEventRouterData* data = |
1045 ExtensionDownloadsEventRouterData::Get(item); | 1048 ExtensionDownloadsEventRouterData::Get(item); |
1046 if (!data) { | 1049 if (!data) { |
1047 data = new ExtensionDownloadsEventRouterData( | 1050 data = new ExtensionDownloadsEventRouterData( |
1048 item, std::unique_ptr<base::DictionaryValue>( | 1051 item, std::unique_ptr<base::DictionaryValue>( |
1049 new base::DictionaryValue())); | 1052 new base::DictionaryValue())); |
1050 } | 1053 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1083 } | 1086 } |
1084 DownloadQuery::DownloadVector results; | 1087 DownloadQuery::DownloadVector results; |
1085 RunDownloadQuery(params->query, | 1088 RunDownloadQuery(params->query, |
1086 manager, | 1089 manager, |
1087 incognito_manager, | 1090 incognito_manager, |
1088 &error_, | 1091 &error_, |
1089 &results); | 1092 &results); |
1090 if (!error_.empty()) | 1093 if (!error_.empty()) |
1091 return false; | 1094 return false; |
1092 | 1095 |
1093 base::ListValue* json_results = new base::ListValue(); | 1096 std::unique_ptr<base::ListValue> json_results(new base::ListValue()); |
1094 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); | 1097 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); |
1095 it != results.end(); ++it) { | 1098 it != results.end(); ++it) { |
1096 DownloadItem* download_item = *it; | 1099 DownloadItem* download_item = *it; |
1097 uint32_t download_id = download_item->GetId(); | 1100 uint32_t download_id = download_item->GetId(); |
1098 bool off_record = ((incognito_manager != NULL) && | 1101 bool off_record = ((incognito_manager != NULL) && |
1099 (incognito_manager->GetDownload(download_id) != NULL)); | 1102 (incognito_manager->GetDownload(download_id) != NULL)); |
1100 std::unique_ptr<base::DictionaryValue> json_item(DownloadItemToJSON( | 1103 std::unique_ptr<base::DictionaryValue> json_item(DownloadItemToJSON( |
1101 *it, off_record ? GetProfile()->GetOffTheRecordProfile() | 1104 *it, off_record ? GetProfile()->GetOffTheRecordProfile() |
1102 : GetProfile()->GetOriginalProfile())); | 1105 : GetProfile()->GetOriginalProfile())); |
1103 json_results->Append(json_item.release()); | 1106 json_results->Append(json_item.release()); |
1104 } | 1107 } |
1105 SetResult(json_results); | 1108 SetResult(std::move(json_results)); |
1106 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); | 1109 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); |
1107 return true; | 1110 return true; |
1108 } | 1111 } |
1109 | 1112 |
1110 DownloadsPauseFunction::DownloadsPauseFunction() {} | 1113 DownloadsPauseFunction::DownloadsPauseFunction() {} |
1111 | 1114 |
1112 DownloadsPauseFunction::~DownloadsPauseFunction() {} | 1115 DownloadsPauseFunction::~DownloadsPauseFunction() {} |
1113 | 1116 |
1114 bool DownloadsPauseFunction::RunSync() { | 1117 bool DownloadsPauseFunction::RunSync() { |
1115 std::unique_ptr<downloads::Pause::Params> params( | 1118 std::unique_ptr<downloads::Pause::Params> params( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1180 DownloadManager* incognito_manager = NULL; | 1183 DownloadManager* incognito_manager = NULL; |
1181 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); | 1184 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); |
1182 DownloadQuery::DownloadVector results; | 1185 DownloadQuery::DownloadVector results; |
1183 RunDownloadQuery(params->query, | 1186 RunDownloadQuery(params->query, |
1184 manager, | 1187 manager, |
1185 incognito_manager, | 1188 incognito_manager, |
1186 &error_, | 1189 &error_, |
1187 &results); | 1190 &results); |
1188 if (!error_.empty()) | 1191 if (!error_.empty()) |
1189 return false; | 1192 return false; |
1190 base::ListValue* json_results = new base::ListValue(); | 1193 std::unique_ptr<base::ListValue> json_results(new base::ListValue()); |
1191 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); | 1194 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); |
1192 it != results.end(); ++it) { | 1195 it != results.end(); ++it) { |
1193 json_results->Append( | 1196 json_results->Append( |
1194 new base::FundamentalValue(static_cast<int>((*it)->GetId()))); | 1197 new base::FundamentalValue(static_cast<int>((*it)->GetId()))); |
Devlin
2016/05/20 17:56:54
ditto
| |
1195 (*it)->Remove(); | 1198 (*it)->Remove(); |
1196 } | 1199 } |
1197 SetResult(json_results); | 1200 SetResult(std::move(json_results)); |
1198 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); | 1201 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); |
1199 return true; | 1202 return true; |
1200 } | 1203 } |
1201 | 1204 |
1202 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() { | 1205 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() { |
1203 } | 1206 } |
1204 | 1207 |
1205 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { | 1208 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { |
1206 } | 1209 } |
1207 | 1210 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1498 return true; | 1501 return true; |
1499 } | 1502 } |
1500 | 1503 |
1501 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { | 1504 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { |
1502 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1505 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1503 if (Fault(url.empty(), errors::kIconNotFound, &error_)) { | 1506 if (Fault(url.empty(), errors::kIconNotFound, &error_)) { |
1504 SendResponse(false); | 1507 SendResponse(false); |
1505 return; | 1508 return; |
1506 } | 1509 } |
1507 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); | 1510 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); |
1508 SetResult(new base::StringValue(url)); | 1511 SetResult(base::MakeUnique<base::StringValue>(url)); |
1509 SendResponse(true); | 1512 SendResponse(true); |
1510 } | 1513 } |
1511 | 1514 |
1512 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( | 1515 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( |
1513 Profile* profile, | 1516 Profile* profile, |
1514 DownloadManager* manager) | 1517 DownloadManager* manager) |
1515 : profile_(profile), | 1518 : profile_(profile), |
1516 notifier_(manager, this), | 1519 notifier_(manager, this), |
1517 extension_registry_observer_(this) { | 1520 extension_registry_observer_(this) { |
1518 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1521 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1900 return; | 1903 return; |
1901 base::Time now(base::Time::Now()); | 1904 base::Time now(base::Time::Now()); |
1902 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); | 1905 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); |
1903 if (delta <= kFileExistenceRateLimitSeconds) | 1906 if (delta <= kFileExistenceRateLimitSeconds) |
1904 return; | 1907 return; |
1905 last_checked_removal_ = now; | 1908 last_checked_removal_ = now; |
1906 manager->CheckForHistoryFilesRemoval(); | 1909 manager->CheckForHistoryFilesRemoval(); |
1907 } | 1910 } |
1908 | 1911 |
1909 } // namespace extensions | 1912 } // namespace extensions |
OLD | NEW |