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