devtools_network_controller.h revision 116680a4aac90f2aa7413d9095a592090648e557
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.
4
5#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_
6#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_
7
8#include <string>
9
10#include "base/containers/scoped_ptr_hash_map.h"
11#include "base/macros.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/memory/weak_ptr.h"
14#include "base/threading/thread_checker.h"
15
16class DevToolsNetworkConditions;
17class DevToolsNetworkInterceptor;
18class DevToolsNetworkTransaction;
19
20namespace test {
21class DevToolsNetworkControllerHelper;
22}
23
24// DevToolsNetworkController tracks DevToolsNetworkTransactions.
25class DevToolsNetworkController {
26
27 public:
28  DevToolsNetworkController();
29  virtual ~DevToolsNetworkController();
30
31  // Applies network emulation configuration.
32  void SetNetworkState(
33      const std::string& client_id,
34      scoped_ptr<DevToolsNetworkConditions> conditions);
35
36  base::WeakPtr<DevToolsNetworkInterceptor> GetInterceptor(
37      DevToolsNetworkTransaction* transaction);
38
39 protected:
40  friend class test::DevToolsNetworkControllerHelper;
41
42 private:
43  // Controller must be constructed on IO thread.
44  base::ThreadChecker thread_checker_;
45
46  void SetNetworkStateOnIO(
47      const std::string& client_id,
48      scoped_ptr<DevToolsNetworkConditions> conditions);
49
50  typedef scoped_ptr<DevToolsNetworkInterceptor> Interceptor;
51  Interceptor default_interceptor_;
52  Interceptor appcache_interceptor_;
53  typedef base::ScopedPtrHashMap<std::string, DevToolsNetworkInterceptor>
54      Interceptors;
55  Interceptors interceptors_;
56
57  base::WeakPtrFactory<DevToolsNetworkController> weak_ptr_factory_;
58
59  DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController);
60};
61
62#endif  // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_
63