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

Side by Side Diff: chrome/browser/devtools/devtools_network_interceptor.h

Issue 342473004: DevTools: make network conditions emulation scoped (browser) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename + fix nits + polish Created 6 years, 6 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 2014 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 CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_INTERCEPTOR_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_INTERCEPTOR_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/timer/timer.h"
15
16 class DevToolsNetworkConditions;
17 class DevToolsNetworkTransaction;
18
19 namespace base {
20 class TimeDelta;
21 class TimeTicks;
22 }
23
24 // DevToolsNetworkInterceptor emulates network conditions for transactions with
25 // specific client id.
26 class DevToolsNetworkInterceptor {
27
28 public:
29 DevToolsNetworkInterceptor();
30 virtual ~DevToolsNetworkInterceptor();
31
32 base::WeakPtr<DevToolsNetworkInterceptor> GetWeakPtr();
33
34 // Applies network emulation configuration.
35 void UpdateConditions(
36 const scoped_refptr<DevToolsNetworkConditions> conditions);
37
38 void AddTransaction(DevToolsNetworkTransaction* transaction);
39 void RemoveTransaction(DevToolsNetworkTransaction* transaction);
40
41 bool ShouldFail(const DevToolsNetworkTransaction* transaction);
42 bool ShouldThrottle(const DevToolsNetworkTransaction* transaction);
43 void ThrottleTransaction(DevToolsNetworkTransaction* transaction);
44
45 const DevToolsNetworkConditions* conditions() const {
46 return conditions_.get();
47 }
48
49 private:
50 scoped_refptr<DevToolsNetworkConditions> conditions_;
51
52 void UpdateThrottles();
53 void ArmTimer();
54 void OnTimer();
55
56 typedef std::set<DevToolsNetworkTransaction*> Transactions;
57 Transactions transactions_;
58
59 std::vector<DevToolsNetworkTransaction*> throttled_transactions_;
60 base::OneShotTimer<DevToolsNetworkInterceptor> timer_;
61 base::TimeTicks offset_;
62 base::TimeDelta tick_length_;
63 uint64_t last_tick_;
64
65 base::WeakPtrFactory<DevToolsNetworkInterceptor> weak_ptr_factory_;
66
67 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkInterceptor);
68 };
69
70 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_INTERCEPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698