summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/chrome_network_delegate.h
blob: f6efe2eadfcb3c76f03c2d3fcd4c7b526a47e5b3 (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
// Copyright (c) 2011 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_NET_CHROME_NETWORK_DELEGATE_H_
#define CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_
#pragma once

#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/profiles/profile.h"
#include "net/base/network_delegate.h"

class ExtensionEventRouterForwarder;
class ProtocolHandlerRegistry;

// ChromeNetworkDelegate is the central point from within the chrome code to
// add hooks into the network stack.
class ChromeNetworkDelegate : public net::NetworkDelegate {
 public:
  // If |profile_id| is the invalid profile, events will be broadcasted to all
  // profiles, otherwise, they will only be sent to the specified profile.
  explicit ChromeNetworkDelegate(
      ExtensionEventRouterForwarder* event_router,
      ProfileId profile_id,
      ProtocolHandlerRegistry* protocol_handler_registry);
  virtual ~ChromeNetworkDelegate();

 private:
  // NetworkDelegate methods:
  virtual bool OnBeforeURLRequest(net::URLRequest* request,
                                  net::CompletionCallback* callback);
  virtual void OnSendHttpRequest(net::HttpRequestHeaders* headers);
  virtual void OnResponseStarted(net::URLRequest* request);
  virtual void OnReadCompleted(net::URLRequest* request, int bytes_read);
  virtual net::URLRequestJob* OnMaybeCreateURLRequestJob(
      net::URLRequest* request);

  scoped_refptr<ExtensionEventRouterForwarder> event_router_;
  const ProfileId profile_id_;
  scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_;
  DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate);
};

#endif  // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_