| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class SequencedTaskRunner; | 20 class SequencedTaskRunner; |
| 21 class SequencedWorkerPool; | 21 class SequencedWorkerPool; |
| 22 } | 22 } |
| 23 | 23 |
| 24 // Loads and parses an upload list text file of the format | 24 // Loads and parses an upload list text file of the format |
| 25 // upload_time,upload_id[,local_id[,capture_time]] | 25 // upload_time,upload_id[,local_id[,capture_time[,state]]] |
| 26 // upload_time,upload_id[,local_id[,capture_time]] | 26 // upload_time,upload_id[,local_id[,capture_time[,state]]] |
| 27 // etc. | 27 // etc. |
| 28 // where each line represents an upload. |upload_time| and |capture_time| are | 28 // where each line represents an upload. |upload_time| and |capture_time| are in |
| 29 // in Unix time. Must be used from the UI thread. The loading and parsing is | 29 // Unix time. |state| is an int in the range of UploadInfo::State. Must be used |
| 30 // done on a blocking pool task runner. A line may or may not contain | 30 // from the UI thread. The loading and parsing is done on a blocking pool task |
| 31 // |local_id| and |capture_time|. | 31 // runner. A line may or may not contain |local_id|, |capture_time|, and |
| 32 // |state|. |
| 32 class UploadList : public base::RefCountedThreadSafe<UploadList> { | 33 class UploadList : public base::RefCountedThreadSafe<UploadList> { |
| 33 public: | 34 public: |
| 34 struct UploadInfo { | 35 struct UploadInfo { |
| 36 enum class State { |
| 37 NotUploaded = 0, |
| 38 Pending = 1, |
| 39 Uploaded = 2, |
| 40 }; |
| 41 |
| 35 UploadInfo(const std::string& upload_id, | 42 UploadInfo(const std::string& upload_id, |
| 36 const base::Time& upload_time, | 43 const base::Time& upload_time, |
| 37 const std::string& local_id, | 44 const std::string& local_id, |
| 38 const base::Time& capture_time); | 45 const base::Time& capture_time, |
| 46 State state); |
| 39 UploadInfo(const std::string& upload_id, const base::Time& upload_time); | 47 UploadInfo(const std::string& upload_id, const base::Time& upload_time); |
| 40 ~UploadInfo(); | 48 ~UploadInfo(); |
| 41 | 49 |
| 50 // These fields are only valid when |state| == UploadInfo::State::Uploaded. |
| 42 std::string upload_id; | 51 std::string upload_id; |
| 43 base::Time upload_time; | 52 base::Time upload_time; |
| 44 | 53 |
| 45 // ID for locally stored data that may or may not be uploaded. | 54 // ID for locally stored data that may or may not be uploaded. |
| 46 std::string local_id; | 55 std::string local_id; |
| 47 | 56 |
| 48 // The time the data was captured. This is useful if the data is stored | 57 // The time the data was captured. This is useful if the data is stored |
| 49 // locally when captured and uploaded at a later time. | 58 // locally when captured and uploaded at a later time. |
| 50 base::Time capture_time; | 59 base::Time capture_time; |
| 60 |
| 61 State state; |
| 51 }; | 62 }; |
| 52 | 63 |
| 53 class Delegate { | 64 class Delegate { |
| 54 public: | 65 public: |
| 55 // Invoked when the upload list has been loaded. Will be called on the | 66 // Invoked when the upload list has been loaded. Will be called on the |
| 56 // UI thread. | 67 // UI thread. |
| 57 virtual void OnUploadListAvailable() = 0; | 68 virtual void OnUploadListAvailable() = 0; |
| 58 | 69 |
| 59 protected: | 70 protected: |
| 60 virtual ~Delegate() {} | 71 virtual ~Delegate() {} |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 Delegate* delegate_; | 117 Delegate* delegate_; |
| 107 | 118 |
| 108 const base::FilePath upload_log_path_; | 119 const base::FilePath upload_log_path_; |
| 109 | 120 |
| 110 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 121 scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| 111 | 122 |
| 112 DISALLOW_COPY_AND_ASSIGN(UploadList); | 123 DISALLOW_COPY_AND_ASSIGN(UploadList); |
| 113 }; | 124 }; |
| 114 | 125 |
| 115 #endif // COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_ | 126 #endif // COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_ |
| OLD | NEW |