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
23 class UploadList
: public base::RefCountedThreadSafe
<UploadList
> {
26 UploadInfo(const std::string
& c
, const base::Time
& t
);
35 // Invoked when the upload list has been loaded. Will be called on the
37 virtual void OnUploadListAvailable() = 0;
40 virtual ~Delegate() {}
43 // Creates a new upload list with the given callback delegate.
44 UploadList(Delegate
* delegate
, const base::FilePath
& upload_log_path
);
46 // Starts loading the upload list. OnUploadListAvailable will be called when
47 // loading is complete.
48 void LoadUploadListAsynchronously();
50 // Clears the delegate, so that any outstanding asynchronous load will not
51 // call the delegate on completion.
54 // Populates |uploads| with the |max_count| most recent uploads,
55 // in reverse chronological order.
56 // Must be called only after OnUploadListAvailable has been called.
57 void GetUploads(unsigned int max_count
, std::vector
<UploadInfo
>* uploads
);
60 virtual ~UploadList();
62 // Reads the upload log and stores the entries in |uploads_|.
63 virtual void LoadUploadList();
65 // Adds |info| to |uploads_|.
66 void AppendUploadInfo(const UploadInfo
& info
);
69 friend class base::RefCountedThreadSafe
<UploadList
>;
70 FRIEND_TEST_ALL_PREFIXES(UploadListTest
, ParseLogEntries
);
72 // Manages the background thread work for LoadUploadListAsynchronously().
73 void LoadUploadListAndInformDelegateOfCompletion();
75 // Calls the delegate's callback method, if there is a delegate.
76 void InformDelegateOfCompletion();
78 // Parses upload log lines, converting them to UploadInfo entries.
79 void ParseLogEntries(const std::vector
<std::string
>& log_entries
);
81 std::vector
<UploadInfo
> uploads_
;
83 const base::FilePath upload_log_path_
;
85 DISALLOW_COPY_AND_ASSIGN(UploadList
);
88 #endif // CHROME_BROWSER_UPLOAD_LIST_H_