Index: net/base/load_state_change_coalescer.h |
diff --git a/net/base/load_state_change_coalescer.h b/net/base/load_state_change_coalescer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b7591a23d833f32147e79aaca206df06986e000c |
--- /dev/null |
+++ b/net/base/load_state_change_coalescer.h |
@@ -0,0 +1,52 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_BASE_LOAD_STATE_CHANGE_COALESCER_H_ |
eroman
2015/03/06 05:13:01
please move this into the net/proxy directory. Thi
Sam McNally
2015/03/06 09:33:02
Done.
|
+#define NET_BASE_LOAD_STATE_CHANGE_COALESCER_H_ |
+ |
+#include "base/cancelable_callback.h" |
+#include "base/time/time.h" |
+#include "net/base/load_states.h" |
+#include "net/base/net_export.h" |
+ |
+namespace net { |
+ |
+// A class that coalesces LoadState changes. When a new LoadState is reported, |
+// it becomes the pending LoadState and is queued for |timeout|. If the timeout |
+// elapses without another new LoadState, the pending LoadState becomes the |
+// committed LoadState and the callback is called with that LoadState. If a new |
+// LoadState is reported before the timeout has elapsed, the pending LoadState |
eroman
2015/03/06 05:13:01
"LoadState is discarded"
Sam McNally
2015/03/06 09:33:02
Done.
|
+// discarded and the new LoadState becomes the new pending LoadState, unless |
+// it's the same as the committed LoadState, in which case no pending LoadState |
+// is queued. |
+class NET_EXPORT_PRIVATE LoadStateChangeCoalescer { |
+ public: |
+ LoadStateChangeCoalescer(const base::Callback<void(LoadState)>& callback, |
+ const base::TimeDelta& timeout, |
+ LoadState initial_load_state); |
+ ~LoadStateChangeCoalescer(); |
+ |
+ // Adds a LoadState change to the pipeline. If it isn't coalesced, |callback_| |
+ // will be called with |load_state| after |timeout_|. |
+ void LoadStateChanged(LoadState load_state); |
+ |
+ private: |
+ void SendLoadStateChanged(); |
+ |
+ // The callback to call to report a LoadState change. |
+ const base::Callback<void(LoadState)> callback_; |
+ |
+ // The amount of time for which a LoadState change can be coalesced. |
+ const base::TimeDelta timeout_; |
+ |
+ base::CancelableClosure pending_load_state_change_; |
+ LoadState committed_load_state_; |
+ LoadState pending_load_state_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(LoadStateChangeCoalescer); |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_BASE_LOAD_STATE_CHANGE_COALESCER_H_ |