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

Unified Diff: components/doodle/doodle_fetcher.h

Issue 2660883002: Introduce a Doodle Fetcher for NTP (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « components/doodle/OWNERS ('k') | components/doodle/doodle_fetcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/doodle/doodle_fetcher.h
diff --git a/components/doodle/doodle_fetcher.h b/components/doodle/doodle_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..92fe93819ffeb2e82e56ef2958625a7da48da76b
--- /dev/null
+++ b/components/doodle/doodle_fetcher.h
@@ -0,0 +1,80 @@
+// Copyright 2017 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_DOODLE_DOODLE_FETCHER_H_
+#define COMPONENTS_DOODLE_DOODLE_FETCHER_H_
+
+#include <memory>
+#include <string>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "net/url_request/url_fetcher_delegate.h"
+
+namespace base {
+class DictionaryValue;
+class Value;
+}
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+using ParseJSONCallback = base::Callback<void(
+ const std::string& unsafe_json,
+ const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback,
+ const base::Callback<void(const std::string&)>& error_callback)>;
+
+struct DoodleImage {
+ std::string url;
+ int height;
+ int width;
+ std::string background_color;
+};
+
+struct DoodleConfig {
+ DoodleConfig();
+ DoodleConfig(DoodleImage large_image);
+ DoodleConfig(const DoodleConfig& config);
+ bool error_during_fetch;
+ std::string search_url;
+ std::string fullpage_interactive_url;
+ DoodleImage large_image;
+};
+
+class DoodleFetcher : public net::URLFetcherDelegate {
+ public:
+ using FinishedCallback = base::Callback<void(DoodleConfig doodle_config)>;
+
+ DoodleFetcher(net::URLRequestContextGetter* download_context,
+ ParseJSONCallback parse_json);
+
+ ~DoodleFetcher() override;
+
+ void FetchDoodle(const FinishedCallback& callback);
+
+ private:
+ // net::URLFetcherDelegate implementation.
+ void OnURLFetchComplete(const net::URLFetcher* source) override;
+
+ void OnJsonParsed(std::unique_ptr<base::Value> json);
+ void OnJsonParseFailed(const std::string& error_message);
+ void ParseDoodle(std::unique_ptr<base::DictionaryValue> config);
+ void OnDownloadFailed();
+
+ // Parameters set from constructor.
+ net::URLRequestContextGetter* const download_context_;
+ ParseJSONCallback parse_json_;
+
+ FinishedCallback callback_;
+
+ std::unique_ptr<net::URLFetcher> fetcher_;
+
+ base::WeakPtrFactory<DoodleFetcher> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(DoodleFetcher);
+};
+
+#endif // COMPONENTS_DOODLE_DOODLE_FETCHER_H_
« no previous file with comments | « components/doodle/OWNERS ('k') | components/doodle/doodle_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698