Commit 2801b152 authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Add iOS factory for RemoteSuggestionsService

Omnibox NTP Zero-Prefix Suggestions use the RemoteSuggestionsService
to actually get their suggestions. The corresponding factory currently
doesn't exist on iOS, so this CL creates it.

Bug: 1048193
Change-Id: I7ad14129a954e96225adc9d6b000087165ce5859
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2035964
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738520}
parent 45c1f87d
......@@ -12,6 +12,8 @@ source_set("autocomplete") {
"autocomplete_scheme_classifier_impl.mm",
"in_memory_url_index_factory.cc",
"in_memory_url_index_factory.h",
"remote_suggestions_service_factory.h",
"remote_suggestions_service_factory.mm",
"shortcuts_backend_factory.h",
"shortcuts_backend_factory.mm",
]
......
......@@ -17,6 +17,7 @@
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "ios/chrome/browser/autocomplete/in_memory_url_index_factory.h"
#include "ios/chrome/browser/autocomplete/remote_suggestions_service_factory.h"
#include "ios/chrome/browser/autocomplete/shortcuts_backend_factory.h"
#include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
......@@ -101,7 +102,8 @@ AutocompleteProviderClientImpl::GetTemplateURLService() const {
RemoteSuggestionsService*
AutocompleteProviderClientImpl::GetRemoteSuggestionsService(
bool create_if_necessary) const {
return nullptr;
return RemoteSuggestionsServiceFactory::GetForBrowserState(
browser_state_, create_if_necessary);
}
DocumentSuggestionsService*
......
// Copyright 2020 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 IOS_CHROME_BROWSER_AUTOCOMPLETE_REMOTE_SUGGESTIONS_SERVICE_FACTORY_H_
#define IOS_CHROME_BROWSER_AUTOCOMPLETE_REMOTE_SUGGESTIONS_SERVICE_FACTORY_H_
#include "base/no_destructor.h"
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
class ChromeBrowserState;
class RemoteSuggestionsService;
// Singleton that owns all RemoteSuggestionsServices and associates them with
// ChromeBrowserState.
class RemoteSuggestionsServiceFactory : public BrowserStateKeyedServiceFactory {
public:
static RemoteSuggestionsService* GetForBrowserState(
ChromeBrowserState* browser_state,
bool create_if_necessary);
static RemoteSuggestionsServiceFactory* GetInstance();
private:
friend class base::NoDestructor<RemoteSuggestionsServiceFactory>;
RemoteSuggestionsServiceFactory();
~RemoteSuggestionsServiceFactory() override;
// BrowserStateKeyedServiceFactory implementation.
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
web::BrowserState* context) const override;
RemoteSuggestionsServiceFactory(const RemoteSuggestionsServiceFactory&) =
delete;
RemoteSuggestionsServiceFactory& operator=(
const RemoteSuggestionsServiceFactory&) = delete;
};
#endif // IOS_CHROME_BROWSER_AUTOCOMPLETE_REMOTE_SUGGESTIONS_SERVICE_FACTORY_H_
// Copyright 2020 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.
#import "ios/chrome/browser/autocomplete/remote_suggestions_service_factory.h"
#include "base/no_destructor.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/omnibox/browser/remote_suggestions_service.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// static
RemoteSuggestionsService* RemoteSuggestionsServiceFactory::GetForBrowserState(
ChromeBrowserState* browser_state,
bool create_if_necessary) {
return static_cast<RemoteSuggestionsService*>(
GetInstance()->GetServiceForBrowserState(browser_state,
create_if_necessary));
}
// static
RemoteSuggestionsServiceFactory*
RemoteSuggestionsServiceFactory::GetInstance() {
static base::NoDestructor<RemoteSuggestionsServiceFactory> instance;
return instance.get();
}
std::unique_ptr<KeyedService>
RemoteSuggestionsServiceFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
ChromeBrowserState* browser_state =
ChromeBrowserState::FromBrowserState(context);
return std::make_unique<RemoteSuggestionsService>(
browser_state->GetSharedURLLoaderFactory());
}
RemoteSuggestionsServiceFactory::RemoteSuggestionsServiceFactory()
: BrowserStateKeyedServiceFactory(
"RemoteSuggestionsService",
BrowserStateDependencyManager::GetInstance()) {}
RemoteSuggestionsServiceFactory::~RemoteSuggestionsServiceFactory() {}
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