| 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 <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 const char kStartedBeforeKey[] = "startedBefore"; | 166 const char kStartedBeforeKey[] = "startedBefore"; |
| 167 const char kStateComplete[] = "complete"; | 167 const char kStateComplete[] = "complete"; |
| 168 const char kStateInProgress[] = "in_progress"; | 168 const char kStateInProgress[] = "in_progress"; |
| 169 const char kStateInterrupted[] = "interrupted"; | 169 const char kStateInterrupted[] = "interrupted"; |
| 170 const char kStateKey[] = "state"; | 170 const char kStateKey[] = "state"; |
| 171 const char kTotalBytesGreaterKey[] = "totalBytesGreater"; | 171 const char kTotalBytesGreaterKey[] = "totalBytesGreater"; |
| 172 const char kTotalBytesKey[] = "totalBytes"; | 172 const char kTotalBytesKey[] = "totalBytes"; |
| 173 const char kTotalBytesLessKey[] = "totalBytesLess"; | 173 const char kTotalBytesLessKey[] = "totalBytesLess"; |
| 174 const char kUrlKey[] = "url"; | 174 const char kUrlKey[] = "url"; |
| 175 const char kUrlRegexKey[] = "urlRegex"; | 175 const char kUrlRegexKey[] = "urlRegex"; |
| 176 const char kFinalUrlKey[] = "finalUrl"; |
| 177 const char kFinalUrlRegexKey[] = "finalUrlRegex"; |
| 176 | 178 |
| 177 // Note: Any change to the danger type strings, should be accompanied by a | 179 // Note: Any change to the danger type strings, should be accompanied by a |
| 178 // corresponding change to downloads.json. | 180 // corresponding change to downloads.json. |
| 179 const char* const kDangerStrings[] = { | 181 const char* const kDangerStrings[] = { |
| 180 kDangerSafe, | 182 kDangerSafe, |
| 181 kDangerFile, | 183 kDangerFile, |
| 182 kDangerUrl, | 184 kDangerUrl, |
| 183 kDangerContent, | 185 kDangerContent, |
| 184 kDangerSafe, | 186 kDangerSafe, |
| 185 kDangerUncommon, | 187 kDangerUncommon, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 249 } |
| 248 | 250 |
| 249 std::unique_ptr<base::DictionaryValue> DownloadItemToJSON( | 251 std::unique_ptr<base::DictionaryValue> DownloadItemToJSON( |
| 250 DownloadItem* download_item, | 252 DownloadItem* download_item, |
| 251 Profile* profile) { | 253 Profile* profile) { |
| 252 base::DictionaryValue* json = new base::DictionaryValue(); | 254 base::DictionaryValue* json = new base::DictionaryValue(); |
| 253 json->SetBoolean(kExistsKey, !download_item->GetFileExternallyRemoved()); | 255 json->SetBoolean(kExistsKey, !download_item->GetFileExternallyRemoved()); |
| 254 json->SetInteger(kIdKey, download_item->GetId()); | 256 json->SetInteger(kIdKey, download_item->GetId()); |
| 255 const GURL& url = download_item->GetOriginalUrl(); | 257 const GURL& url = download_item->GetOriginalUrl(); |
| 256 json->SetString(kUrlKey, (url.is_valid() ? url.spec() : std::string())); | 258 json->SetString(kUrlKey, (url.is_valid() ? url.spec() : std::string())); |
| 259 const GURL& finalUrl = download_item->GetURL(); |
| 260 json->SetString(kFinalUrlKey, |
| 261 (finalUrl.is_valid() ? finalUrl.spec() : std::string())); |
| 257 const GURL& referrer = download_item->GetReferrerUrl(); | 262 const GURL& referrer = download_item->GetReferrerUrl(); |
| 258 json->SetString(kReferrerUrlKey, (referrer.is_valid() ? referrer.spec() | 263 json->SetString(kReferrerUrlKey, (referrer.is_valid() ? referrer.spec() |
| 259 : std::string())); | 264 : std::string())); |
| 260 json->SetString(kFilenameKey, | 265 json->SetString(kFilenameKey, |
| 261 download_item->GetTargetFilePath().LossyDisplayName()); | 266 download_item->GetTargetFilePath().LossyDisplayName()); |
| 262 json->SetString(kDangerKey, DangerString(download_item->GetDangerType())); | 267 json->SetString(kDangerKey, DangerString(download_item->GetDangerType())); |
| 263 json->SetString(kStateKey, StateString(download_item->GetState())); | 268 json->SetString(kStateKey, StateString(download_item->GetState())); |
| 264 json->SetBoolean(kCanResumeKey, download_item->CanResume()); | 269 json->SetBoolean(kCanResumeKey, download_item->CanResume()); |
| 265 json->SetBoolean(kPausedKey, download_item->IsPaused()); | 270 json->SetBoolean(kPausedKey, download_item->IsPaused()); |
| 266 json->SetString(kMimeKey, download_item->GetMimeType()); | 271 json->SetString(kMimeKey, download_item->GetMimeType()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 filter_types[kEndedAfterKey] = DownloadQuery::FILTER_ENDED_AFTER; | 373 filter_types[kEndedAfterKey] = DownloadQuery::FILTER_ENDED_AFTER; |
| 369 filter_types[kEndedBeforeKey] = DownloadQuery::FILTER_ENDED_BEFORE; | 374 filter_types[kEndedBeforeKey] = DownloadQuery::FILTER_ENDED_BEFORE; |
| 370 filter_types[kEndTimeKey] = DownloadQuery::FILTER_END_TIME; | 375 filter_types[kEndTimeKey] = DownloadQuery::FILTER_END_TIME; |
| 371 filter_types[kStartedAfterKey] = DownloadQuery::FILTER_STARTED_AFTER; | 376 filter_types[kStartedAfterKey] = DownloadQuery::FILTER_STARTED_AFTER; |
| 372 filter_types[kStartedBeforeKey] = DownloadQuery::FILTER_STARTED_BEFORE; | 377 filter_types[kStartedBeforeKey] = DownloadQuery::FILTER_STARTED_BEFORE; |
| 373 filter_types[kStartTimeKey] = DownloadQuery::FILTER_START_TIME; | 378 filter_types[kStartTimeKey] = DownloadQuery::FILTER_START_TIME; |
| 374 filter_types[kTotalBytesKey] = DownloadQuery::FILTER_TOTAL_BYTES; | 379 filter_types[kTotalBytesKey] = DownloadQuery::FILTER_TOTAL_BYTES; |
| 375 filter_types[kTotalBytesGreaterKey] = | 380 filter_types[kTotalBytesGreaterKey] = |
| 376 DownloadQuery::FILTER_TOTAL_BYTES_GREATER; | 381 DownloadQuery::FILTER_TOTAL_BYTES_GREATER; |
| 377 filter_types[kTotalBytesLessKey] = DownloadQuery::FILTER_TOTAL_BYTES_LESS; | 382 filter_types[kTotalBytesLessKey] = DownloadQuery::FILTER_TOTAL_BYTES_LESS; |
| 378 filter_types[kUrlKey] = DownloadQuery::FILTER_URL; | 383 filter_types[kUrlKey] = DownloadQuery::FILTER_ORIGINAL_URL; |
| 379 filter_types[kUrlRegexKey] = DownloadQuery::FILTER_URL_REGEX; | 384 filter_types[kUrlRegexKey] = DownloadQuery::FILTER_ORIGINAL_URL_REGEX; |
| 385 filter_types[kFinalUrlKey] = DownloadQuery::FILTER_URL; |
| 386 filter_types[kFinalUrlRegexKey] = DownloadQuery::FILTER_URL_REGEX; |
| 380 } | 387 } |
| 381 | 388 |
| 382 typedef base::hash_map<std::string, DownloadQuery::SortType> SortTypeMap; | 389 typedef base::hash_map<std::string, DownloadQuery::SortType> SortTypeMap; |
| 383 | 390 |
| 384 void InitSortTypeMap(SortTypeMap* sorter_types_ptr) { | 391 void InitSortTypeMap(SortTypeMap* sorter_types_ptr) { |
| 385 SortTypeMap& sorter_types = *sorter_types_ptr; | 392 SortTypeMap& sorter_types = *sorter_types_ptr; |
| 386 sorter_types[kBytesReceivedKey] = DownloadQuery::SORT_BYTES_RECEIVED; | 393 sorter_types[kBytesReceivedKey] = DownloadQuery::SORT_BYTES_RECEIVED; |
| 387 sorter_types[kDangerKey] = DownloadQuery::SORT_DANGER; | 394 sorter_types[kDangerKey] = DownloadQuery::SORT_DANGER; |
| 388 sorter_types[kEndTimeKey] = DownloadQuery::SORT_END_TIME; | 395 sorter_types[kEndTimeKey] = DownloadQuery::SORT_END_TIME; |
| 389 sorter_types[kExistsKey] = DownloadQuery::SORT_EXISTS; | 396 sorter_types[kExistsKey] = DownloadQuery::SORT_EXISTS; |
| 390 sorter_types[kFilenameKey] = DownloadQuery::SORT_FILENAME; | 397 sorter_types[kFilenameKey] = DownloadQuery::SORT_FILENAME; |
| 391 sorter_types[kMimeKey] = DownloadQuery::SORT_MIME; | 398 sorter_types[kMimeKey] = DownloadQuery::SORT_MIME; |
| 392 sorter_types[kPausedKey] = DownloadQuery::SORT_PAUSED; | 399 sorter_types[kPausedKey] = DownloadQuery::SORT_PAUSED; |
| 393 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME; | 400 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME; |
| 394 sorter_types[kStateKey] = DownloadQuery::SORT_STATE; | 401 sorter_types[kStateKey] = DownloadQuery::SORT_STATE; |
| 395 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES; | 402 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES; |
| 396 sorter_types[kUrlKey] = DownloadQuery::SORT_URL; | 403 sorter_types[kUrlKey] = DownloadQuery::SORT_ORIGINAL_URL; |
| 404 sorter_types[kFinalUrlKey] = DownloadQuery::SORT_URL; |
| 397 } | 405 } |
| 398 | 406 |
| 399 bool IsNotTemporaryDownloadFilter(const DownloadItem& download_item) { | 407 bool IsNotTemporaryDownloadFilter(const DownloadItem& download_item) { |
| 400 return !download_item.IsTemporary(); | 408 return !download_item.IsTemporary(); |
| 401 } | 409 } |
| 402 | 410 |
| 403 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to | 411 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to |
| 404 // the off-record DownloadManager if one exists and is requested via | 412 // the off-record DownloadManager if one exists and is requested via |
| 405 // |include_incognito|. This should work regardless of whether |profile| is | 413 // |include_incognito|. This should work regardless of whether |profile| is |
| 406 // original or incognito. | 414 // original or incognito. |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 *message_out = message_in; | 907 *message_out = message_in; |
| 900 return true; | 908 return true; |
| 901 } | 909 } |
| 902 | 910 |
| 903 bool InvalidId(DownloadItem* valid_item, std::string* message_out) { | 911 bool InvalidId(DownloadItem* valid_item, std::string* message_out) { |
| 904 return Fault(!valid_item, errors::kInvalidId, message_out); | 912 return Fault(!valid_item, errors::kInvalidId, message_out); |
| 905 } | 913 } |
| 906 | 914 |
| 907 bool IsDownloadDeltaField(const std::string& field) { | 915 bool IsDownloadDeltaField(const std::string& field) { |
| 908 return ((field == kUrlKey) || | 916 return ((field == kUrlKey) || |
| 917 (field == kFinalUrlKey) || |
| 909 (field == kFilenameKey) || | 918 (field == kFilenameKey) || |
| 910 (field == kDangerKey) || | 919 (field == kDangerKey) || |
| 911 (field == kMimeKey) || | 920 (field == kMimeKey) || |
| 912 (field == kStartTimeKey) || | 921 (field == kStartTimeKey) || |
| 913 (field == kEndTimeKey) || | 922 (field == kEndTimeKey) || |
| 914 (field == kStateKey) || | 923 (field == kStateKey) || |
| 915 (field == kCanResumeKey) || | 924 (field == kCanResumeKey) || |
| 916 (field == kPausedKey) || | 925 (field == kPausedKey) || |
| 917 (field == kErrorKey) || | 926 (field == kErrorKey) || |
| 918 (field == kTotalBytesKey) || | 927 (field == kTotalBytesKey) || |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 return; | 1911 return; |
| 1903 base::Time now(base::Time::Now()); | 1912 base::Time now(base::Time::Now()); |
| 1904 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); | 1913 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); |
| 1905 if (delta <= kFileExistenceRateLimitSeconds) | 1914 if (delta <= kFileExistenceRateLimitSeconds) |
| 1906 return; | 1915 return; |
| 1907 last_checked_removal_ = now; | 1916 last_checked_removal_ = now; |
| 1908 manager->CheckForHistoryFilesRemoval(); | 1917 manager->CheckForHistoryFilesRemoval(); |
| 1909 } | 1918 } |
| 1910 | 1919 |
| 1911 } // namespace extensions | 1920 } // namespace extensions |
| OLD | NEW |