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

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

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

Powered by Google App Engine
This is Rietveld 408576698