| 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 #ifndef COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_ | 5 #ifndef COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_ |
| 6 #define COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_ | 6 #define COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // where each line represents an upload. |upload_time| and |capture_time| are in | 28 // where each line represents an upload. |upload_time| and |capture_time| are in |
| 29 // Unix time. |state| is an int in the range of UploadInfo::State. Must be used | 29 // Unix time. |state| is an int in the range of UploadInfo::State. Must be used |
| 30 // from the UI thread. The loading and parsing is done on a blocking pool task | 30 // from the UI thread. The loading and parsing is done on a blocking pool task |
| 31 // runner. A line may or may not contain |local_id|, |capture_time|, and | 31 // runner. A line may or may not contain |local_id|, |capture_time|, and |
| 32 // |state|. | 32 // |state|. |
| 33 class UploadList : public base::RefCountedThreadSafe<UploadList> { | 33 class UploadList : public base::RefCountedThreadSafe<UploadList> { |
| 34 public: | 34 public: |
| 35 struct UploadInfo { | 35 struct UploadInfo { |
| 36 enum class State { | 36 enum class State { |
| 37 NotUploaded = 0, | 37 NotUploaded = 0, |
| 38 Pending = 1, | 38 Pending, |
| 39 Uploaded = 2, | 39 Pending_UserRequested, |
| 40 Uploaded, |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 UploadInfo(const std::string& upload_id, | 43 UploadInfo(const std::string& upload_id, |
| 43 const base::Time& upload_time, | 44 const base::Time& upload_time, |
| 44 const std::string& local_id, | 45 const std::string& local_id, |
| 45 const base::Time& capture_time, | 46 const base::Time& capture_time, |
| 46 State state); | 47 State state); |
| 47 UploadInfo(const std::string& upload_id, const base::Time& upload_time); | 48 UploadInfo(const std::string& upload_id, const base::Time& upload_time); |
| 48 ~UploadInfo(); | 49 ~UploadInfo(); |
| 49 | 50 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 73 | 74 |
| 74 // Creates a new upload list with the given callback delegate. | 75 // Creates a new upload list with the given callback delegate. |
| 75 UploadList(Delegate* delegate, | 76 UploadList(Delegate* delegate, |
| 76 const base::FilePath& upload_log_path, | 77 const base::FilePath& upload_log_path, |
| 77 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); | 78 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); |
| 78 | 79 |
| 79 // Starts loading the upload list. OnUploadListAvailable will be called when | 80 // Starts loading the upload list. OnUploadListAvailable will be called when |
| 80 // loading is complete. | 81 // loading is complete. |
| 81 void LoadUploadListAsynchronously(); | 82 void LoadUploadListAsynchronously(); |
| 82 | 83 |
| 84 // Asynchronously requests a user triggered upload. |
| 85 void RequestSingleCrashUploadAsync(const std::string& local_id); |
| 86 |
| 83 // Clears the delegate, so that any outstanding asynchronous load will not | 87 // Clears the delegate, so that any outstanding asynchronous load will not |
| 84 // call the delegate on completion. | 88 // call the delegate on completion. |
| 85 void ClearDelegate(); | 89 void ClearDelegate(); |
| 86 | 90 |
| 87 // Populates |uploads| with the |max_count| most recent uploads, | 91 // Populates |uploads| with the |max_count| most recent uploads, |
| 88 // in reverse chronological order. | 92 // in reverse chronological order. |
| 89 // Must be called only after OnUploadListAvailable has been called. | 93 // Must be called only after OnUploadListAvailable has been called. |
| 90 void GetUploads(size_t max_count, std::vector<UploadInfo>* uploads); | 94 void GetUploads(size_t max_count, std::vector<UploadInfo>* uploads); |
| 91 | 95 |
| 92 protected: | 96 protected: |
| 93 virtual ~UploadList(); | 97 virtual ~UploadList(); |
| 94 | 98 |
| 95 // Reads the upload log and stores the entries in |uploads|. | 99 // Reads the upload log and stores the entries in |uploads|. |
| 96 virtual void LoadUploadList(std::vector<UploadInfo>* uploads); | 100 virtual void LoadUploadList(std::vector<UploadInfo>* uploads); |
| 97 | 101 |
| 102 // Requests a user triggered upload for a crash report with a given id. |
| 103 virtual void RequestSingleCrashUpload(const std::string& local_id); |
| 104 |
| 98 private: | 105 private: |
| 99 friend class base::RefCountedThreadSafe<UploadList>; | 106 friend class base::RefCountedThreadSafe<UploadList>; |
| 100 | 107 |
| 101 // Manages the background thread work for LoadUploadListAsynchronously(). | 108 // Manages the background thread work for LoadUploadListAsynchronously(). |
| 102 void PerformLoadAndNotifyDelegate( | 109 void PerformLoadAndNotifyDelegate( |
| 103 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 110 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 104 | 111 |
| 105 // Calls the delegate's callback method, if there is a delegate. Stores | 112 // Calls the delegate's callback method, if there is a delegate. Stores |
| 106 // the newly loaded |uploads| into |uploads_| on the delegate's task runner. | 113 // the newly loaded |uploads| into |uploads_| on the delegate's task runner. |
| 107 void SetUploadsAndNotifyDelegate(std::vector<UploadInfo> uploads); | 114 void SetUploadsAndNotifyDelegate(std::vector<UploadInfo> uploads); |
| 108 | 115 |
| 109 // Parses upload log lines, converting them to UploadInfo entries. | 116 // Parses upload log lines, converting them to UploadInfo entries. |
| 110 void ParseLogEntries(const std::vector<std::string>& log_entries, | 117 void ParseLogEntries(const std::vector<std::string>& log_entries, |
| 111 std::vector<UploadInfo>* uploads); | 118 std::vector<UploadInfo>* uploads); |
| 112 | 119 |
| 113 // |thread_checker_| ensures that |uploads_| is only set from the task runner | 120 // |thread_checker_| ensures that |uploads_| is only set from the task runner |
| 114 // that created the UploadList. | 121 // that created the UploadList. |
| 115 base::ThreadChecker thread_checker_; | 122 base::ThreadChecker thread_checker_; |
| 116 std::vector<UploadInfo> uploads_; | 123 std::vector<UploadInfo> uploads_; |
| 117 Delegate* delegate_; | 124 Delegate* delegate_; |
| 118 | 125 |
| 119 const base::FilePath upload_log_path_; | 126 const base::FilePath upload_log_path_; |
| 120 | 127 |
| 121 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 128 scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| 122 | 129 |
| 123 DISALLOW_COPY_AND_ASSIGN(UploadList); | 130 DISALLOW_COPY_AND_ASSIGN(UploadList); |
| 124 }; | 131 }; |
| 125 | 132 |
| 126 #endif // COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_ | 133 #endif // COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_ |
| OLD | NEW |