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

Side by Side Diff: base/task/cancelable_task_tracker.h

Issue 2830093003: Replace uses of hash_map in //base (Closed)
Patch Set: WebKit callers Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // CancelableTaskTracker posts tasks (in the form of a Closure) to a 5 // CancelableTaskTracker posts tasks (in the form of a Closure) to a
6 // TaskRunner, and is able to cancel the task later if it's not needed 6 // TaskRunner, and is able to cancel the task later if it's not needed
7 // anymore. On destruction, CancelableTaskTracker will cancel all 7 // anymore. On destruction, CancelableTaskTracker will cancel all
8 // tracked tasks. 8 // tracked tasks.
9 // 9 //
10 // Each cancelable task can be associated with a reply (also a Closure). After 10 // Each cancelable task can be associated with a reply (also a Closure). After
(...skipping 25 matching lines...) Expand all
36 #ifndef BASE_TASK_CANCELABLE_TASK_TRACKER_H_ 36 #ifndef BASE_TASK_CANCELABLE_TASK_TRACKER_H_
37 #define BASE_TASK_CANCELABLE_TASK_TRACKER_H_ 37 #define BASE_TASK_CANCELABLE_TASK_TRACKER_H_
38 38
39 #include <stdint.h> 39 #include <stdint.h>
40 40
41 #include <utility> 41 #include <utility>
42 42
43 #include "base/base_export.h" 43 #include "base/base_export.h"
44 #include "base/bind.h" 44 #include "base/bind.h"
45 #include "base/callback.h" 45 #include "base/callback.h"
46 #include "base/containers/hash_tables.h" 46 #include "base/containers/small_map.h"
47 #include "base/macros.h" 47 #include "base/macros.h"
48 #include "base/memory/weak_ptr.h" 48 #include "base/memory/weak_ptr.h"
49 #include "base/post_task_and_reply_with_result_internal.h" 49 #include "base/post_task_and_reply_with_result_internal.h"
50 #include "base/sequence_checker.h" 50 #include "base/sequence_checker.h"
51 51
52 namespace tracked_objects { 52 namespace tracked_objects {
53 class Location; 53 class Location;
54 } // namespace tracked_objects 54 } // namespace tracked_objects
55 55
56 namespace base { 56 namespace base {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 void TryCancelAll(); 135 void TryCancelAll();
136 136
137 // Returns true iff there are in-flight tasks that are still being 137 // Returns true iff there are in-flight tasks that are still being
138 // tracked. 138 // tracked.
139 bool HasTrackedTasks() const; 139 bool HasTrackedTasks() const;
140 140
141 private: 141 private:
142 void Track(TaskId id, CancellationFlag* flag); 142 void Track(TaskId id, CancellationFlag* flag);
143 void Untrack(TaskId id); 143 void Untrack(TaskId id);
144 144
145 hash_map<TaskId, CancellationFlag*> task_flags_; 145 // Typically the number of tasks are 0-2 and occationally 3-4. But since
146 // this is a general API that could be used in unexpected ways, use a
147 // small_map instead of a flat_map to avoid falling over if there are many
148 // tasks.
149 base::small_map<std::map<TaskId, CancellationFlag*>, 4> task_flags_;
Łukasz Anforowicz 2017/04/24 18:46:10 optional nit: I notice that the declaration above
146 150
147 TaskId next_id_; 151 TaskId next_id_;
148 SequenceChecker sequence_checker_; 152 SequenceChecker sequence_checker_;
149 153
150 WeakPtrFactory<CancelableTaskTracker> weak_factory_; 154 WeakPtrFactory<CancelableTaskTracker> weak_factory_;
151 155
152 DISALLOW_COPY_AND_ASSIGN(CancelableTaskTracker); 156 DISALLOW_COPY_AND_ASSIGN(CancelableTaskTracker);
153 }; 157 };
154 158
155 } // namespace base 159 } // namespace base
156 160
157 #endif // BASE_TASK_CANCELABLE_TASK_TRACKER_H_ 161 #endif // BASE_TASK_CANCELABLE_TASK_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698