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/sequenced_task_runner.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/task_runner.h" |
18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/sequenced_task_runner_handle.h" |
19 | 20 |
20 UploadList::UploadInfo::UploadInfo(const std::string& upload_id, | 21 UploadList::UploadInfo::UploadInfo(const std::string& upload_id, |
21 const base::Time& upload_time, | 22 const base::Time& upload_time, |
22 const std::string& local_id, | 23 const std::string& local_id, |
23 const base::Time& capture_time, | 24 const base::Time& capture_time, |
24 State state) | 25 State state) |
25 : upload_id(upload_id), | 26 : upload_id(upload_id), |
26 upload_time(upload_time), | 27 upload_time(upload_time), |
27 local_id(local_id), | 28 local_id(local_id), |
28 capture_time(capture_time), | 29 capture_time(capture_time), |
(...skipping 13 matching lines...) Expand all Loading... |
42 : upload_id(upload_id), upload_time(upload_time), state(State::Uploaded) {} | 43 : upload_id(upload_id), upload_time(upload_time), state(State::Uploaded) {} |
43 | 44 |
44 UploadList::UploadInfo::UploadInfo(const UploadInfo& upload_info) | 45 UploadList::UploadInfo::UploadInfo(const UploadInfo& upload_info) |
45 : upload_id(upload_info.upload_id), | 46 : upload_id(upload_info.upload_id), |
46 upload_time(upload_info.upload_time), | 47 upload_time(upload_info.upload_time), |
47 local_id(upload_info.local_id), | 48 local_id(upload_info.local_id), |
48 capture_time(upload_info.capture_time), | 49 capture_time(upload_info.capture_time), |
49 state(upload_info.state), | 50 state(upload_info.state), |
50 file_size(upload_info.file_size) {} | 51 file_size(upload_info.file_size) {} |
51 | 52 |
52 UploadList::UploadInfo::~UploadInfo() {} | 53 UploadList::UploadInfo::~UploadInfo() = default; |
53 | 54 |
54 UploadList::UploadList( | 55 UploadList::UploadList(Delegate* delegate, |
55 Delegate* delegate, | 56 const base::FilePath& upload_log_path, |
56 const base::FilePath& upload_log_path, | 57 scoped_refptr<base::TaskRunner> task_runner) |
57 const scoped_refptr<base::SequencedWorkerPool>& worker_pool) | |
58 : delegate_(delegate), | 58 : delegate_(delegate), |
59 upload_log_path_(upload_log_path), | 59 upload_log_path_(upload_log_path), |
60 worker_pool_(worker_pool) {} | 60 task_runner_(std::move(task_runner)) {} |
61 | 61 |
62 UploadList::~UploadList() {} | 62 UploadList::~UploadList() = default; |
63 | 63 |
64 void UploadList::LoadUploadListAsynchronously() { | 64 void UploadList::LoadUploadListAsynchronously() { |
65 DCHECK(thread_checker_.CalledOnValidThread()); | 65 DCHECK(sequence_checker_.CalledOnValidSequence()); |
66 worker_pool_->PostTask( | 66 task_runner_->PostTask( |
67 FROM_HERE, | 67 FROM_HERE, base::Bind(&UploadList::PerformLoadAndNotifyDelegate, this, |
68 base::Bind(&UploadList::PerformLoadAndNotifyDelegate, | 68 base::SequencedTaskRunnerHandle::Get())); |
69 this, base::ThreadTaskRunnerHandle::Get())); | |
70 } | 69 } |
71 | 70 |
72 void UploadList::ClearDelegate() { | 71 void UploadList::ClearDelegate() { |
73 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(sequence_checker_.CalledOnValidSequence()); |
74 delegate_ = NULL; | 73 delegate_ = NULL; |
75 } | 74 } |
76 | 75 |
77 void UploadList::PerformLoadAndNotifyDelegate( | 76 void UploadList::PerformLoadAndNotifyDelegate( |
78 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 77 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
79 std::vector<UploadInfo> uploads; | 78 std::vector<UploadInfo> uploads; |
80 LoadUploadList(&uploads); | 79 LoadUploadList(&uploads); |
81 task_runner->PostTask( | 80 task_runner->PostTask( |
82 FROM_HERE, | 81 FROM_HERE, |
83 base::Bind(&UploadList::SetUploadsAndNotifyDelegate, this, | 82 base::Bind(&UploadList::SetUploadsAndNotifyDelegate, this, |
84 std::move(uploads))); | 83 std::move(uploads))); |
85 } | 84 } |
86 | 85 |
87 void UploadList::LoadUploadList(std::vector<UploadInfo>* uploads) { | 86 void UploadList::LoadUploadList(std::vector<UploadInfo>* uploads) { |
88 if (base::PathExists(upload_log_path_)) { | 87 if (base::PathExists(upload_log_path_)) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 !components[4].empty() && | 133 !components[4].empty() && |
135 base::StringToInt(components[4], &state)) { | 134 base::StringToInt(components[4], &state)) { |
136 info.state = static_cast<UploadInfo::State>(state); | 135 info.state = static_cast<UploadInfo::State>(state); |
137 } | 136 } |
138 | 137 |
139 uploads->push_back(info); | 138 uploads->push_back(info); |
140 } | 139 } |
141 } | 140 } |
142 | 141 |
143 void UploadList::SetUploadsAndNotifyDelegate(std::vector<UploadInfo> uploads) { | 142 void UploadList::SetUploadsAndNotifyDelegate(std::vector<UploadInfo> uploads) { |
144 DCHECK(thread_checker_.CalledOnValidThread()); | 143 DCHECK(sequence_checker_.CalledOnValidSequence()); |
145 uploads_ = std::move(uploads); | 144 uploads_ = std::move(uploads); |
146 if (delegate_) | 145 if (delegate_) |
147 delegate_->OnUploadListAvailable(); | 146 delegate_->OnUploadListAvailable(); |
148 } | 147 } |
149 | 148 |
150 void UploadList::GetUploads(size_t max_count, | 149 void UploadList::GetUploads(size_t max_count, |
151 std::vector<UploadInfo>* uploads) { | 150 std::vector<UploadInfo>* uploads) { |
152 DCHECK(thread_checker_.CalledOnValidThread()); | 151 DCHECK(sequence_checker_.CalledOnValidSequence()); |
153 std::copy(uploads_.begin(), | 152 std::copy(uploads_.begin(), |
154 uploads_.begin() + std::min(uploads_.size(), max_count), | 153 uploads_.begin() + std::min(uploads_.size(), max_count), |
155 std::back_inserter(*uploads)); | 154 std::back_inserter(*uploads)); |
156 } | 155 } |
157 | 156 |
158 void UploadList::RequestSingleCrashUploadAsync(const std::string& local_id) { | 157 void UploadList::RequestSingleCrashUploadAsync(const std::string& local_id) { |
| 158 DCHECK(sequence_checker_.CalledOnValidSequence()); |
159 #if defined(OS_WIN) || defined(OS_MACOSX) | 159 #if defined(OS_WIN) || defined(OS_MACOSX) |
160 DCHECK(thread_checker_.CalledOnValidThread()); | 160 task_runner_->PostTask( |
161 worker_pool_->PostTask( | |
162 FROM_HERE, | 161 FROM_HERE, |
163 base::Bind(&UploadList::RequestSingleCrashUpload, this, local_id)); | 162 base::Bind(&UploadList::RequestSingleCrashUpload, this, local_id)); |
164 #endif | 163 #endif |
165 } | 164 } |
166 | 165 |
167 void UploadList::RequestSingleCrashUpload(const std::string& local_id) { | 166 void UploadList::RequestSingleCrashUpload(const std::string& local_id) { |
168 // Manual uploads for not uploaded crash reports are not available for non | 167 // Manual uploads for not uploaded crash reports are not available for non |
169 // crashpad systems. | 168 // crashpad systems. |
170 NOTREACHED(); | 169 NOTREACHED(); |
171 } | 170 } |
OLD | NEW |