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

Side by Side Diff: net/proxy/load_state_change_coalescer.h

Issue 1145153004: Split ProxyResolverV8Tracing into an implementation and a wrapper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « net/net.gypi ('k') | net/proxy/load_state_change_coalescer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef NET_PROXY_LOAD_STATE_CHANGE_COALESCER_H_
6 #define NET_PROXY_LOAD_STATE_CHANGE_COALESCER_H_
7
8 #include "base/cancelable_callback.h"
9 #include "base/time/time.h"
10 #include "base/timer/timer.h"
11 #include "net/base/load_states.h"
12
13 namespace net {
14
15 // A class that coalesces LoadState changes. When a new LoadState is reported,
16 // it becomes the pending LoadState and is queued for |timeout|. If the timeout
17 // elapses without another new LoadState, the pending LoadState becomes the
18 // committed LoadState and the callback is called with that LoadState. If a new
19 // LoadState is reported before the timeout has elapsed, the pending LoadState
20 // is discarded and the new LoadState becomes the new pending LoadState, unless
21 // it's the same as the committed LoadState, in which case no pending LoadState
22 // is queued.
23 class LoadStateChangeCoalescer {
24 public:
25 LoadStateChangeCoalescer(const base::Callback<void(LoadState)>& callback,
26 const base::TimeDelta& timeout,
27 LoadState initial_load_state);
28 ~LoadStateChangeCoalescer();
29
30 // Adds a LoadState change to the pipeline. If it isn't coalesced, |callback_|
31 // will be called with |load_state| after |timeout_|.
32 void LoadStateChanged(LoadState load_state);
33
34 private:
35 void SendLoadStateChanged();
36
37 // The callback to call to report a LoadState change.
38 const base::Callback<void(LoadState)> callback_;
39
40 // The amount of time for which a LoadState change can be coalesced.
41 const base::TimeDelta timeout_;
42
43 base::OneShotTimer<LoadStateChangeCoalescer> timer_;
44 LoadState committed_load_state_;
45 LoadState pending_load_state_;
46
47 DISALLOW_COPY_AND_ASSIGN(LoadStateChangeCoalescer);
48 };
49
50 } // namespace net
51
52 #endif // NET_PROXY_LOAD_STATE_CHANGE_COALESCER_H_
OLDNEW
« no previous file with comments | « net/net.gypi ('k') | net/proxy/load_state_change_coalescer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698