summaryrefslogtreecommitdiffstats
path: root/chrome/browser/devtools/devtools_network_controller.h
blob: b9170495d3e825ba2785d105ba500f4c6386e57e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_
#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_

#include <set>
#include <string>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"

class DevToolsNetworkTransaction;
class GURL;
class Profile;

namespace content {
class ResourceContext;
}

namespace net {
struct HttpRequestInfo;
}

namespace test {
class DevToolsNetworkControllerHelper;
}

// DevToolsNetworkController tracks DevToolsNetworkTransactions.
class DevToolsNetworkController {

 public:
  DevToolsNetworkController();
  virtual ~DevToolsNetworkController();

  void AddTransaction(DevToolsNetworkTransaction* transaction);

  void RemoveTransaction(DevToolsNetworkTransaction* transaction);

  // Applies network emulation configuration.
  // |client_id| should be DevToolsAgentHost GUID.
  void SetNetworkState(
      const std::string& client_id,
      bool disable_network);

  bool ShouldFail(const net::HttpRequestInfo* request);

 protected:
  friend class test::DevToolsNetworkControllerHelper;

 private:
  // Controller must be constructed on IO thread.
  base::ThreadChecker thread_checker_;

  void SetNetworkStateOnIO(
      const std::string& client_id,
      bool disable_network);

  typedef std::set<DevToolsNetworkTransaction*> Transactions;
  Transactions transactions_;

  typedef std::set<std::string> Clients;
  Clients clients_;

  base::WeakPtrFactory<DevToolsNetworkController> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController);
};

#endif  // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_CONTROLLER_H_