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

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: Addressed comments 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>
9 #include <string> 8 #include <string>
10 #include <vector>
11 9
10 #include "base/containers/scoped_ptr_hash_map.h"
12 #include "base/macros.h" 11 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
16 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
17 #include "base/timer/timer.h"
18 16
19 class DevToolsNetworkConditions; 17 class DevToolsNetworkConditions;
18 class DevToolsNetworkRealm;
20 class DevToolsNetworkTransaction; 19 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 20
37 namespace test { 21 namespace test {
38 class DevToolsNetworkControllerHelper; 22 class DevToolsNetworkControllerHelper;
39 } 23 }
40 24
41 // DevToolsNetworkController tracks DevToolsNetworkTransactions. 25 // DevToolsNetworkController tracks DevToolsNetworkTransactions.
42 class DevToolsNetworkController { 26 class DevToolsNetworkController {
43 27
44 public: 28 public:
45 DevToolsNetworkController(); 29 DevToolsNetworkController();
46 virtual ~DevToolsNetworkController(); 30 virtual ~DevToolsNetworkController();
47 31
48 void AddTransaction(DevToolsNetworkTransaction* transaction);
49
50 void RemoveTransaction(DevToolsNetworkTransaction* transaction);
51
52 // Applies network emulation configuration. 32 // Applies network emulation configuration.
53 void SetNetworkState( 33 void SetNetworkState(
34 const std::string& client_id,
54 const scoped_refptr<DevToolsNetworkConditions> conditions); 35 const scoped_refptr<DevToolsNetworkConditions> conditions);
55 36
56 bool ShouldFail(const net::HttpRequestInfo* request); 37 base::WeakPtr<DevToolsNetworkRealm> GetRealm(
57 bool ShouldThrottle(const net::HttpRequestInfo* request); 38 DevToolsNetworkTransaction* transaction);
58 void ThrottleTransaction(DevToolsNetworkTransaction* transaction);
59 39
60 protected: 40 protected:
61 friend class test::DevToolsNetworkControllerHelper; 41 friend class test::DevToolsNetworkControllerHelper;
62 42
63 private: 43 private:
64 // Controller must be constructed on IO thread. 44 // Controller must be constructed on IO thread.
65 base::ThreadChecker thread_checker_; 45 base::ThreadChecker thread_checker_;
66 46
67 typedef scoped_refptr<DevToolsNetworkConditions> Conditions; 47 void SetNetworkStateOnIO(
48 const std::string& client_id,
49 const scoped_refptr<DevToolsNetworkConditions> conditions);
68 50
69 void SetNetworkStateOnIO(const Conditions conditions); 51 typedef scoped_ptr<DevToolsNetworkRealm> Realm;
70 52 Realm default_realm_;
71 typedef std::set<DevToolsNetworkTransaction*> Transactions; 53 Realm appcache_realm_;
72 Transactions transactions_; 54 typedef base::ScopedPtrHashMap<std::string, DevToolsNetworkRealm> Realms;
73 55 Realms realms_;
74 Conditions conditions_;
75
76 void UpdateThrottles();
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_;
85 56
86 base::WeakPtrFactory<DevToolsNetworkController> weak_ptr_factory_; 57 base::WeakPtrFactory<DevToolsNetworkController> weak_ptr_factory_;
87 58
88 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController); 59 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController);
89 }; 60 };
90 61
91 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_ 62 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698