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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UPLOAD_LIST_H_
6 #define CHROME_BROWSER_UPLOAD_LIST_H_
11 #include "base/files/file_path.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/time/time.h"
16 // Loads and parses an upload list text file of the format
20 // where each line represents an upload and "time" is Unix time. Must be used
21 // from the UI thread. The loading and parsing is done on a blocking pool task
22 // runner. A line may or may not contain "local_id".
23 class UploadList
: public base::RefCountedThreadSafe
<UploadList
> {
26 UploadInfo(const std::string
& id
,
28 const std::string
& local_id
);
29 UploadInfo(const std::string
& id
, const base::Time
& t
);
34 // ID for a locally stored object that may or may not be uploaded.
40 // Invoked when the upload list has been loaded. Will be called on the
42 virtual void OnUploadListAvailable() = 0;
45 virtual ~Delegate() {}
48 // Creates a new upload list with the given callback delegate.
49 UploadList(Delegate
* delegate
, const base::FilePath
& upload_log_path
);
51 // Starts loading the upload list. OnUploadListAvailable will be called when
52 // loading is complete.
53 void LoadUploadListAsynchronously();
55 // Clears the delegate, so that any outstanding asynchronous load will not
56 // call the delegate on completion.
59 // Populates |uploads| with the |max_count| most recent uploads,
60 // in reverse chronological order.
61 // Must be called only after OnUploadListAvailable has been called.
62 void GetUploads(unsigned int max_count
, std::vector
<UploadInfo
>* uploads
);
65 virtual ~UploadList();
67 // Reads the upload log and stores the entries in |uploads_|.
68 virtual void LoadUploadList();
70 // Adds |info| to |uploads_|.
71 void AppendUploadInfo(const UploadInfo
& info
);
77 friend class base::RefCountedThreadSafe
<UploadList
>;
78 FRIEND_TEST_ALL_PREFIXES(UploadListTest
, ParseLogEntries
);
79 FRIEND_TEST_ALL_PREFIXES(UploadListTest
, ParseLogEntriesWithLocalId
);
81 // Manages the background thread work for LoadUploadListAsynchronously().
82 void LoadUploadListAndInformDelegateOfCompletion();
84 // Calls the delegate's callback method, if there is a delegate.
85 void InformDelegateOfCompletion();
87 // Parses upload log lines, converting them to UploadInfo entries.
88 void ParseLogEntries(const std::vector
<std::string
>& log_entries
);
90 std::vector
<UploadInfo
> uploads_
;
92 const base::FilePath upload_log_path_
;
94 DISALLOW_COPY_AND_ASSIGN(UploadList
);
97 #endif // CHROME_BROWSER_UPLOAD_LIST_H_