Commit a4a16f32 authored by Kristi Park's avatar Kristi Park Committed by Commit Bot

Delete UrlValidityCheckerFactory and move singleton to InstantService

Classes with only static functions are not allowed as per the style
guide (https://google.github.io/styleguide/cppguide.html#Nonmember,_Static_Member,_and_Global_Functions).

Instead, InstantService will own the single UrlValidityChecker instance.

Bug: 874194
Change-Id: Ia4fa35abfdfde3e0d64b268c11c9b7a82fedc126
Reviewed-on: https://chromium-review.googlesource.com/c/1283947
Commit-Queue: Kristi Park <kristipark@chromium.org>
Reviewed-by: default avatarMathieu Perreault <mathp@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600508}
parent 1740bdc5
...@@ -2940,8 +2940,6 @@ jumbo_split_static_library("browser") { ...@@ -2940,8 +2940,6 @@ jumbo_split_static_library("browser") {
"search/one_google_bar/one_google_bar_service_observer.h", "search/one_google_bar/one_google_bar_service_observer.h",
"search/search_engine_base_url_tracker.cc", "search/search_engine_base_url_tracker.cc",
"search/search_engine_base_url_tracker.h", "search/search_engine_base_url_tracker.h",
"search/url_validity_checker_factory.cc",
"search/url_validity_checker_factory.h",
"signin/mutable_profile_oauth2_token_service_delegate.cc", "signin/mutable_profile_oauth2_token_service_delegate.cc",
"signin/mutable_profile_oauth2_token_service_delegate.h", "signin/mutable_profile_oauth2_token_service_delegate.h",
"signin/signin_promo.cc", "signin/signin_promo.cc",
......
...@@ -8,13 +8,17 @@ ...@@ -8,13 +8,17 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/no_destructor.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/time/default_tick_clock.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/ntp_tiles/chrome_most_visited_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.h"
#include "chrome/browser/search/instant_io_context.h" #include "chrome/browser/search/instant_io_context.h"
...@@ -25,7 +29,6 @@ ...@@ -25,7 +29,6 @@
#include "chrome/browser/search/ntp_icon_source.h" #include "chrome/browser/search/ntp_icon_source.h"
#include "chrome/browser/search/search.h" #include "chrome/browser/search/search.h"
#include "chrome/browser/search/thumbnail_source.h" #include "chrome/browser/search/thumbnail_source.h"
#include "chrome/browser/search/url_validity_checker_factory.h"
#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service.h"
...@@ -41,6 +44,7 @@ ...@@ -41,6 +44,7 @@
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/search/search.h" #include "components/search/search.h"
#include "components/search/url_validity_checker_impl.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h" #include "components/search_engines/template_url_service_observer.h"
#include "components/sync_preferences/pref_service_syncable.h" #include "components/sync_preferences/pref_service_syncable.h"
...@@ -50,6 +54,7 @@ ...@@ -50,6 +54,7 @@
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/url_data_source.h" #include "content/public/browser/url_data_source.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
namespace { namespace {
...@@ -809,9 +814,14 @@ void InstantService::FallbackToDefaultThemeInfo() { ...@@ -809,9 +814,14 @@ void InstantService::FallbackToDefaultThemeInfo() {
} }
UrlValidityChecker* InstantService::GetUrlValidityChecker() { UrlValidityChecker* InstantService::GetUrlValidityChecker() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (url_checker_for_testing_ != nullptr) if (url_checker_for_testing_ != nullptr)
return url_checker_for_testing_; return url_checker_for_testing_;
return UrlValidityCheckerFactory::GetUrlValidityChecker(); static base::NoDestructor<UrlValidityCheckerImpl> checker(
g_browser_process->system_network_context_manager()
->GetSharedURLLoaderFactory(),
base::DefaultTickClock::GetInstance());
return checker.get();
} }
// static // static
......
...@@ -203,8 +203,9 @@ class InstantService : public KeyedService, ...@@ -203,8 +203,9 @@ class InstantService : public KeyedService,
// chrome-search://local-ntp/background.jpg // chrome-search://local-ntp/background.jpg
void SetBackgroundToLocalResource(); void SetBackgroundToLocalResource();
// Returns UrlValidityCheckerFactory::GetInstance() or // Returns the owned instance of UrlValidityChecker or
// |url_checker_for_testing_| if not null. // |url_checker_for_testing_| if not null. Should only be called from the UI
// thread.
UrlValidityChecker* GetUrlValidityChecker(); UrlValidityChecker* GetUrlValidityChecker();
Profile* const profile_; Profile* const profile_;
......
// Copyright 2018 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/search/url_validity_checker_factory.h"
#include <memory>
#include "base/time/default_tick_clock.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "content/public/browser/browser_thread.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
// static
UrlValidityChecker* UrlValidityCheckerFactory::GetUrlValidityChecker() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
static base::NoDestructor<UrlValidityCheckerImpl> checker(
g_browser_process->system_network_context_manager()
->GetSharedURLLoaderFactory(),
base::DefaultTickClock::GetInstance());
return checker.get();
}
UrlValidityCheckerFactory::UrlValidityCheckerFactory() = default;
UrlValidityCheckerFactory::~UrlValidityCheckerFactory() = default;
// Copyright 2018 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_SEARCH_URL_VALIDITY_CHECKER_FACTORY_H_
#define CHROME_BROWSER_SEARCH_URL_VALIDITY_CHECKER_FACTORY_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "components/search/url_validity_checker_impl.h"
// Singleton that owns a single UrlValidityCheckerImpl instance. Should only be
// called from the UI thread.
class UrlValidityCheckerFactory {
public:
static UrlValidityChecker* GetUrlValidityChecker();
private:
friend class base::NoDestructor<UrlValidityCheckerFactory>;
UrlValidityCheckerFactory();
~UrlValidityCheckerFactory();
DISALLOW_COPY_AND_ASSIGN(UrlValidityCheckerFactory);
};
#endif // CHROME_BROWSER_SEARCH_URL_VALIDITY_CHECKER_FACTORY_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment