Adds service to get wallpaper collections to display on NTP background.

Creates a service that uses SimpleURLLoader to asynchronously request
wallpaper collections from the Backdrop service, and makes them
available to the Local NTP in a javascript variable.

Bug: 839152
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I4c1c8e1d0a3c12eecf3db27f4fd92e79470fcc34
Reviewed-on: https://chromium-review.googlesource.com/1066850
Commit-Queue: Ramya Nagarajan <[email protected]>
Reviewed-by: Christian Dullweber <[email protected]>
Reviewed-by: Ilya Sherman <[email protected]>
Reviewed-by: Marc Treib <[email protected]>
Cr-Commit-Position: refs/heads/master@{#561885}
diff --git a/chrome/browser/search/local_ntp_source.h b/chrome/browser/search/local_ntp_source.h
index 3da0d45..5fe6b67 100644
--- a/chrome/browser/search/local_ntp_source.h
+++ b/chrome/browser/search/local_ntp_source.h
@@ -15,6 +15,7 @@
 #include "base/scoped_observer.h"
 #include "base/time/time.h"
 #include "build/build_config.h"
+#include "chrome/browser/search/background/ntp_background_service_observer.h"
 #include "chrome/browser/search/one_google_bar/one_google_bar_service_observer.h"
 #include "content/public/browser/url_data_source.h"
 
@@ -23,6 +24,7 @@
 #endif
 
 struct OneGoogleBarData;
+class NtpBackgroundService;
 class OneGoogleBarService;
 class Profile;
 
@@ -38,6 +40,7 @@
 // To prevent accidental access, all methods that get called on the IO thread
 // are implemented as non-member functions.
 class LocalNtpSource : public content::URLDataSource,
+                       public NtpBackgroundServiceObserver,
                        public OneGoogleBarServiceObserver {
  public:
   explicit LocalNtpSource(Profile* profile);
@@ -46,6 +49,17 @@
   class GoogleSearchProviderTracker;
   class DesktopLogoObserver;
 
+  struct NtpBackgroundRequest {
+    NtpBackgroundRequest(
+        base::TimeTicks start_time,
+        const content::URLDataSource::GotDataCallback& callback);
+    NtpBackgroundRequest(const NtpBackgroundRequest&);
+    ~NtpBackgroundRequest();
+
+    base::TimeTicks start_time;
+    content::URLDataSource::GotDataCallback callback;
+  };
+
   struct OneGoogleBarRequest {
     OneGoogleBarRequest(
         base::TimeTicks start_time,
@@ -73,6 +87,9 @@
   std::string GetContentSecurityPolicyScriptSrc() const override;
   std::string GetContentSecurityPolicyChildSrc() const override;
 
+  // Overridden from NtpBackgroundServiceObserver:
+  void OnCollectionInfoAvailable() override;
+
   // Overridden from OneGoogleBarServiceObserver:
   void OnOneGoogleBarDataUpdated() override;
   void OnOneGoogleBarServiceShuttingDown() override;
@@ -81,6 +98,15 @@
 
   Profile* const profile_;
 
+  std::vector<NtpBackgroundRequest> ntp_background_requests_;
+
+  NtpBackgroundService* ntp_background_service_;
+
+  ScopedObserver<NtpBackgroundService, NtpBackgroundServiceObserver>
+      ntp_background_service_observer_;
+
+  std::vector<OneGoogleBarRequest> one_google_bar_requests_;
+
   OneGoogleBarService* one_google_bar_service_;
 
   ScopedObserver<OneGoogleBarService, OneGoogleBarServiceObserver>
@@ -89,8 +115,6 @@
   search_provider_logos::LogoService* logo_service_;
   std::unique_ptr<DesktopLogoObserver> logo_observer_;
 
-  std::vector<OneGoogleBarRequest> one_google_bar_requests_;
-
   std::unique_ptr<GoogleSearchProviderTracker> google_tracker_;
 
   base::WeakPtrFactory<LocalNtpSource> weak_ptr_factory_;