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

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: Addressed comments + refactoring 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
34 // DevToolsNetworkController tracks DevToolsNetworkTransactions. 40 // DevToolsNetworkController tracks DevToolsNetworkTransactions.
35 class DevToolsNetworkController { 41 class DevToolsNetworkController {
36 42
37 public: 43 public:
38 DevToolsNetworkController(); 44 DevToolsNetworkController();
39 virtual ~DevToolsNetworkController(); 45 virtual ~DevToolsNetworkController();
40 46
41 void AddTransaction(DevToolsNetworkTransaction* transaction); 47 void AddTransaction(DevToolsNetworkTransaction* transaction);
42 48
43 void RemoveTransaction(DevToolsNetworkTransaction* transaction); 49 void RemoveTransaction(DevToolsNetworkTransaction* transaction);
44 50
45 // Applies network emulation configuration. 51 // Applies network emulation configuration.
46 // |client_id| should be DevToolsAgentHost GUID.
47 void SetNetworkState( 52 void SetNetworkState(
48 const std::string& client_id,
49 const scoped_refptr<DevToolsNetworkConditions> conditions); 53 const scoped_refptr<DevToolsNetworkConditions> conditions);
50 54
51 bool ShouldFail(const net::HttpRequestInfo* request); 55 bool ShouldFail(const net::HttpRequestInfo* request);
56 bool ShouldThrottle(const net::HttpRequestInfo* request);
57 void ThrottleTransaction(DevToolsNetworkTransaction* transaction);
52 58
53 protected: 59 protected:
54 friend class test::DevToolsNetworkControllerHelper; 60 friend class test::DevToolsNetworkControllerHelper;
55 61
56 private: 62 private:
57 // Controller must be constructed on IO thread. 63 // Controller must be constructed on IO thread.
58 base::ThreadChecker thread_checker_; 64 base::ThreadChecker thread_checker_;
59 65
60 typedef scoped_refptr<DevToolsNetworkConditions> Conditions; 66 typedef scoped_refptr<DevToolsNetworkConditions> Conditions;
61 67
62 void SetNetworkStateOnIO( 68 void SetNetworkStateOnIO(const Conditions conditions);
63 const std::string& client_id,
64 const Conditions conditions);
65 69
66 typedef std::set<DevToolsNetworkTransaction*> Transactions; 70 typedef std::set<DevToolsNetworkTransaction*> Transactions;
67 Transactions transactions_; 71 Transactions transactions_;
68 72
69 // Active client id. 73 Conditions conditions_;
70 std::string active_client_id_;
71 74
72 // Active network conditions. 75 void UpdateThrottles();
73 Conditions conditions_; 76 void ArmTimer();
77 void OnTimer();
78
79 typedef std::vector<DevToolsNetworkTransaction*> Throttles;
80 Throttles throttles_;
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698