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 #include <vector> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "base/timer/timer.h" |
16 | 18 |
17 class DevToolsNetworkConditions; | 19 class DevToolsNetworkConditions; |
18 class DevToolsNetworkTransaction; | 20 class DevToolsNetworkTransaction; |
19 class GURL; | 21 class GURL; |
20 class Profile; | 22 class Profile; |
21 | 23 |
| 24 namespace base { |
| 25 class TimeDelta; |
| 26 class TimeTicks; |
| 27 } |
| 28 |
22 namespace content { | 29 namespace content { |
23 class ResourceContext; | 30 class ResourceContext; |
24 } | 31 } |
25 | 32 |
26 namespace net { | 33 namespace net { |
27 struct HttpRequestInfo; | 34 struct HttpRequestInfo; |
28 } | 35 } |
29 | 36 |
30 namespace test { | 37 namespace test { |
31 class DevToolsNetworkControllerHelper; | 38 class DevToolsNetworkControllerHelper; |
32 } | 39 } |
33 | 40 |
34 // DevToolsNetworkController tracks DevToolsNetworkTransactions. | 41 // DevToolsNetworkController tracks DevToolsNetworkTransactions. |
35 class DevToolsNetworkController { | 42 class DevToolsNetworkController { |
36 | 43 |
37 public: | 44 public: |
38 DevToolsNetworkController(); | 45 DevToolsNetworkController(); |
39 virtual ~DevToolsNetworkController(); | 46 virtual ~DevToolsNetworkController(); |
40 | 47 |
41 void AddTransaction(DevToolsNetworkTransaction* transaction); | 48 void AddTransaction(DevToolsNetworkTransaction* transaction); |
42 | 49 |
43 void RemoveTransaction(DevToolsNetworkTransaction* transaction); | 50 void RemoveTransaction(DevToolsNetworkTransaction* transaction); |
44 | 51 |
45 // Applies network emulation configuration. | 52 // Applies network emulation configuration. |
46 // |client_id| should be DevToolsAgentHost GUID. | |
47 void SetNetworkState( | 53 void SetNetworkState( |
48 const std::string& client_id, | |
49 const scoped_refptr<DevToolsNetworkConditions> conditions); | 54 const scoped_refptr<DevToolsNetworkConditions> conditions); |
50 | 55 |
51 bool ShouldFail(const net::HttpRequestInfo* request); | 56 bool ShouldFail(const net::HttpRequestInfo* request); |
| 57 bool ShouldThrottle(const net::HttpRequestInfo* request); |
| 58 void ThrottleTransaction(DevToolsNetworkTransaction* transaction); |
52 | 59 |
53 protected: | 60 protected: |
54 friend class test::DevToolsNetworkControllerHelper; | 61 friend class test::DevToolsNetworkControllerHelper; |
55 | 62 |
56 private: | 63 private: |
57 // Controller must be constructed on IO thread. | 64 // Controller must be constructed on IO thread. |
58 base::ThreadChecker thread_checker_; | 65 base::ThreadChecker thread_checker_; |
59 | 66 |
60 typedef scoped_refptr<DevToolsNetworkConditions> Conditions; | 67 typedef scoped_refptr<DevToolsNetworkConditions> Conditions; |
61 | 68 |
62 void SetNetworkStateOnIO( | 69 void SetNetworkStateOnIO(const Conditions conditions); |
63 const std::string& client_id, | |
64 const Conditions conditions); | |
65 | 70 |
66 typedef std::set<DevToolsNetworkTransaction*> Transactions; | 71 typedef std::set<DevToolsNetworkTransaction*> Transactions; |
67 Transactions transactions_; | 72 Transactions transactions_; |
68 | 73 |
69 // Active client id. | 74 Conditions conditions_; |
70 std::string active_client_id_; | |
71 | 75 |
72 // Active network conditions. | 76 void UpdateThrottles(); |
73 Conditions conditions_; | 77 void ArmTimer(); |
| 78 void OnTimer(); |
| 79 |
| 80 std::vector<DevToolsNetworkTransaction*> throttled_transactions_; |
| 81 base::OneShotTimer<DevToolsNetworkController> timer_; |
| 82 base::TimeTicks offset_; |
| 83 base::TimeDelta tick_length_; |
| 84 uint64_t last_tick_; |
74 | 85 |
75 base::WeakPtrFactory<DevToolsNetworkController> weak_ptr_factory_; | 86 base::WeakPtrFactory<DevToolsNetworkController> weak_ptr_factory_; |
76 | 87 |
77 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController); | 88 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController); |
78 }; | 89 }; |
79 | 90 |
80 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_ | 91 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_ |
OLD | NEW |