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

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

Issue 324953002: DevToolsNetworkController: support "limit throughput" network condition. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolved TODO 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
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. 56 // |client_id| should be DevToolsAgentHost GUID.
47 void SetNetworkState( 57 void SetNetworkState(
48 const std::string& client_id, 58 const std::string& client_id,
49 const scoped_refptr<DevToolsNetworkConditions> conditions); 59 const scoped_refptr<DevToolsNetworkConditions> conditions);
50 60
51 bool ShouldFail(const net::HttpRequestInfo* request); 61 bool ShouldFail(const net::HttpRequestInfo* request);
62 bool ShouldThrottle(const net::HttpRequestInfo* request);
63 void ThrottleTransaction(DevToolsNetworkTransaction* transaction,
64 int64_t penalty);
52 65
53 protected: 66 protected:
54 friend class test::DevToolsNetworkControllerHelper; 67 friend class test::DevToolsNetworkControllerHelper;
55 68
56 private: 69 private:
57 // Controller must be constructed on IO thread. 70 // Controller must be constructed on IO thread.
58 base::ThreadChecker thread_checker_; 71 base::ThreadChecker thread_checker_;
59 72
60 typedef scoped_refptr<DevToolsNetworkConditions> Conditions; 73 typedef scoped_refptr<DevToolsNetworkConditions> Conditions;
61 74
62 void SetNetworkStateOnIO( 75 void SetNetworkStateOnIO(
63 const std::string& client_id, 76 const std::string& client_id,
64 const Conditions conditions); 77 const Conditions conditions);
65 78
66 typedef std::set<DevToolsNetworkTransaction*> Transactions; 79 typedef std::set<DevToolsNetworkTransaction*> Transactions;
67 Transactions transactions_; 80 Transactions transactions_;
68 81
69 // Active client id. 82 // Active client id.
70 std::string active_client_id_; 83 std::string active_client_id_;
71 84
72 // Active network conditions. 85 // Active network conditions.
73 Conditions conditions_; 86 Conditions conditions_;
74 87
88 void UpdateThrottles();
89 void FireThrottledCallbacks();
90 void CancelThrottles();
91 void ArmTimer();
92 void OnTimer();
93
94 typedef std::vector<Throttle> Throttles;
95 Throttles throttles_;
96 base::OneShotTimer<DevToolsNetworkController> timer_;
97 base::TimeTicks offset_;
98 base::TimeDelta tick_length_;
99 uint64_t last_tick_;
100
75 base::WeakPtrFactory<DevToolsNetworkController> weak_ptr_factory_; 101 base::WeakPtrFactory<DevToolsNetworkController> weak_ptr_factory_;
76 102
77 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController); 103 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController);
78 }; 104 };
79 105
80 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_ 106 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698