| OLD | NEW |
| (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/proxy/load_state_change_coalescer.h" | |
| 6 | |
| 7 namespace net { | |
| 8 | |
| 9 LoadStateChangeCoalescer::LoadStateChangeCoalescer( | |
| 10 const base::Callback<void(LoadState)>& callback, | |
| 11 const base::TimeDelta& timeout, | |
| 12 LoadState initial_load_state) | |
| 13 : callback_(callback), | |
| 14 timeout_(timeout), | |
| 15 committed_load_state_(initial_load_state), | |
| 16 pending_load_state_(initial_load_state) { | |
| 17 } | |
| 18 | |
| 19 void LoadStateChangeCoalescer::LoadStateChanged(LoadState load_state) { | |
| 20 if (load_state == committed_load_state_) { | |
| 21 timer_.Stop(); | |
| 22 return; | |
| 23 } | |
| 24 pending_load_state_ = load_state; | |
| 25 timer_.Start(FROM_HERE, timeout_, this, | |
| 26 &LoadStateChangeCoalescer::SendLoadStateChanged); | |
| 27 } | |
| 28 | |
| 29 LoadStateChangeCoalescer::~LoadStateChangeCoalescer() = default; | |
| 30 | |
| 31 void LoadStateChangeCoalescer::SendLoadStateChanged() { | |
| 32 committed_load_state_ = pending_load_state_; | |
| 33 callback_.Run(pending_load_state_); | |
| 34 } | |
| 35 | |
| 36 } // namespace net | |
| OLD | NEW |