[Presentation API, Android] Implement basic messaging
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_network_interceptor.h
blob971f585229755c6a3e19d6f203627e19bb8d54cb
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_INTERCEPTOR_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_INTERCEPTOR_H_
8 #include <set>
9 #include <string>
10 #include <utility>
11 #include <vector>
13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/timer/timer.h"
17 class DevToolsNetworkConditions;
18 class DevToolsNetworkTransaction;
20 namespace base {
21 class TimeDelta;
22 class TimeTicks;
25 // DevToolsNetworkInterceptor emulates network conditions for transactions with
26 // specific client id.
27 class DevToolsNetworkInterceptor {
29 public:
30 DevToolsNetworkInterceptor();
31 virtual ~DevToolsNetworkInterceptor();
33 base::WeakPtr<DevToolsNetworkInterceptor> GetWeakPtr();
35 // Applies network emulation configuration.
36 void UpdateConditions(scoped_ptr<DevToolsNetworkConditions> conditions);
38 void AddTransaction(DevToolsNetworkTransaction* transaction);
39 void RemoveTransaction(DevToolsNetworkTransaction* transaction);
41 bool ShouldFail(const DevToolsNetworkTransaction* transaction);
42 bool ShouldThrottle(const DevToolsNetworkTransaction* transaction);
43 void ThrottleTransaction(DevToolsNetworkTransaction* transaction, bool start);
45 const DevToolsNetworkConditions* conditions() const {
46 return conditions_.get();
49 private:
50 scoped_ptr<DevToolsNetworkConditions> conditions_;
52 void UpdateThrottledTransactions(base::TimeTicks now);
53 void UpdateSuspendedTransactions(base::TimeTicks now);
54 void ArmTimer(base::TimeTicks now);
55 void OnTimer();
57 void FireThrottledCallback(DevToolsNetworkTransaction* transaction);
59 typedef std::set<DevToolsNetworkTransaction*> Transactions;
60 Transactions transactions_;
62 // Transactions suspended for a "latency" period.
63 typedef std::pair<DevToolsNetworkTransaction*, int64_t> SuspendedTransaction;
64 typedef std::vector<SuspendedTransaction> SuspendedTransactions;
65 SuspendedTransactions suspended_transactions_;
67 // Transactions waiting certain amount of transfer to be "accounted".
68 std::vector<DevToolsNetworkTransaction*> throttled_transactions_;
70 base::OneShotTimer<DevToolsNetworkInterceptor> timer_;
71 base::TimeTicks offset_;
72 base::TimeDelta tick_length_;
73 base::TimeDelta latency_length_;
74 uint64_t last_tick_;
76 base::WeakPtrFactory<DevToolsNetworkInterceptor> weak_ptr_factory_;
78 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkInterceptor);
81 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_INTERCEPTOR_H_