Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_URL_REQUEST_CONTEXT_ADAPTER_H_ |
| 6 #define COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ | 6 #define COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | |
| 10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 15 #include "net/base/net_log.h" | 16 #include "net/base/net_log.h" |
| 16 #include "net/base/network_change_notifier.h" | 17 #include "net/base/network_change_notifier.h" |
| 17 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 class NetLogLogger; | 22 class NetLogLogger; |
| 22 } // namespace net | 23 } // namespace net |
| 23 | 24 |
| 24 namespace cronet { | 25 namespace cronet { |
| 25 | 26 |
| 26 struct URLRequestContextConfig; | 27 struct URLRequestContextConfig; |
| 28 typedef struct base::Callback<void()> RunAfterContextInitTask; | |
|
mmenke
2014/10/02 19:51:18
nit: Know I was the one who added the "struct", b
xunjieli
2014/10/02 21:39:41
Done.
| |
| 27 | 29 |
| 28 // Implementation of the Chromium NetLog observer interface. | 30 // Implementation of the Chromium NetLog observer interface. |
| 29 class NetLogObserver : public net::NetLog::ThreadSafeObserver { | 31 class NetLogObserver : public net::NetLog::ThreadSafeObserver { |
| 30 public: | 32 public: |
| 31 explicit NetLogObserver() {} | 33 explicit NetLogObserver() {} |
| 32 | 34 |
| 33 virtual ~NetLogObserver() {} | 35 virtual ~NetLogObserver() {} |
| 34 | 36 |
| 35 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; | 37 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; |
| 36 | 38 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 49 protected: | 51 protected: |
| 50 friend class base::RefCountedThreadSafe<URLRequestContextAdapterDelegate>; | 52 friend class base::RefCountedThreadSafe<URLRequestContextAdapterDelegate>; |
| 51 | 53 |
| 52 virtual ~URLRequestContextAdapterDelegate() {} | 54 virtual ~URLRequestContextAdapterDelegate() {} |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 URLRequestContextAdapter(URLRequestContextAdapterDelegate* delegate, | 57 URLRequestContextAdapter(URLRequestContextAdapterDelegate* delegate, |
| 56 std::string user_agent); | 58 std::string user_agent); |
| 57 void Initialize(scoped_ptr<URLRequestContextConfig> config); | 59 void Initialize(scoped_ptr<URLRequestContextConfig> config); |
| 58 | 60 |
| 61 // Runs a task that might depend on context being initialized. | |
| 62 void RunTask(const RunAfterContextInitTask& callback); | |
| 63 void RunTaskOnNetworkThread(const RunAfterContextInitTask& callback); | |
| 64 | |
| 59 const std::string& GetUserAgent(const GURL& url) const; | 65 const std::string& GetUserAgent(const GURL& url) const; |
| 60 | 66 |
| 61 // net::URLRequestContextGetter implementation: | 67 // net::URLRequestContextGetter implementation: |
| 62 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; | 68 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |
| 63 virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() | 69 virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
| 64 const OVERRIDE; | 70 const OVERRIDE; |
| 65 | 71 |
| 66 void StartNetLogToFile(const std::string& file_name); | 72 void StartNetLogToFile(const std::string& file_name); |
| 67 void StopNetLog(); | 73 void StopNetLog(); |
| 68 | 74 |
| 69 private: | 75 private: |
| 70 scoped_refptr<URLRequestContextAdapterDelegate> delegate_; | 76 scoped_refptr<URLRequestContextAdapterDelegate> delegate_; |
| 71 scoped_ptr<net::URLRequestContext> context_; | 77 scoped_ptr<net::URLRequestContext> context_; |
| 72 std::string user_agent_; | 78 std::string user_agent_; |
| 73 base::Thread* network_thread_; | 79 base::Thread* network_thread_; |
| 74 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 80 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 75 scoped_ptr<NetLogObserver> net_log_observer_; | 81 scoped_ptr<NetLogObserver> net_log_observer_; |
| 76 scoped_ptr<net::NetLogLogger> net_log_logger_; | 82 scoped_ptr<net::NetLogLogger> net_log_logger_; |
| 77 | 83 |
| 84 // A queue of tasks that need to be run after context has been initialized. | |
| 85 std::queue<RunAfterContextInitTask> tasks_; | |
|
mmenke
2014/10/02 19:51:18
Maybe tasks_waiting_for_context_?
mmenke
2014/10/02 19:51:18
Should include <queue>
xunjieli
2014/10/02 21:39:41
Done.
xunjieli
2014/10/02 21:39:42
Done.
| |
| 86 bool is_context_initialized_; | |
| 87 | |
| 78 virtual ~URLRequestContextAdapter(); | 88 virtual ~URLRequestContextAdapter(); |
| 79 | 89 |
| 80 // Initializes |context_| on the Network thread. | 90 // Initializes |context_| on the Network thread. |
| 81 void InitializeURLRequestContext(scoped_ptr<URLRequestContextConfig> config); | 91 void InitializeURLRequestContext(scoped_ptr<URLRequestContextConfig> config); |
| 82 | 92 |
| 83 DISALLOW_COPY_AND_ASSIGN(URLRequestContextAdapter); | 93 DISALLOW_COPY_AND_ASSIGN(URLRequestContextAdapter); |
| 84 }; | 94 }; |
| 85 | 95 |
| 86 } // namespace cronet | 96 } // namespace cronet |
| 87 | 97 |
| 88 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ | 98 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_CONTEXT_ADAPTER_H_ |
| OLD | NEW |