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

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: Add race condition test 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
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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
15 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
16 #include "base/time/time.h" 15 #include "base/time/time.h"
17 16
18 namespace base { 17 namespace base {
19 class SequencedTaskRunner; 18 class SequencedTaskRunner;
20 class SequencedWorkerPool; 19 class SequencedWorkerPool;
21 } 20 }
22 21
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // loading is complete. 67 // loading is complete.
69 void LoadUploadListAsynchronously(); 68 void LoadUploadListAsynchronously();
70 69
71 // Clears the delegate, so that any outstanding asynchronous load will not 70 // Clears the delegate, so that any outstanding asynchronous load will not
72 // call the delegate on completion. 71 // call the delegate on completion.
73 void ClearDelegate(); 72 void ClearDelegate();
74 73
75 // Populates |uploads| with the |max_count| most recent uploads, 74 // Populates |uploads| with the |max_count| most recent uploads,
76 // in reverse chronological order. 75 // in reverse chronological order.
77 // Must be called only after OnUploadListAvailable has been called. 76 // Must be called only after OnUploadListAvailable has been called.
78 void GetUploads(unsigned int max_count, std::vector<UploadInfo>* uploads); 77 void GetUploads(size_t max_count, std::vector<UploadInfo>* uploads);
Mark Mentovai 2016/03/25 18:26:56 #include <stddef.h> here now (and remove it from u
Robert Sesek 2016/03/25 18:45:56 Done.
79 78
80 protected: 79 protected:
81 virtual ~UploadList(); 80 virtual ~UploadList();
82 81
83 // Reads the upload log and stores the entries in |uploads_|. 82 // Reads the upload log and stores the entries in |uploads|.
84 virtual void LoadUploadList(); 83 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 84
92 private: 85 private:
93 friend class base::RefCountedThreadSafe<UploadList>; 86 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 87
102 // Manages the background thread work for LoadUploadListAsynchronously(). 88 // Manages the background thread work for LoadUploadListAsynchronously().
103 void LoadUploadListAndInformDelegateOfCompletion( 89 void PerformLoadAndNotifyDelegate(
104 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 90 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
105 91
106 // Calls the delegate's callback method, if there is a delegate. 92 // Calls the delegate's callback method, if there is a delegate. Stores
107 void InformDelegateOfCompletion(); 93 // the newly loaded |uploads| into |uploads_| on the delegate's task runner.
94 void SetUploadsAndNotifyDelegate(std::vector<UploadInfo> uploads);
108 95
109 // Parses upload log lines, converting them to UploadInfo entries. 96 // Parses upload log lines, converting them to UploadInfo entries.
110 void ParseLogEntries(const std::vector<std::string>& log_entries); 97 void ParseLogEntries(const std::vector<std::string>& log_entries,
98 std::vector<UploadInfo>* uploads);
111 99
100 // |thread_checker_| ensures that |uploads_| is only set from the task runner
101 // that created the UploadList.
102 base::ThreadChecker thread_checker_;
112 std::vector<UploadInfo> uploads_; 103 std::vector<UploadInfo> uploads_;
113 Delegate* delegate_; 104 Delegate* delegate_;
105
114 const base::FilePath upload_log_path_; 106 const base::FilePath upload_log_path_;
115 107
116 base::ThreadChecker thread_checker_;
117 scoped_refptr<base::SequencedWorkerPool> worker_pool_; 108 scoped_refptr<base::SequencedWorkerPool> worker_pool_;
118 109
119 DISALLOW_COPY_AND_ASSIGN(UploadList); 110 DISALLOW_COPY_AND_ASSIGN(UploadList);
120 }; 111 };
121 112
122 #endif // COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_ 113 #endif // COMPONENTS_UPLOAD_LIST_UPLOAD_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698