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/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
16 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
17 | 18 |
18 UploadList::UploadInfo::UploadInfo(const std::string& id, | 19 UploadList::UploadInfo::UploadInfo(const std::string& id, |
19 const base::Time& t, | 20 const base::Time& t, |
20 const std::string& local_id) | 21 const std::string& local_id) |
21 : id(id), time(t), local_id(local_id) {} | 22 : id(id), time(t), local_id(local_id) {} |
22 | 23 |
23 UploadList::UploadInfo::UploadInfo(const std::string& id, const base::Time& t) | 24 UploadList::UploadInfo::UploadInfo(const std::string& id, const base::Time& t) |
24 : id(id), time(t) {} | 25 : id(id), time(t) {} |
(...skipping 28 matching lines...) Expand all Loading... |
53 LoadUploadList(); | 54 LoadUploadList(); |
54 task_runner->PostTask( | 55 task_runner->PostTask( |
55 FROM_HERE, | 56 FROM_HERE, |
56 base::Bind(&UploadList::InformDelegateOfCompletion, this)); | 57 base::Bind(&UploadList::InformDelegateOfCompletion, this)); |
57 } | 58 } |
58 | 59 |
59 void UploadList::LoadUploadList() { | 60 void UploadList::LoadUploadList() { |
60 if (base::PathExists(upload_log_path_)) { | 61 if (base::PathExists(upload_log_path_)) { |
61 std::string contents; | 62 std::string contents; |
62 base::ReadFileToString(upload_log_path_, &contents); | 63 base::ReadFileToString(upload_log_path_, &contents); |
63 std::vector<std::string> log_entries; | 64 std::vector<std::string> log_entries = base::SplitString( |
64 base::SplitStringAlongWhitespace(contents, &log_entries); | 65 contents, base::kWhitespaceASCII, base::KEEP_WHITESPACE, |
| 66 base::SPLIT_WANT_NONEMPTY); |
65 ClearUploads(); | 67 ClearUploads(); |
66 ParseLogEntries(log_entries); | 68 ParseLogEntries(log_entries); |
67 } | 69 } |
68 } | 70 } |
69 | 71 |
70 void UploadList::AppendUploadInfo(const UploadInfo& info) { | 72 void UploadList::AppendUploadInfo(const UploadInfo& info) { |
71 uploads_.push_back(info); | 73 uploads_.push_back(info); |
72 } | 74 } |
73 | 75 |
74 void UploadList::ClearUploads() { | 76 void UploadList::ClearUploads() { |
(...skipping 29 matching lines...) Expand all Loading... |
104 delegate_->OnUploadListAvailable(); | 106 delegate_->OnUploadListAvailable(); |
105 } | 107 } |
106 | 108 |
107 void UploadList::GetUploads(unsigned int max_count, | 109 void UploadList::GetUploads(unsigned int max_count, |
108 std::vector<UploadInfo>* uploads) { | 110 std::vector<UploadInfo>* uploads) { |
109 DCHECK(thread_checker_.CalledOnValidThread()); | 111 DCHECK(thread_checker_.CalledOnValidThread()); |
110 std::copy(uploads_.begin(), | 112 std::copy(uploads_.begin(), |
111 uploads_.begin() + std::min<size_t>(uploads_.size(), max_count), | 113 uploads_.begin() + std::min<size_t>(uploads_.size(), max_count), |
112 std::back_inserter(*uploads)); | 114 std::back_inserter(*uploads)); |
113 } | 115 } |
OLD | NEW |