Remove the dependency of PasswordStore on BrowserContextKeyedService
[chromium-blink-merge.git] / chrome / browser / upload_list.h
blobe62288d4f41950d7cec027d453d20089a15bb22f
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_
8 #include <string>
9 #include <vector>
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
17 // time,id
18 // time,id
19 // etc.
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.
23 class UploadList : public base::RefCountedThreadSafe<UploadList> {
24 public:
25 struct UploadInfo {
26 UploadInfo(const std::string& c, const base::Time& t);
27 ~UploadInfo();
29 std::string id;
30 base::Time time;
33 class Delegate {
34 public:
35 // Invoked when the upload list has been loaded. Will be called on the
36 // UI thread.
37 virtual void OnUploadListAvailable() = 0;
39 protected:
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.
52 void ClearDelegate();
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);
59 protected:
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);
68 // Clear |uploads_|.
69 void ClearUploads();
71 private:
72 friend class base::RefCountedThreadSafe<UploadList>;
73 FRIEND_TEST_ALL_PREFIXES(UploadListTest, ParseLogEntries);
75 // Manages the background thread work for LoadUploadListAsynchronously().
76 void LoadUploadListAndInformDelegateOfCompletion();
78 // Calls the delegate's callback method, if there is a delegate.
79 void InformDelegateOfCompletion();
81 // Parses upload log lines, converting them to UploadInfo entries.
82 void ParseLogEntries(const std::vector<std::string>& log_entries);
84 std::vector<UploadInfo> uploads_;
85 Delegate* delegate_;
86 const base::FilePath upload_log_path_;
88 DISALLOW_COPY_AND_ASSIGN(UploadList);
91 #endif // CHROME_BROWSER_UPLOAD_LIST_H_