Add ChromeMostVisitedSitesFactory

Move the popular sites factory next to it.

Currently PopularSites is explicitly not enabled (not even instantiated)
on desktop. We could in theory create it and let the field trial decide
whether to show tiles from it, but it really needs some work first for a
world where we use thumbnails instead of icons. Also, Desktop has its
own, separate mechanism for displaying default tiles baked into
TopSites.

BUG=655622

Review-Url: https://codereview.chromium.org/2572533002
Cr-Commit-Position: refs/heads/master@{#438472}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index ff9ba4c..4ff6479ef 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -746,6 +746,10 @@
     "ntp_snippets/content_suggestions_service_factory.h",
     "ntp_snippets/download_suggestions_provider.cc",
     "ntp_snippets/download_suggestions_provider.h",
+    "ntp_tiles/chrome_most_visited_sites_factory.cc",
+    "ntp_tiles/chrome_most_visited_sites_factory.h",
+    "ntp_tiles/chrome_popular_sites_factory.cc",
+    "ntp_tiles/chrome_popular_sites_factory.h",
     "page_load_metrics/browser_page_track_decider.cc",
     "page_load_metrics/browser_page_track_decider.h",
     "page_load_metrics/metrics_navigation_throttle.cc",
@@ -3102,8 +3106,6 @@
       "android/ntp/ntp_snippets_bridge.h",
       "android/ntp/ntp_snippets_launcher.cc",
       "android/ntp/ntp_snippets_launcher.h",
-      "android/ntp/popular_sites.cc",
-      "android/ntp/popular_sites.h",
       "android/offline_pages/background_scheduler_bridge.cc",
       "android/offline_pages/background_scheduler_bridge.h",
       "android/offline_pages/downloads/offline_page_download_bridge.cc",
diff --git a/chrome/browser/android/ntp/most_visited_sites_bridge.cc b/chrome/browser/android/ntp/most_visited_sites_bridge.cc
index cbb5bcb..4f35387 100644
--- a/chrome/browser/android/ntp/most_visited_sites_bridge.cc
+++ b/chrome/browser/android/ntp/most_visited_sites_bridge.cc
@@ -10,34 +10,16 @@
 #include "base/android/jni_array.h"
 #include "base/android/jni_string.h"
 #include "base/android/scoped_java_ref.h"
-#include "base/bind.h"
-#include "base/callback.h"
-#include "base/memory/ptr_util.h"
-#include "chrome/browser/android/ntp/popular_sites.h"
 #include "chrome/browser/browser_process.h"
-#include "chrome/browser/favicon/favicon_service_factory.h"
-#include "chrome/browser/history/top_sites_factory.h"
+#include "chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/profiles/profile_android.h"
-#include "chrome/browser/search/suggestions/image_decoder_impl.h"
-#include "chrome/browser/search/suggestions/suggestions_service_factory.h"
-#include "chrome/browser/search_engines/template_url_service_factory.h"
-#include "chrome/browser/supervised_user/supervised_user_service.h"
-#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
-#include "chrome/browser/supervised_user/supervised_user_url_filter.h"
 #include "chrome/browser/thumbnails/thumbnail_list_source.h"
-#include "components/history/core/browser/top_sites.h"
-#include "components/image_fetcher/image_fetcher_impl.h"
-#include "components/ntp_tiles/icon_cacher.h"
 #include "components/ntp_tiles/metrics.h"
-#include "components/ntp_tiles/popular_sites.h"
+#include "components/ntp_tiles/most_visited_sites.h"
 #include "components/rappor/rappor_service_impl.h"
-#include "components/safe_json/safe_json_parser.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/url_data_source.h"
 #include "jni/MostVisitedSites_jni.h"
 #include "ui/gfx/android/java_bitmap.h"
-#include "url/gurl.h"
 
 using base::android::AttachCurrentThread;
 using base::android::ConvertJavaStringToUTF8;
@@ -47,63 +29,11 @@
 using base::android::ScopedJavaLocalRef;
 using base::android::ToJavaArrayOfStrings;
 using base::android::ToJavaIntArray;
-using content::BrowserThread;
+using ntp_tiles::MostVisitedSites;
+using ntp_tiles::NTPTileSource;
+using ntp_tiles::NTPTilesVector;
 using ntp_tiles::metrics::MostVisitedTileType;
 using ntp_tiles::metrics::TileImpression;
-using ntp_tiles::MostVisitedSites;
-using ntp_tiles::MostVisitedSitesSupervisor;
-using ntp_tiles::NTPTileSource;
-using suggestions::SuggestionsServiceFactory;
-
-MostVisitedSitesBridge::SupervisorBridge::SupervisorBridge(Profile* profile)
-    : profile_(profile),
-      supervisor_observer_(nullptr),
-      register_observer_(this) {
-  register_observer_.Add(SupervisedUserServiceFactory::GetForProfile(profile_));
-}
-
-MostVisitedSitesBridge::SupervisorBridge::~SupervisorBridge() {}
-
-void MostVisitedSitesBridge::SupervisorBridge::SetObserver(
-    Observer* new_observer) {
-  if (new_observer)
-    DCHECK(!supervisor_observer_);
-  else
-    DCHECK(supervisor_observer_);
-
-  supervisor_observer_ = new_observer;
-}
-
-bool MostVisitedSitesBridge::SupervisorBridge::IsBlocked(const GURL& url) {
-  SupervisedUserService* supervised_user_service =
-      SupervisedUserServiceFactory::GetForProfile(profile_);
-  auto* url_filter = supervised_user_service->GetURLFilterForUIThread();
-  return url_filter->GetFilteringBehaviorForURL(url) ==
-         SupervisedUserURLFilter::FilteringBehavior::BLOCK;
-}
-
-std::vector<MostVisitedSitesSupervisor::Whitelist>
-MostVisitedSitesBridge::SupervisorBridge::whitelists() {
-  std::vector<MostVisitedSitesSupervisor::Whitelist> results;
-  SupervisedUserService* supervised_user_service =
-      SupervisedUserServiceFactory::GetForProfile(profile_);
-  for (const auto& whitelist : supervised_user_service->whitelists()) {
-    results.emplace_back(Whitelist{
-        whitelist->title(), whitelist->entry_point(),
-        whitelist->large_icon_path(),
-    });
-  }
-  return results;
-}
-
-bool MostVisitedSitesBridge::SupervisorBridge::IsChildProfile() {
-  return profile_->IsChild();
-}
-
-void MostVisitedSitesBridge::SupervisorBridge::OnURLFilterChanged() {
-  if (supervisor_observer_)
-    supervisor_observer_->OnBlockedSitesChanged();
-}
 
 class MostVisitedSitesBridge::JavaObserver : public MostVisitedSites::Observer {
  public:
@@ -157,19 +87,7 @@
 }
 
 MostVisitedSitesBridge::MostVisitedSitesBridge(Profile* profile)
-    : supervisor_(profile),
-      most_visited_(profile->GetPrefs(),
-                    TopSitesFactory::GetForProfile(profile),
-                    SuggestionsServiceFactory::GetForProfile(profile),
-                    ChromePopularSites::NewForProfile(profile),
-                    base::MakeUnique<ntp_tiles::IconCacher>(
-                        FaviconServiceFactory::GetForProfile(
-                            profile,
-                            ServiceAccessType::IMPLICIT_ACCESS),
-                        base::MakeUnique<image_fetcher::ImageFetcherImpl>(
-                            base::MakeUnique<suggestions::ImageDecoderImpl>(),
-                            profile->GetRequestContext())),
-                    &supervisor_) {
+    : most_visited_(ChromeMostVisitedSitesFactory::NewForProfile(profile)) {
   // Register the thumbnails debugging page.
   // TODO(sfiera): find thumbnails a home. They don't belong here.
   content::URLDataSource::Add(profile, new ThumbnailListSource(profile));
@@ -189,7 +107,7 @@
     const JavaParamRef<jobject>& j_observer,
     jint num_sites) {
   java_observer_.reset(new JavaObserver(env, j_observer));
-  most_visited_.SetMostVisitedURLsObserver(java_observer_.get(), num_sites);
+  most_visited_->SetMostVisitedURLsObserver(java_observer_.get(), num_sites);
 }
 
 void MostVisitedSitesBridge::AddOrRemoveBlacklistedUrl(
@@ -198,7 +116,7 @@
     const JavaParamRef<jstring>& j_url,
     jboolean add_url) {
   GURL url(ConvertJavaStringToUTF8(env, j_url));
-  most_visited_.AddOrRemoveBlacklistedUrl(url, add_url);
+  most_visited_->AddOrRemoveBlacklistedUrl(url, add_url);
 }
 
 void MostVisitedSitesBridge::RecordPageImpression(
diff --git a/chrome/browser/android/ntp/most_visited_sites_bridge.h b/chrome/browser/android/ntp/most_visited_sites_bridge.h
index 18020c9b..a86483d 100644
--- a/chrome/browser/android/ntp/most_visited_sites_bridge.h
+++ b/chrome/browser/android/ntp/most_visited_sites_bridge.h
@@ -6,22 +6,18 @@
 #define CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_BRIDGE_H_
 
 #include <jni.h>
-#include <stddef.h>
 
 #include <memory>
-#include <string>
-#include <vector>
 
 #include "base/android/scoped_java_ref.h"
 #include "base/macros.h"
-#include "chrome/browser/supervised_user/supervised_user_service.h"
-#include "chrome/browser/supervised_user/supervised_user_service_observer.h"
-#include "components/ntp_tiles/most_visited_sites.h"
-
-using ntp_tiles::NTPTilesVector;
 
 class Profile;
 
+namespace ntp_tiles {
+class MostVisitedSites;
+}  // namespace ntp_tiles
+
 // Provides the list of most visited sites and their thumbnails to Java.
 class MostVisitedSitesBridge {
  public:
@@ -62,29 +58,7 @@
   class JavaObserver;
   std::unique_ptr<JavaObserver> java_observer_;
 
-  class SupervisorBridge : public ntp_tiles::MostVisitedSitesSupervisor,
-                           public SupervisedUserServiceObserver {
-   public:
-    explicit SupervisorBridge(Profile* profile);
-    ~SupervisorBridge() override;
-
-    void SetObserver(Observer* observer) override;
-    bool IsBlocked(const GURL& url) override;
-    std::vector<MostVisitedSitesSupervisor::Whitelist> whitelists() override;
-    bool IsChildProfile() override;
-
-    // SupervisedUserServiceObserver implementation.
-    void OnURLFilterChanged() override;
-
-   private:
-    Profile* const profile_;
-    Observer* supervisor_observer_;
-    ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver>
-        register_observer_;
-  };
-  SupervisorBridge supervisor_;
-
-  ntp_tiles::MostVisitedSites most_visited_;
+  std::unique_ptr<ntp_tiles::MostVisitedSites> most_visited_;
 
   DISALLOW_COPY_AND_ASSIGN(MostVisitedSitesBridge);
 };
diff --git a/chrome/browser/android/ntp/popular_sites.h b/chrome/browser/android/ntp/popular_sites.h
deleted file mode 100644
index 07d3730..0000000
--- a/chrome/browser/android/ntp/popular_sites.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2015 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 CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_
-#define CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_
-
-#include <memory>
-
-#include "base/files/file_path.h"
-#include "base/macros.h"
-
-class Profile;
-
-namespace ntp_tiles {
-class PopularSites;
-}  // namespace ntp_tiles
-
-// TODO(sfiera): move to chrome_popular_sites.h
-class ChromePopularSites {
- public:
-  static std::unique_ptr<ntp_tiles::PopularSites> NewForProfile(
-      Profile* profile);
-
- private:
-  DISALLOW_IMPLICIT_CONSTRUCTORS(ChromePopularSites);
-};
-
-#endif  // CHROME_BROWSER_ANDROID_NTP_POPULAR_SITES_H_
diff --git a/chrome/browser/ntp_tiles/OWNERS b/chrome/browser/ntp_tiles/OWNERS
new file mode 100644
index 0000000..af1328d
--- /dev/null
+++ b/chrome/browser/ntp_tiles/OWNERS
@@ -0,0 +1 @@
+file://components/ntp_tiles/OWNERS
diff --git a/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc b/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc
new file mode 100644
index 0000000..88ea6d7a
--- /dev/null
+++ b/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc
@@ -0,0 +1,125 @@
+// Copyright 2013 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.
+
+#include "chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/memory/ptr_util.h"
+#include "chrome/browser/favicon/favicon_service_factory.h"
+#include "chrome/browser/history/top_sites_factory.h"
+#include "chrome/browser/ntp_tiles/chrome_popular_sites_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/search/suggestions/image_decoder_impl.h"
+#include "chrome/browser/search/suggestions/suggestions_service_factory.h"
+#include "chrome/browser/supervised_user/supervised_user_service.h"
+#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
+#include "chrome/browser/supervised_user/supervised_user_service_observer.h"
+#include "chrome/browser/supervised_user/supervised_user_url_filter.h"
+#include "chrome/browser/thumbnails/thumbnail_list_source.h"
+#include "components/history/core/browser/top_sites.h"
+#include "components/image_fetcher/image_fetcher_impl.h"
+#include "components/ntp_tiles/icon_cacher.h"
+#include "components/ntp_tiles/metrics.h"
+#include "components/ntp_tiles/most_visited_sites.h"
+
+using suggestions::SuggestionsServiceFactory;
+
+namespace {
+
+class SupervisorBridge : public ntp_tiles::MostVisitedSitesSupervisor,
+                         public SupervisedUserServiceObserver {
+ public:
+  explicit SupervisorBridge(Profile* profile);
+  ~SupervisorBridge() override;
+
+  void SetObserver(Observer* observer) override;
+  bool IsBlocked(const GURL& url) override;
+  std::vector<MostVisitedSitesSupervisor::Whitelist> whitelists() override;
+  bool IsChildProfile() override;
+
+  // SupervisedUserServiceObserver implementation.
+  void OnURLFilterChanged() override;
+
+ private:
+  Profile* const profile_;
+  Observer* supervisor_observer_;
+  ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver>
+      register_observer_;
+};
+
+SupervisorBridge::SupervisorBridge(Profile* profile)
+    : profile_(profile),
+      supervisor_observer_(nullptr),
+      register_observer_(this) {
+  register_observer_.Add(SupervisedUserServiceFactory::GetForProfile(profile_));
+}
+
+SupervisorBridge::~SupervisorBridge() {}
+
+void SupervisorBridge::SetObserver(Observer* new_observer) {
+  if (new_observer) {
+    DCHECK(!supervisor_observer_);
+  } else {
+    DCHECK(supervisor_observer_);
+  }
+
+  supervisor_observer_ = new_observer;
+}
+
+bool SupervisorBridge::IsBlocked(const GURL& url) {
+  SupervisedUserService* supervised_user_service =
+      SupervisedUserServiceFactory::GetForProfile(profile_);
+  auto* url_filter = supervised_user_service->GetURLFilterForUIThread();
+  return url_filter->GetFilteringBehaviorForURL(url) ==
+         SupervisedUserURLFilter::FilteringBehavior::BLOCK;
+}
+
+std::vector<ntp_tiles::MostVisitedSitesSupervisor::Whitelist>
+SupervisorBridge::whitelists() {
+  std::vector<MostVisitedSitesSupervisor::Whitelist> results;
+  SupervisedUserService* supervised_user_service =
+      SupervisedUserServiceFactory::GetForProfile(profile_);
+  for (const auto& whitelist : supervised_user_service->whitelists()) {
+    results.emplace_back(Whitelist{
+        whitelist->title(), whitelist->entry_point(),
+        whitelist->large_icon_path(),
+    });
+  }
+  return results;
+}
+
+bool SupervisorBridge::IsChildProfile() {
+  return profile_->IsChild();
+}
+
+void SupervisorBridge::OnURLFilterChanged() {
+  if (supervisor_observer_) {
+    supervisor_observer_->OnBlockedSitesChanged();
+  }
+}
+
+}  // namespace
+
+// static
+std::unique_ptr<ntp_tiles::MostVisitedSites>
+ChromeMostVisitedSitesFactory::NewForProfile(Profile* profile) {
+  return base::MakeUnique<ntp_tiles::MostVisitedSites>(
+      profile->GetPrefs(), TopSitesFactory::GetForProfile(profile),
+      SuggestionsServiceFactory::GetForProfile(profile),
+#if defined(OS_ANDROID)
+      ChromePopularSitesFactory::NewForProfile(profile),
+#else
+      nullptr,
+#endif
+      base::MakeUnique<ntp_tiles::IconCacher>(
+          FaviconServiceFactory::GetForProfile(
+              profile, ServiceAccessType::IMPLICIT_ACCESS),
+          base::MakeUnique<image_fetcher::ImageFetcherImpl>(
+              base::MakeUnique<suggestions::ImageDecoderImpl>(),
+              profile->GetRequestContext())),
+      base::MakeUnique<SupervisorBridge>(profile));
+}
diff --git a/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h b/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h
new file mode 100644
index 0000000..2ceec1b
--- /dev/null
+++ b/chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h
@@ -0,0 +1,24 @@
+// 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 CHROME_BROWSER_NTP_TILES_CHROME_MOST_VISITED_SITES_FACTORY_H_
+#define CHROME_BROWSER_NTP_TILES_CHROME_MOST_VISITED_SITES_FACTORY_H_
+
+#include <memory>
+
+class Profile;
+
+namespace ntp_tiles {
+class MostVisitedSites;
+}  // namespace ntp_tiles
+
+class ChromeMostVisitedSitesFactory {
+ public:
+  static std::unique_ptr<ntp_tiles::MostVisitedSites> NewForProfile(
+      Profile* profile);
+
+  ChromeMostVisitedSitesFactory() = delete;
+};
+
+#endif  // CHROME_BROWSER_NTP_TILES_CHROME_MOST_VISITED_SITES_FACTORY_H_
diff --git a/chrome/browser/android/ntp/popular_sites.cc b/chrome/browser/ntp_tiles/chrome_popular_sites_factory.cc
similarity index 85%
rename from chrome/browser/android/ntp/popular_sites.cc
rename to chrome/browser/ntp_tiles/chrome_popular_sites_factory.cc
index 3413ce4..0970f35 100644
--- a/chrome/browser/android/ntp/popular_sites.cc
+++ b/chrome/browser/ntp_tiles/chrome_popular_sites_factory.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "chrome/browser/android/ntp/popular_sites.h"
+#include "chrome/browser/ntp_tiles/chrome_popular_sites_factory.h"
 
 #include "base/bind.h"
 #include "base/memory/ptr_util.h"
@@ -15,8 +15,8 @@
 #include "components/safe_json/safe_json_parser.h"
 #include "content/public/browser/browser_thread.h"
 
-std::unique_ptr<ntp_tiles::PopularSites> ChromePopularSites::NewForProfile(
-    Profile* profile) {
+std::unique_ptr<ntp_tiles::PopularSites>
+ChromePopularSitesFactory::NewForProfile(Profile* profile) {
   base::FilePath directory;  // remains empty if PathService::Get() fails.
   PathService::Get(chrome::DIR_USER_DATA, &directory);
   return base::MakeUnique<ntp_tiles::PopularSites>(
diff --git a/chrome/browser/ntp_tiles/chrome_popular_sites_factory.h b/chrome/browser/ntp_tiles/chrome_popular_sites_factory.h
new file mode 100644
index 0000000..97c355f
--- /dev/null
+++ b/chrome/browser/ntp_tiles/chrome_popular_sites_factory.h
@@ -0,0 +1,24 @@
+// Copyright 2015 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 CHROME_BROWSER_NTP_TILES_CHROME_POPULAR_SITES_FACTORY_H_
+#define CHROME_BROWSER_NTP_TILES_CHROME_POPULAR_SITES_FACTORY_H_
+
+#include <memory>
+
+class Profile;
+
+namespace ntp_tiles {
+class PopularSites;
+}  // namespace ntp_tiles
+
+class ChromePopularSitesFactory {
+ public:
+  static std::unique_ptr<ntp_tiles::PopularSites> NewForProfile(
+      Profile* profile);
+
+  ChromePopularSitesFactory() = delete;
+};
+
+#endif  // CHROME_BROWSER_NTP_TILES_CHROME_POPULAR_SITES_FACTORY_H_
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc
index c897a96..3d5863d 100644
--- a/chrome/browser/search/instant_service.cc
+++ b/chrome/browser/search/instant_service.cc
@@ -14,6 +14,7 @@
 #include "chrome/browser/favicon/favicon_service_factory.h"
 #include "chrome/browser/favicon/large_icon_service_factory.h"
 #include "chrome/browser/history/top_sites_factory.h"
+#include "chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/search/instant_io_context.h"
 #include "chrome/browser/search/instant_service_observer.h"
@@ -100,20 +101,8 @@
                  content::NotificationService::AllSources());
 
   if (base::FeatureList::IsEnabled(kNtpTilesFeature)) {
-    most_visited_sites_ = base::MakeUnique<ntp_tiles::MostVisitedSites>(
-        profile_->GetPrefs(), TopSitesFactory::GetForProfile(profile_),
-        suggestions::SuggestionsServiceFactory::GetForProfile(profile_),
-        /*popular_sites=*/nullptr,
-        base::MakeUnique<ntp_tiles::IconCacher>(
-            FaviconServiceFactory::GetForProfile(
-                profile, ServiceAccessType::IMPLICIT_ACCESS),
-            base::MakeUnique<image_fetcher::ImageFetcherImpl>(
-                base::MakeUnique<suggestions::ImageDecoderImpl>(),
-                profile->GetRequestContext())),
-        /*supervisor=*/nullptr);
-    // TODO(treib): Add supervisor.
-    // TODO(sfiera): Share this with Android in a factory.
-
+    most_visited_sites_ =
+        ChromeMostVisitedSitesFactory::NewForProfile(profile_);
     most_visited_sites_->SetMostVisitedURLsObserver(this, 8);
   } else {
     top_sites_ = TopSitesFactory::GetForProfile(profile_);
diff --git a/chrome/browser/ui/webui/ntp_tiles_internals_ui.cc b/chrome/browser/ui/webui/ntp_tiles_internals_ui.cc
index cfaf580..6f70597 100644
--- a/chrome/browser/ui/webui/ntp_tiles_internals_ui.cc
+++ b/chrome/browser/ui/webui/ntp_tiles_internals_ui.cc
@@ -8,6 +8,8 @@
 #include "base/memory/ptr_util.h"
 #include "chrome/browser/favicon/favicon_service_factory.h"
 #include "chrome/browser/history/top_sites_factory.h"
+#include "chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h"
+#include "chrome/browser/ntp_tiles/chrome_popular_sites_factory.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
@@ -26,10 +28,6 @@
 #include "content/public/browser/web_ui_data_source.h"
 #include "content/public/browser/web_ui_message_handler.h"
 
-#if defined(OS_ANDROID)
-#include "chrome/browser/android/ntp/popular_sites.h"
-#endif
-
 namespace {
 
 // The implementation for the chrome://ntp-tiles-internals page.
@@ -69,16 +67,12 @@
   switch (source) {
     case ntp_tiles::NTPTileSource::TOP_SITES:
     case ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE:
-      return true;
-#if defined(OS_ANDROID)
-    case ntp_tiles::NTPTileSource::POPULAR:
     case ntp_tiles::NTPTileSource::WHITELIST:
       return true;
+    case ntp_tiles::NTPTileSource::POPULAR:
+#if defined(OS_ANDROID)
+      return true;
 #else
-    case ntp_tiles::NTPTileSource::POPULAR:
-      return false;
-    case ntp_tiles::NTPTileSource::WHITELIST:
-      // TODO(sfiera): support WHITELIST.
       return false;
 #endif
   }
@@ -88,25 +82,14 @@
 
 std::unique_ptr<ntp_tiles::MostVisitedSites>
 ChromeNTPTilesInternalsMessageHandlerClient::MakeMostVisitedSites() {
-  // TODO(sfiera): share with Android and Instant in a factory.
-  auto* profile = Profile::FromWebUI(web_ui());
-  return base::MakeUnique<ntp_tiles::MostVisitedSites>(
-      GetPrefs(), TopSitesFactory::GetForProfile(profile),
-      suggestions::SuggestionsServiceFactory::GetForProfile(profile),
-      MakePopularSites(),
-      base::MakeUnique<ntp_tiles::IconCacher>(
-          FaviconServiceFactory::GetForProfile(
-              profile, ServiceAccessType::IMPLICIT_ACCESS),
-          base::MakeUnique<image_fetcher::ImageFetcherImpl>(
-              base::MakeUnique<suggestions::ImageDecoderImpl>(),
-              profile->GetRequestContext())),
-      /*supervisor=*/nullptr);
+  return ChromeMostVisitedSitesFactory::NewForProfile(
+      Profile::FromWebUI(web_ui()));
 }
 
 std::unique_ptr<ntp_tiles::PopularSites>
 ChromeNTPTilesInternalsMessageHandlerClient::MakePopularSites() {
 #if defined(OS_ANDROID)
-  return ChromePopularSites::NewForProfile(Profile::FromWebUI(web_ui()));
+  return ChromePopularSitesFactory::NewForProfile(Profile::FromWebUI(web_ui()));
 #else
   return nullptr;
 #endif
diff --git a/chrome/browser/ui/webui/popular_sites_internals_ui.cc b/chrome/browser/ui/webui/popular_sites_internals_ui.cc
index 4deae00..daf09e3 100644
--- a/chrome/browser/ui/webui/popular_sites_internals_ui.cc
+++ b/chrome/browser/ui/webui/popular_sites_internals_ui.cc
@@ -4,7 +4,7 @@
 
 #include "chrome/browser/ui/webui/popular_sites_internals_ui.h"
 
-#include "chrome/browser/android/ntp/popular_sites.h"
+#include "chrome/browser/ntp_tiles/chrome_popular_sites_factory.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/common/url_constants.h"
 #include "components/grit/components_resources.h"
@@ -56,7 +56,7 @@
 
 std::unique_ptr<ntp_tiles::PopularSites>
 ChromePopularSitesInternalsMessageHandlerBridge::MakePopularSites() {
-  return ChromePopularSites::NewForProfile(Profile::FromWebUI(web_ui()));
+  return ChromePopularSitesFactory::NewForProfile(Profile::FromWebUI(web_ui()));
 }
 
 PrefService* ChromePopularSitesInternalsMessageHandlerBridge::GetPrefs() {