Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / chrome / browser / net / ios_chrome_network_delegate.h
blobf6f1f18e8774ca5449eaabdc64209a026c6213a7
1 // Copyright 2015 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 IOS_CHROME_BROWSER_NET_IOS_CHROME_NETWORK_DELEGATE_H_
6 #define IOS_CHROME_BROWSER_NET_IOS_CHROME_NETWORK_DELEGATE_H_
8 #include <stdint.h>
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/content_settings/core/browser/cookie_settings.h"
14 #include "net/base/network_delegate_impl.h"
16 class PrefService;
18 template <typename T>
19 class PrefMember;
21 typedef PrefMember<bool> BooleanPrefMember;
23 namespace domain_reliability {
24 class DomainReliabilityMonitor;
27 namespace policy {
28 class URLBlacklistManager;
31 // IOSChromeNetworkDelegate is the central point from within the Chrome code to
32 // add hooks into the network stack.
33 class IOSChromeNetworkDelegate : public net::NetworkDelegateImpl {
34 public:
35 IOSChromeNetworkDelegate();
36 ~IOSChromeNetworkDelegate() override;
38 #if defined(ENABLE_CONFIGURATION_POLICY)
39 void set_url_blacklist_manager(
40 const policy::URLBlacklistManager* url_blacklist_manager) {
41 url_blacklist_manager_ = url_blacklist_manager;
43 #endif
45 // If |cookie_settings| is null or not set, all cookies are enabled,
46 // otherwise the settings are enforced on all observed network requests.
47 // Not inlined because we assign a scoped_refptr, which requires us to include
48 // the header file. Here we just forward-declare it.
49 void set_cookie_settings(content_settings::CookieSettings* cookie_settings) {
50 cookie_settings_ = cookie_settings;
53 void set_enable_do_not_track(BooleanPrefMember* enable_do_not_track) {
54 enable_do_not_track_ = enable_do_not_track;
57 void set_domain_reliability_monitor(
58 domain_reliability::DomainReliabilityMonitor* monitor) {
59 domain_reliability_monitor_ = monitor;
62 // Binds the pref members to |pref_service| and moves them to the IO thread.
63 // This method should be called on the UI thread.
64 static void InitializePrefsOnUIThread(BooleanPrefMember* enable_do_not_track,
65 PrefService* pref_service);
67 private:
68 // NetworkDelegate implementation.
69 int OnBeforeURLRequest(net::URLRequest* request,
70 const net::CompletionCallback& callback,
71 GURL* new_url) override;
72 void OnBeforeRedirect(net::URLRequest* request,
73 const GURL& new_location) override;
74 void OnCompleted(net::URLRequest* request, bool started) override;
75 net::NetworkDelegate::AuthRequiredResponse OnAuthRequired(
76 net::URLRequest* request,
77 const net::AuthChallengeInfo& auth_info,
78 const AuthCallback& callback,
79 net::AuthCredentials* credentials) override;
80 bool OnCanGetCookies(const net::URLRequest& request,
81 const net::CookieList& cookie_list) override;
82 bool OnCanSetCookie(const net::URLRequest& request,
83 const std::string& cookie_line,
84 net::CookieOptions* options) override;
85 bool OnCanAccessFile(const net::URLRequest& request,
86 const base::FilePath& path) const override;
87 bool OnCanEnablePrivacyMode(
88 const GURL& url,
89 const GURL& first_party_for_cookies) const override;
90 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
91 const net::URLRequest& request,
92 const GURL& target_url,
93 const GURL& referrer_url) const override;
95 void AccumulateContentLength(int64 received_payload_byte_count,
96 int64 original_payload_byte_count);
98 scoped_refptr<content_settings::CookieSettings> cookie_settings_;
100 // Weak, owned by our owner.
101 BooleanPrefMember* enable_do_not_track_;
103 // Weak, owned by our owner.
104 #if defined(ENABLE_CONFIGURATION_POLICY)
105 const policy::URLBlacklistManager* url_blacklist_manager_;
106 #endif
107 domain_reliability::DomainReliabilityMonitor* domain_reliability_monitor_;
109 DISALLOW_COPY_AND_ASSIGN(IOSChromeNetworkDelegate);
112 #endif // IOS_CHROME_BROWSER_NET_IOS_CHROME_NETWORK_DELEGATE_H_