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