| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 // |items| will contain |count| DownloadItems in the order that they were | 346 // |items| will contain |count| DownloadItems in the order that they were |
| 347 // specified in |history_info|. Returns true on success and false otherwise. | 347 // specified in |history_info|. Returns true on success and false otherwise. |
| 348 bool CreateHistoryDownloads(const HistoryDownloadInfo* history_info, | 348 bool CreateHistoryDownloads(const HistoryDownloadInfo* history_info, |
| 349 size_t count, | 349 size_t count, |
| 350 DownloadManager::DownloadVector* items) { | 350 DownloadManager::DownloadVector* items) { |
| 351 DownloadIdComparator download_id_comparator; | 351 DownloadIdComparator download_id_comparator; |
| 352 base::Time current = base::Time::Now(); | 352 base::Time current = base::Time::Now(); |
| 353 items->clear(); | 353 items->clear(); |
| 354 GetOnRecordManager()->GetAllDownloads(items); | 354 GetOnRecordManager()->GetAllDownloads(items); |
| 355 CHECK_EQ(0, static_cast<int>(items->size())); | 355 CHECK_EQ(0, static_cast<int>(items->size())); |
| 356 std::vector<GURL> url_chain; |
| 357 url_chain.push_back(GURL()); |
| 356 for (size_t i = 0; i < count; ++i) { | 358 for (size_t i = 0; i < count; ++i) { |
| 357 DownloadItem* item = GetOnRecordManager()->CreateDownloadItem( | 359 DownloadItem* item = GetOnRecordManager()->CreateDownloadItem( |
| 358 downloads_directory().Append(history_info[i].filename), | 360 downloads_directory().Append(history_info[i].filename), |
| 359 GURL(), GURL(), // URL, referrer | 361 downloads_directory().Append(history_info[i].filename), |
| 362 url_chain, GURL(), // URL Chain, referrer |
| 360 current, current, // start_time, end_time | 363 current, current, // start_time, end_time |
| 361 1, 1, // received_bytes, total_bytes | 364 1, 1, // received_bytes, total_bytes |
| 362 history_info[i].state, // state | 365 history_info[i].state, // state |
| 366 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
| 363 false); // opened | 367 false); // opened |
| 364 items->push_back(item); | 368 items->push_back(item); |
| 365 } | 369 } |
| 366 | 370 |
| 367 // Order by ID so that they are in the order that we created them. | 371 // Order by ID so that they are in the order that we created them. |
| 368 std::sort(items->begin(), items->end(), download_id_comparator); | 372 std::sort(items->begin(), items->end(), download_id_comparator); |
| 369 // Set the danger type if necessary. | 373 // Set the danger type if necessary. |
| 370 for (size_t i = 0; i < count; ++i) { | 374 for (size_t i = 0; i < count; ++i) { |
| 371 if (history_info[i].danger_type != | 375 if (history_info[i].danger_type != |
| 372 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { | 376 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
| (...skipping 1762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 " \"state\": {" | 2139 " \"state\": {" |
| 2136 " \"previous\": \"in_progress\"," | 2140 " \"previous\": \"in_progress\"," |
| 2137 " \"current\": \"complete\"}}]", | 2141 " \"current\": \"complete\"}}]", |
| 2138 result_id, | 2142 result_id, |
| 2139 GetFilename("on_record.txt.crdownload").c_str(), | 2143 GetFilename("on_record.txt.crdownload").c_str(), |
| 2140 GetFilename("on_record.txt").c_str()))); | 2144 GetFilename("on_record.txt").c_str()))); |
| 2141 std::string disk_data; | 2145 std::string disk_data; |
| 2142 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); | 2146 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); |
| 2143 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2147 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
| 2144 } | 2148 } |
| OLD | NEW |