Ignore title parameter for navigator.registerProtocolHandler
[chromium-blink-merge.git] / components / cronet / android / url_request_context_peer.h
blob256a649aaa937ae26c22ab36dcb82247db3d42bb
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 COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_PEER_H_
6 #define COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_PEER_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread.h"
15 #include "net/base/net_log.h"
16 #include "net/base/network_change_notifier.h"
17 #include "net/url_request/url_request_context.h"
18 #include "net/url_request/url_request_context_getter.h"
20 namespace net {
21 class NetLogLogger;
22 } // namespace net
24 namespace cronet {
26 // Implementation of the Chromium NetLog observer interface.
27 class NetLogObserver : public net::NetLog::ThreadSafeObserver {
28 public:
29 explicit NetLogObserver(int log_level) { log_level_ = log_level; }
31 virtual ~NetLogObserver() {}
33 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
35 private:
36 int log_level_;
38 DISALLOW_COPY_AND_ASSIGN(NetLogObserver);
41 // Fully configured |URLRequestContext|.
42 class URLRequestContextPeer : public net::URLRequestContextGetter {
43 public:
44 class URLRequestContextPeerDelegate
45 : public base::RefCountedThreadSafe<URLRequestContextPeerDelegate> {
46 public:
47 virtual void OnContextInitialized(URLRequestContextPeer* context) = 0;
49 protected:
50 friend class base::RefCountedThreadSafe<URLRequestContextPeerDelegate>;
52 virtual ~URLRequestContextPeerDelegate() {}
55 URLRequestContextPeer(URLRequestContextPeerDelegate* delegate,
56 std::string user_agent,
57 int log_level,
58 const char* version);
59 void Initialize();
61 const std::string& GetUserAgent(const GURL& url) const;
63 int logging_level() const { return logging_level_; }
65 const char* version() const { return version_; }
67 // net::URLRequestContextGetter implementation:
68 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
69 virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
70 const OVERRIDE;
72 void StartNetLogToFile(const std::string& file_name);
73 void StopNetLog();
75 private:
76 scoped_refptr<URLRequestContextPeerDelegate> delegate_;
77 scoped_ptr<net::URLRequestContext> context_;
78 int logging_level_;
79 const char* version_;
80 std::string user_agent_;
81 base::Thread* network_thread_;
82 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
83 scoped_ptr<NetLogObserver> net_log_observer_;
84 scoped_ptr<net::NetLogLogger> net_log_logger_;
86 virtual ~URLRequestContextPeer();
88 // Initializes |context_| on the IO thread.
89 void InitializeURLRequestContext();
91 DISALLOW_COPY_AND_ASSIGN(URLRequestContextPeer);
94 } // namespace cronet
96 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_PEER_H_