blob: a9edd0fe31d5d10cac0f9bb15c603243018feb8c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_
#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_
#include <set>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "base/timer/timer.h"
class DevToolsNetworkConditions;
class DevToolsNetworkTransaction;
class GURL;
class Profile;
namespace base {
class TimeDelta;
class TimeTicks;
}
namespace content {
class ResourceContext;
}
namespace net {
struct HttpRequestInfo;
}
namespace test {
class DevToolsNetworkControllerHelper;
}
// DevToolsNetworkController tracks DevToolsNetworkTransactions.
class DevToolsNetworkController {
public:
DevToolsNetworkController();
virtual ~DevToolsNetworkController();
void AddTransaction(DevToolsNetworkTransaction* transaction);
void RemoveTransaction(DevToolsNetworkTransaction* transaction);
// Applies network emulation configuration.
void SetNetworkState(
const scoped_refptr<DevToolsNetworkConditions> conditions);
bool ShouldFail(const net::HttpRequestInfo* request);
bool ShouldThrottle(const net::HttpRequestInfo* request);
void ThrottleTransaction(DevToolsNetworkTransaction* transaction);
protected:
friend class test::DevToolsNetworkControllerHelper;
private:
// Controller must be constructed on IO thread.
base::ThreadChecker thread_checker_;
typedef scoped_refptr<DevToolsNetworkConditions> Conditions;
void SetNetworkStateOnIO(const Conditions conditions);
typedef std::set<DevToolsNetworkTransaction*> Transactions;
Transactions transactions_;
Conditions conditions_;
void UpdateThrottles();
void ArmTimer();
void OnTimer();
std::vector<DevToolsNetworkTransaction*> throttled_transactions_;
base::OneShotTimer<DevToolsNetworkController> timer_;
base::TimeTicks offset_;
base::TimeDelta tick_length_;
uint64_t last_tick_;
base::WeakPtrFactory<DevToolsNetworkController> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController);
};
#endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_
|