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.
5 #include "net/proxy/load_state_change_coalescer.h"
9 LoadStateChangeCoalescer::LoadStateChangeCoalescer(
10 const base::Callback
<void(LoadState
)>& callback
,
11 const base::TimeDelta
& timeout
,
12 LoadState initial_load_state
)
13 : callback_(callback
),
15 committed_load_state_(initial_load_state
),
16 pending_load_state_(initial_load_state
) {
19 void LoadStateChangeCoalescer::LoadStateChanged(LoadState load_state
) {
20 if (load_state
== committed_load_state_
) {
24 pending_load_state_
= load_state
;
25 timer_
.Start(FROM_HERE
, timeout_
, this,
26 &LoadStateChangeCoalescer::SendLoadStateChanged
);
29 LoadStateChangeCoalescer::~LoadStateChangeCoalescer() = default;
31 void LoadStateChangeCoalescer::SendLoadStateChanged() {
32 committed_load_state_
= pending_load_state_
;
33 callback_
.Run(pending_load_state_
);