text_log_upload_list.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_UPLOAD_LIST_TEXT_LOG_UPLOAD_LIST_H_
  5. #define COMPONENTS_UPLOAD_LIST_TEXT_LOG_UPLOAD_LIST_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/files/file_path.h"
  9. #include "components/upload_list/upload_list.h"
  10. // Loads and parses an upload list text file of the line-based JSON format:
  11. // {"upload_time":<value>[,"upload_id":<value>[,"local_id":<value>
  12. // [,"capture_time":<value>[,"state":<value>[,"source":<value>]]]]]}
  13. // {"upload_time":<value>[,"upload_id":<value>[,"local_id":<value>
  14. // [,"capture_time":<value>[,"state":<value>[,"source":<value>]]]]]}
  15. // ...
  16. // or the CSV format:
  17. // upload_time,upload_id[,local_id[,capture_time[,state]]]
  18. // upload_time,upload_id[,local_id[,capture_time[,state]]]
  19. // ...
  20. // where each line represents an upload. |upload_time| and |capture_time| are in
  21. // Unix time. |state| is an int in the range of UploadInfo::State. A line may
  22. // or may not contain |local_id|, |capture_time|, |state| and |source|.
  23. class TextLogUploadList : public UploadList {
  24. public:
  25. // Creates a new upload list that parses the log at |upload_log_path|.
  26. explicit TextLogUploadList(const base::FilePath& upload_log_path);
  27. TextLogUploadList(const TextLogUploadList&) = delete;
  28. TextLogUploadList& operator=(const TextLogUploadList&) = delete;
  29. const base::FilePath& upload_log_path() const { return upload_log_path_; }
  30. protected:
  31. ~TextLogUploadList() override;
  32. // UploadList:
  33. std::vector<UploadList::UploadInfo> LoadUploadList() override;
  34. void ClearUploadList(const base::Time& begin, const base::Time& end) override;
  35. // Parses upload log lines, converting them to UploadInfo entries.
  36. // The method also reverse the order of the entries (the first entry in
  37. // |uploads| is the last in |log_entries|).
  38. void ParseLogEntries(const std::vector<std::string>& log_entries,
  39. std::vector<UploadInfo>* uploads);
  40. const base::FilePath upload_log_path_;
  41. };
  42. #endif // COMPONENTS_UPLOAD_LIST_TEXT_LOG_UPLOAD_LIST_H_