Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: components/cronet/android/cronet_url_request_context_adapter.h

Issue 586143002: Initial implementation of Cronet Async API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ 5 #ifndef COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_
6 #define COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ 6 #define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "net/base/net_log.h" 15 #include "net/base/net_log.h"
16 #include "net/base/network_change_notifier.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" 17 #include "net/url_request/url_request_context_getter.h"
19 18
19 namespace base {
20 class SingleThreadTaskRunner;
21 } // namespace base
22
20 namespace net { 23 namespace net {
21 class NetLogLogger; 24 class NetLogLogger;
25 class URLRequestContext;
22 } // namespace net 26 } // namespace net
23 27
24 namespace cronet { 28 namespace cronet {
25 29
26 struct URLRequestContextConfig; 30 struct URLRequestContextConfig;
27 31
28 // Implementation of the Chromium NetLog observer interface. 32 // Fully configured |URLRequestContext|.
29 class NetLogObserver : public net::NetLog::ThreadSafeObserver { 33 class CronetURLRequestContextAdapter : public net::URLRequestContextGetter {
30 public: 34 public:
31 explicit NetLogObserver() {} 35 class CronetURLRequestContextAdapterDelegate
32 36 : public base::RefCountedThreadSafe<
33 virtual ~NetLogObserver() {} 37 CronetURLRequestContextAdapterDelegate> {
34
35 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
36
37 private:
38 DISALLOW_COPY_AND_ASSIGN(NetLogObserver);
39 };
40
41 // Fully configured |URLRequestContext|.
42 class URLRequestContextAdapter : public net::URLRequestContextGetter {
43 public:
44 class URLRequestContextAdapterDelegate
45 : public base::RefCountedThreadSafe<URLRequestContextAdapterDelegate> {
46 public: 38 public:
47 virtual void OnContextInitialized(URLRequestContextAdapter* context) = 0; 39 virtual void OnContextInitialized(
40 CronetURLRequestContextAdapter* context) = 0;
48 41
49 protected: 42 protected:
50 friend class base::RefCountedThreadSafe<URLRequestContextAdapterDelegate>; 43 friend class base::RefCountedThreadSafe<
44 CronetURLRequestContextAdapterDelegate>;
51 45
52 virtual ~URLRequestContextAdapterDelegate() {} 46 virtual ~CronetURLRequestContextAdapterDelegate() {}
53 }; 47 };
54 48
55 URLRequestContextAdapter(URLRequestContextAdapterDelegate* delegate, 49 explicit CronetURLRequestContextAdapter(
56 std::string user_agent); 50 CronetURLRequestContextAdapterDelegate* delegate);
57 void Initialize(scoped_ptr<URLRequestContextConfig> config); 51 void Initialize(scoped_ptr<URLRequestContextConfig> config);
58 52
59 const std::string& GetUserAgent(const GURL& url) const; 53 const std::string& GetUserAgent(const GURL& url) const;
60 54
61 // net::URLRequestContextGetter implementation: 55 // net::URLRequestContextGetter implementation:
62 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; 56 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
63 virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() 57 virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
64 const OVERRIDE; 58 const OVERRIDE;
65 59
66 void StartNetLogToFile(const std::string& file_name); 60 void StartNetLogToFile(const std::string& file_name);
67 void StopNetLog(); 61 void StopNetLog();
68 62
69 private: 63 private:
70 scoped_refptr<URLRequestContextAdapterDelegate> delegate_; 64 scoped_refptr<CronetURLRequestContextAdapterDelegate> delegate_;
71 scoped_ptr<net::URLRequestContext> context_; 65 scoped_ptr<net::URLRequestContext> context_;
72 std::string user_agent_; 66 std::string user_agent_;
73 base::Thread* network_thread_; 67 base::Thread* network_thread_;
74 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 68 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
75 scoped_ptr<NetLogObserver> net_log_observer_;
76 scoped_ptr<net::NetLogLogger> net_log_logger_; 69 scoped_ptr<net::NetLogLogger> net_log_logger_;
77 70
78 virtual ~URLRequestContextAdapter(); 71 virtual ~CronetURLRequestContextAdapter();
79 72
80 // Initializes |context_| on the Network thread. 73 // Initializes |context_| on the Network thread.
81 void InitializeURLRequestContext(scoped_ptr<URLRequestContextConfig> config); 74 void InitializeOnNetworkThread(scoped_ptr<URLRequestContextConfig> config);
75 void StartNetLogToFileOnNetworkThread(const std::string& file_name);
76 void StopNetLogOnNetworkThread();
82 77
83 DISALLOW_COPY_AND_ASSIGN(URLRequestContextAdapter); 78 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter);
84 }; 79 };
85 80
86 } // namespace cronet 81 } // namespace cronet
87 82
88 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ 83 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698