| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/upload_list/upload_list.h" | 5 #include "components/upload_list/upload_list.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
| 18 | 18 |
| 19 UploadList::UploadInfo::UploadInfo(const std::string& id, | 19 UploadList::UploadInfo::UploadInfo(const std::string& upload_id, |
| 20 const base::Time& t, | 20 const base::Time& upload_time, |
| 21 const std::string& local_id) | 21 const std::string& local_id, |
| 22 : id(id), time(t), local_id(local_id) {} | 22 const base::Time& capture_time) |
| 23 : upload_id(upload_id), upload_time(upload_time), |
| 24 local_id(local_id), capture_time(capture_time) {} |
| 23 | 25 |
| 24 UploadList::UploadInfo::UploadInfo(const std::string& id, const base::Time& t) | 26 UploadList::UploadInfo::UploadInfo(const std::string& upload_id, |
| 25 : id(id), time(t) {} | 27 const base::Time& upload_time) |
| 28 : upload_id(upload_id), upload_time(upload_time) {} |
| 26 | 29 |
| 27 UploadList::UploadInfo::~UploadInfo() {} | 30 UploadList::UploadInfo::~UploadInfo() {} |
| 28 | 31 |
| 29 UploadList::UploadList( | 32 UploadList::UploadList( |
| 30 Delegate* delegate, | 33 Delegate* delegate, |
| 31 const base::FilePath& upload_log_path, | 34 const base::FilePath& upload_log_path, |
| 32 const scoped_refptr<base::SequencedWorkerPool>& worker_pool) | 35 const scoped_refptr<base::SequencedWorkerPool>& worker_pool) |
| 33 : delegate_(delegate), | 36 : delegate_(delegate), |
| 34 upload_log_path_(upload_log_path), | 37 upload_log_path_(upload_log_path), |
| 35 worker_pool_(worker_pool) {} | 38 worker_pool_(worker_pool) {} |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 uploads_.clear(); | 80 uploads_.clear(); |
| 78 } | 81 } |
| 79 | 82 |
| 80 void UploadList::ParseLogEntries( | 83 void UploadList::ParseLogEntries( |
| 81 const std::vector<std::string>& log_entries) { | 84 const std::vector<std::string>& log_entries) { |
| 82 std::vector<std::string>::const_reverse_iterator i; | 85 std::vector<std::string>::const_reverse_iterator i; |
| 83 for (i = log_entries.rbegin(); i != log_entries.rend(); ++i) { | 86 for (i = log_entries.rbegin(); i != log_entries.rend(); ++i) { |
| 84 std::vector<std::string> components = base::SplitString( | 87 std::vector<std::string> components = base::SplitString( |
| 85 *i, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 88 *i, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 86 // Skip any blank (or corrupted) lines. | 89 // Skip any blank (or corrupted) lines. |
| 87 if (components.size() != 2 && components.size() != 3) | 90 if (components.size() < 2 || components.size() > 4) |
| 88 continue; | 91 continue; |
| 89 base::Time upload_time; | 92 base::Time upload_time; |
| 90 double seconds_since_epoch; | 93 double seconds_since_epoch; |
| 91 if (!components[0].empty()) { | 94 if (!components[0].empty()) { |
| 92 if (!base::StringToDouble(components[0], &seconds_since_epoch)) | 95 if (!base::StringToDouble(components[0], &seconds_since_epoch)) |
| 93 continue; | 96 continue; |
| 94 upload_time = base::Time::FromDoubleT(seconds_since_epoch); | 97 upload_time = base::Time::FromDoubleT(seconds_since_epoch); |
| 95 } | 98 } |
| 96 UploadInfo info(components[1], upload_time); | 99 UploadInfo info(components[1], upload_time); |
| 97 if (components.size() == 3) | 100 |
| 101 // Add local ID if present. |
| 102 if (components.size() > 2) |
| 98 info.local_id = components[2]; | 103 info.local_id = components[2]; |
| 104 |
| 105 // Add capture time if present. |
| 106 if (components.size() > 3 && |
| 107 !components[3].empty() && |
| 108 base::StringToDouble(components[3], &seconds_since_epoch)) { |
| 109 info.capture_time = base::Time::FromDoubleT(seconds_since_epoch); |
| 110 } |
| 111 |
| 99 uploads_.push_back(info); | 112 uploads_.push_back(info); |
| 100 } | 113 } |
| 101 } | 114 } |
| 102 | 115 |
| 103 void UploadList::InformDelegateOfCompletion() { | 116 void UploadList::InformDelegateOfCompletion() { |
| 104 DCHECK(thread_checker_.CalledOnValidThread()); | 117 DCHECK(thread_checker_.CalledOnValidThread()); |
| 105 if (delegate_) | 118 if (delegate_) |
| 106 delegate_->OnUploadListAvailable(); | 119 delegate_->OnUploadListAvailable(); |
| 107 } | 120 } |
| 108 | 121 |
| 109 void UploadList::GetUploads(unsigned int max_count, | 122 void UploadList::GetUploads(unsigned int max_count, |
| 110 std::vector<UploadInfo>* uploads) { | 123 std::vector<UploadInfo>* uploads) { |
| 111 DCHECK(thread_checker_.CalledOnValidThread()); | 124 DCHECK(thread_checker_.CalledOnValidThread()); |
| 112 std::copy(uploads_.begin(), | 125 std::copy(uploads_.begin(), |
| 113 uploads_.begin() + std::min<size_t>(uploads_.size(), max_count), | 126 uploads_.begin() + std::min<size_t>(uploads_.size(), max_count), |
| 114 std::back_inserter(*uploads)); | 127 std::back_inserter(*uploads)); |
| 115 } | 128 } |
| OLD | NEW |