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

Unified Diff: net/base/load_state_change_coalescer.cc

Issue 939503004: Add LoadState reporting to the mojo proxy resolver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-resolver-mojo
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: net/base/load_state_change_coalescer.cc
diff --git a/net/base/load_state_change_coalescer.cc b/net/base/load_state_change_coalescer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2522b23345c079353951680ba704d88c75123735
--- /dev/null
+++ b/net/base/load_state_change_coalescer.cc
@@ -0,0 +1,42 @@
+// 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.
+
+#include "net/base/load_state_change_coalescer.h"
+
+#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
+
+namespace net {
+
+LoadStateChangeCoalescer::LoadStateChangeCoalescer(
+ const base::Callback<void(LoadState)>& callback,
+ const base::TimeDelta& timeout,
+ LoadState initial_load_state)
+ : callback_(callback),
+ timeout_(timeout),
+ committed_load_state_(initial_load_state),
+ pending_load_state_(initial_load_state) {
+}
+
+void LoadStateChangeCoalescer::LoadStateChanged(LoadState load_state) {
+ if (load_state == committed_load_state_) {
+ pending_load_state_change_.Cancel();
eroman 2015/03/06 05:13:01 Personally I think a OneShotTimer would be easier
Sam McNally 2015/03/06 09:33:02 Done.
+ return;
+ }
+ pending_load_state_ = load_state;
+ pending_load_state_change_.Reset(base::Bind(
eroman 2015/03/06 05:13:01 Won't this mean that If the load state is continuo
Sam McNally 2015/03/06 09:33:02 If we use a maximum delay, a continuously changing
+ &LoadStateChangeCoalescer::SendLoadStateChanged, base::Unretained(this)));
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, pending_load_state_change_.callback(), timeout_);
+}
+
+LoadStateChangeCoalescer::~LoadStateChangeCoalescer() = default;
+
+void LoadStateChangeCoalescer::SendLoadStateChanged() {
+ callback_.Run(pending_load_state_);
+ pending_load_state_change_.Cancel();
+ committed_load_state_ = pending_load_state_;
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698