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

Unified Diff: headless/public/util/url_fetcher.h

Issue 2260793002: Headless utility classes for making deterministic protocol handlers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing files Created 4 years, 4 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: headless/public/util/url_fetcher.h
diff --git a/headless/public/util/url_fetcher.h b/headless/public/util/url_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..e968764e73d082d475b538f0a25a1dca21885ff7
--- /dev/null
+++ b/headless/public/util/url_fetcher.h
@@ -0,0 +1,75 @@
+// Copyright 2016 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 HEADLESS_PUBLIC_UTIL_URL_FETCHER_H_
+#define HEADLESS_PUBLIC_UTIL_URL_FETCHER_H_
+
+#include <stddef.h>
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "net/base/net_errors.h"
+#include "url/gurl.h"
+
+namespace net {
+class HttpRequestHeaders;
+class HttpResponseHeaders;
+} // namespace net
+
+namespace headless {
+
+// An interface for fetching URLs. Note these are only intended to be used once.
+// TODO(alexclarke): Implement a URLFetcher that can backend onto a URLRequest
+// and hook this up in headless_shell under a flag.
+class URLFetcher {
+ public:
+ URLFetcher() {}
+ virtual ~URLFetcher() {}
+
+ // Interface for reporting the fetch result.
+ class ResultListener {
+ public:
+ ResultListener() {}
+
+ // Informs the listener that the fetch failed.
+ virtual void OnStartError(net::Error error) = 0;
+
+ // Informs the listener that the fetch succeeded and returns the HTTP
+ // headers and the body. NOTE |body| must be owned by the caller and remain
+ // valid until the fetcher is destroyed,
+ virtual void OnFetchComplete(
+ const std::string& final_url,
Sami 2016/08/19 11:54:00 Could we use GURL for URLs everywhere?
alex clarke (OOO till 29th) 2016/08/19 12:48:58 Done.
+ int http_response_code,
+ scoped_refptr<net::HttpResponseHeaders> response_headers,
+ const char* body,
+ size_t body_size) = 0;
+
+ // Helper function which extracts the headers from |response_data| and calls
+ // OnFetchComplete.
+ void OnFetchCompleteExtractHeaders(const std::string& final_url,
+ int http_response_code,
+ const char* response_data,
+ size_t response_data_size);
+
+ protected:
+ virtual ~ResultListener() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ResultListener);
+ };
+
+ // Instructs the sub-class to fetch the resource.
+ virtual void StartFetch(const GURL& rewritten_url,
+ const net::HttpRequestHeaders& request_headers,
+ ResultListener* result_listener) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(URLFetcher);
+};
+
+} // namespace headless
+
+#endif // HEADLESS_PUBLIC_UTIL_URL_FETCHER_H_

Powered by Google App Engine
This is Rietveld 408576698