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: 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, 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/base/load_state_change_coalescer.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9
10 namespace net {
11
12 LoadStateChangeCoalescer::LoadStateChangeCoalescer(
13 const base::Callback<void(LoadState)>& callback,
14 const base::TimeDelta& timeout,
15 LoadState initial_load_state)
16 : callback_(callback),
17 timeout_(timeout),
18 committed_load_state_(initial_load_state),
19 pending_load_state_(initial_load_state) {
20 }
21
22 void LoadStateChangeCoalescer::LoadStateChanged(LoadState load_state) {
23 if (load_state == committed_load_state_) {
24 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.
25 return;
26 }
27 pending_load_state_ = load_state;
28 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
29 &LoadStateChangeCoalescer::SendLoadStateChanged, base::Unretained(this)));
30 base::MessageLoop::current()->PostDelayedTask(
31 FROM_HERE, pending_load_state_change_.callback(), timeout_);
32 }
33
34 LoadStateChangeCoalescer::~LoadStateChangeCoalescer() = default;
35
36 void LoadStateChangeCoalescer::SendLoadStateChanged() {
37 callback_.Run(pending_load_state_);
38 pending_load_state_change_.Cancel();
39 committed_load_state_ = pending_load_state_;
40 }
41
42 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698