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

Unified 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, add mock errors to CronetUrlRequestTest. 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/cronet_url_request_context_adapter.h
diff --git a/components/cronet/android/cronet_url_request_context_adapter.h b/components/cronet/android/cronet_url_request_context_adapter.h
new file mode 100644
index 0000000000000000000000000000000000000000..94e264617c4c95abc2d4f6d98f57af3b88fb0a69
--- /dev/null
+++ b/components/cronet/android/cronet_url_request_context_adapter.h
@@ -0,0 +1,83 @@
+// Copyright 2014 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 COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_
+#define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_
+
+#include <string>
+
+#include "base/compiler_specific.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread.h"
+#include "net/base/net_log.h"
+#include "net/base/network_change_notifier.h"
+#include "net/url_request/url_request_context_getter.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+} // namespace base
+
+namespace net {
+class NetLogLogger;
+class URLRequestContext;
+} // namespace net
+
+namespace cronet {
+
+struct URLRequestContextConfig;
+
+// Fully configured |URLRequestContext|.
+class CronetURLRequestContextAdapter : public net::URLRequestContextGetter {
+ public:
+ class CronetURLRequestContextAdapterDelegate
+ : public base::RefCountedThreadSafe<
+ CronetURLRequestContextAdapterDelegate> {
+ public:
+ virtual void OnContextInitialized(
+ CronetURLRequestContextAdapter* context) = 0;
xunjieli 2014/10/17 00:31:35 nit: s/context/context_adapter?
mef 2014/10/17 20:19:42 Done.
+
+ protected:
+ friend class base::RefCountedThreadSafe<
+ CronetURLRequestContextAdapterDelegate>;
+
+ virtual ~CronetURLRequestContextAdapterDelegate() {}
+ };
+
+ explicit CronetURLRequestContextAdapter(
+ CronetURLRequestContextAdapterDelegate* delegate);
+ void Initialize(scoped_ptr<URLRequestContextConfig> config);
+
+ const std::string& GetUserAgent(const GURL& url) const;
+
+ // net::URLRequestContextGetter implementation:
+ net::URLRequestContext* GetURLRequestContext() override;
+ scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
+ const override;
+
+ void StartNetLogToFile(const std::string& file_name);
+ void StopNetLog();
+
+ private:
+ scoped_refptr<CronetURLRequestContextAdapterDelegate> delegate_;
+ scoped_ptr<net::URLRequestContext> context_;
+ std::string user_agent_;
+ base::Thread* network_thread_;
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
+ scoped_ptr<net::NetLogLogger> net_log_logger_;
+
+ virtual ~CronetURLRequestContextAdapter();
+
+ // Initializes |context_| on the Network thread.
xunjieli 2014/10/17 00:31:35 The reason I suggested renaming is that I always c
mef 2014/10/17 20:19:42 Acknowledged. Should we rename |context_| into |re
xunjieli 2014/10/17 20:32:22 I think that is fine. Since we only have one conte
+ void InitializeOnNetworkThread(scoped_ptr<URLRequestContextConfig> config);
+ void StartNetLogToFileOnNetworkThread(const std::string& file_name);
+ void StopNetLogOnNetworkThread();
+
+ DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextAdapter);
+};
+
+} // namespace cronet
+
+#endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_CONTEXT_ADAPTER_H_

Powered by Google App Engine
This is Rietveld 408576698