Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: components/upload_list/upload_list.h

Issue 1830383002: Fix thread safety issues with //components/upload_list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/upload_list/BUILD.gn ('k') | components/upload_list/upload_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
9
8 #include <string> 10 #include <string>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 18
18 namespace base { 19 namespace base {
19 class SequencedTaskRunner; 20 class SequencedTaskRunner;
20 class SequencedWorkerPool; 21 class SequencedWorkerPool;
21 } 22 }
22 23
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // loading is complete. 69 // loading is complete.
69 void LoadUploadListAsynchronously(); 70 void LoadUploadListAsynchronously();
70 71
71 // Clears the delegate, so that any outstanding asynchronous load will not 72 // Clears the delegate, so that any outstanding asynchronous load will not
72 // call the delegate on completion. 73 // call the delegate on completion.
73 void ClearDelegate(); 74 void ClearDelegate();
74 75
75 // Populates |uploads| with the |max_count| most recent uploads, 76 // Populates |uploads| with the |max_count| most recent uploads,
76 // in reverse chronological order. 77 // in reverse chronological order.
77 // Must be called only after OnUploadListAvailable has been called. 78 // Must be called only after OnUploadListAvailable has been called.
78 void GetUploads(unsigned int max_count, std::vector<UploadInfo>* uploads); 79 void GetUploads(size_t max_count, std::vector<UploadInfo>* uploads);
79 80
80 protected: 81 protected:
81 virtual ~UploadList(); 82 virtual ~UploadList();
82 83
83 // Reads the upload log and stores the entries in |uploads_|. 84 // Reads the upload log and stores the entries in |uploads|.
84 virtual void LoadUploadList(); 85 virtual void LoadUploadList(std::vector<UploadInfo>* uploads);
85
86 // Adds |info| to |uploads_|.
87 void AppendUploadInfo(const UploadInfo& info);
88
89 // Clear |uploads_|.
90 void ClearUploads();
91 86
92 private: 87 private:
93 friend class base::RefCountedThreadSafe<UploadList>; 88 friend class base::RefCountedThreadSafe<UploadList>;
94 FRIEND_TEST_ALL_PREFIXES(UploadListTest, ParseUploadTimeUploadId);
95 FRIEND_TEST_ALL_PREFIXES(UploadListTest, ParseUploadTimeUploadIdLocalId);
96 FRIEND_TEST_ALL_PREFIXES(UploadListTest, ParseUploadTimeUploadIdCaptureTime);
97 FRIEND_TEST_ALL_PREFIXES(UploadListTest, ParseLocalIdCaptureTime);
98 FRIEND_TEST_ALL_PREFIXES(UploadListTest,
99 ParseUploadTimeUploadIdLocalIdCaptureTime);
100 FRIEND_TEST_ALL_PREFIXES(UploadListTest, ParseMultipleEntries);
101 89
102 // Manages the background thread work for LoadUploadListAsynchronously(). 90 // Manages the background thread work for LoadUploadListAsynchronously().
103 void LoadUploadListAndInformDelegateOfCompletion( 91 void PerformLoadAndNotifyDelegate(
104 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 92 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
105 93
106 // Calls the delegate's callback method, if there is a delegate. 94 // Calls the delegate's callback method, if there is a delegate. Stores
107 void InformDelegateOfCompletion(); 95 // the newly loaded |uploads| into |uploads_| on the delegate's task runner.
96 void SetUploadsAndNotifyDelegate(std::vector<UploadInfo> uploads);
108 97
109 // Parses upload log lines, converting them to UploadInfo entries. 98 // Parses upload log lines, converting them to UploadInfo entries.
110 void ParseLogEntries(const std::vector<std::string>& log_entries); 99 void ParseLogEntries(const std::vector<std::string>& log_entries,
100 std::vector<UploadInfo>* uploads);
111 101
102 // |thread_checker_| ensures that |uploads_| is only set from the task runner
103 // that created the UploadList.
104 base::ThreadChecker thread_checker_;
112 std::vector<UploadInfo> uploads_; 105 std::vector<UploadInfo> uploads_;
113 Delegate* delegate_; 106 Delegate* delegate_;
107
114 const base::FilePath upload_log_path_; 108 const base::FilePath upload_log_path_;
115 109
116 base::ThreadChecker thread_checker_;
117 scoped_refptr<base::SequencedWorkerPool> worker_pool_; 110 scoped_refptr<base::SequencedWorkerPool> worker_pool_;
118 111
119 DISALLOW_COPY_AND_ASSIGN(UploadList); 112 DISALLOW_COPY_AND_ASSIGN(UploadList);
120 }; 113 };
121 114
122 #endif // COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_ 115 #endif // COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_
OLDNEW
« no previous file with comments | « components/upload_list/BUILD.gn ('k') | components/upload_list/upload_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698