Commit febaea18 authored by Thanh Nguyen's avatar Thanh Nguyen Committed by Commit Bot

[local-search-service] Rename LSS functions used by OS Settings

This CL rename classes and functions used by OS settings so that OS
Settings will be unaffected by the change that we made on LSS. After
the change is done, we will point OS Settings back to the main code.
See go/lss-sandboxing-impl for more details.

Bug: 1137560
Change-Id: If56dc5def738508817f4c2fa92a6d822dfdaad48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2467161Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Commit-Queue: Thanh Nguyen <thanhdng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817220}
parent 914c0473
......@@ -11,7 +11,7 @@
#include "chrome/browser/ui/webui/settings/chromeos/search/search_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_tag_registry.h"
#include "chrome/browser/ui/webui/settings/chromeos/settings_user_action_tracker.h"
#include "chromeos/components/local_search_service/local_search_service.h"
#include "chromeos/components/local_search_service/local_search_service_sync.h"
#include "chromeos/constants/chromeos_features.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -21,7 +21,7 @@ namespace settings {
OsSettingsManager::OsSettingsManager(
Profile* profile,
local_search_service::LocalSearchService* local_search_service,
local_search_service::LocalSearchServiceSync* local_search_service,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client,
phonehub::PhoneHubManager* phone_hub_manager,
syncer::SyncService* sync_service,
......
......@@ -37,7 +37,7 @@ class AndroidSmsService;
} // namespace android_sms
namespace local_search_service {
class LocalSearchService;
class LocalSearchServiceSync;
} // namespace local_search_service
namespace multidevice_setup {
......@@ -63,7 +63,8 @@ class SettingsUserActionTracker;
// Main responsibilities:
//
// (1) Support search queries for settings content. OsSettingsManager is
// responsible for updating the kCroSettings index of the LocalSearchService
// responsible for updating the kCroSettings index of the
// LocalSearchServiceSync
// with search tags corresponding to all settings which are available.
//
// The availability of settings depends on the user's account (e.g.,
......@@ -85,7 +86,7 @@ class OsSettingsManager : public KeyedService {
public:
OsSettingsManager(
Profile* profile,
local_search_service::LocalSearchService* local_search_service,
local_search_service::LocalSearchServiceSync* local_search_service,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client,
phonehub::PhoneHubManager* phone_hub_manager,
syncer::SyncService* sync_service,
......
......@@ -17,7 +17,7 @@
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h"
#include "chrome/browser/ui/webui/settings/chromeos/os_settings_manager.h"
#include "chromeos/components/local_search_service/local_search_service_factory.h"
#include "chromeos/components/local_search_service/local_search_service_sync_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace chromeos {
......@@ -39,7 +39,7 @@ OsSettingsManagerFactory::OsSettingsManagerFactory()
: BrowserContextKeyedServiceFactory(
"OsSettingsManager",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(local_search_service::LocalSearchServiceFactory::GetInstance());
DependsOn(local_search_service::LocalSearchServiceSyncFactory::GetInstance());
DependsOn(multidevice_setup::MultiDeviceSetupClientFactory::GetInstance());
DependsOn(phonehub::PhoneHubManagerFactory::GetInstance());
DependsOn(ProfileSyncServiceFactory::GetInstance());
......@@ -68,7 +68,7 @@ KeyedService* OsSettingsManagerFactory::BuildServiceInstanceFor(
return new OsSettingsManager(
profile,
local_search_service::LocalSearchServiceFactory::GetForBrowserContext(
local_search_service::LocalSearchServiceSyncFactory::GetForBrowserContext(
context),
multidevice_setup::MultiDeviceSetupClientFactory::GetForProfile(profile),
phonehub::PhoneHubManagerFactory::GetForProfile(profile),
......
......@@ -13,7 +13,7 @@
#include "chrome/browser/ui/webui/settings/chromeos/search/search_concept.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_result_icon.mojom.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/components/local_search_service/local_search_service.h"
#include "chromeos/components/local_search_service/local_search_service_sync.h"
#include "ui/base/l10n/l10n_util.h"
namespace chromeos {
......@@ -44,11 +44,11 @@ SearchHandler::SearchHandler(
SearchTagRegistry* search_tag_registry,
OsSettingsSections* sections,
Hierarchy* hierarchy,
local_search_service::LocalSearchService* local_search_service)
local_search_service::LocalSearchServiceSync* local_search_service)
: search_tag_registry_(search_tag_registry),
sections_(sections),
hierarchy_(hierarchy),
index_(local_search_service->GetIndex(
index_(local_search_service->GetIndexSync(
local_search_service::IndexId::kCrosSettings,
local_search_service::Backend::kLinearMap,
g_browser_process ? g_browser_process->local_state() : nullptr)) {
......@@ -76,11 +76,11 @@ std::vector<mojom::SearchResultPtr> SearchHandler::Search(
uint32_t max_local_search_service_results = 5 * max_num_results;
std::vector<local_search_service::Result> local_search_service_results;
local_search_service::ResponseStatus response_status = index_->Find(
local_search_service::ResponseStatus response_status = index_->FindSync(
query, max_local_search_service_results, &local_search_service_results);
if (response_status != local_search_service::ResponseStatus::kSuccess) {
LOG(ERROR) << "Cannot search; LocalSearchService returned "
LOG(ERROR) << "Cannot search; LocalSearchServiceSync returned "
<< static_cast<int>(response_status)
<< ". Returning empty results array.";
return {};
......
......@@ -11,7 +11,7 @@
#include "base/optional.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search.mojom.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_tag_registry.h"
#include "chromeos/components/local_search_service/index.h"
#include "chromeos/components/local_search_service/index_sync.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
......@@ -21,7 +21,7 @@
namespace chromeos {
namespace local_search_service {
class LocalSearchService;
class LocalSearchServiceSync;
} // namespace local_search_service
namespace settings {
......@@ -33,17 +33,18 @@ struct SearchConcept;
// Handles search queries for Chrome OS settings. Search() is expected to be
// invoked by the settings UI as well as the the Launcher search UI. Search
// results are obtained by matching the provided query against search tags
// indexed in the LocalSearchService and cross-referencing results with
// indexed in the LocalSearchServiceSync and cross-referencing results with
// SearchTagRegistry.
//
// Searches which do not provide any matches result in an empty results array.
class SearchHandler : public mojom::SearchHandler,
public SearchTagRegistry::Observer {
public:
SearchHandler(SearchTagRegistry* search_tag_registry,
OsSettingsSections* sections,
Hierarchy* hierarchy,
local_search_service::LocalSearchService* local_search_service);
SearchHandler(
SearchTagRegistry* search_tag_registry,
OsSettingsSections* sections,
Hierarchy* hierarchy,
local_search_service::LocalSearchServiceSync* local_search_service);
~SearchHandler() override;
SearchHandler(const SearchHandler& other) = delete;
......@@ -107,7 +108,7 @@ class SearchHandler : public mojom::SearchHandler,
SearchTagRegistry* search_tag_registry_;
OsSettingsSections* sections_;
Hierarchy* hierarchy_;
local_search_service::Index* index_;
local_search_service::IndexSync* index_;
// Note: Expected to have multiple clients, so ReceiverSet/RemoteSet are used.
mojo::ReceiverSet<mojom::SearchHandler> receivers_;
......
......@@ -13,7 +13,7 @@
#include "chrome/browser/ui/webui/settings/chromeos/search/search.mojom-test-utils.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_tag_registry.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/components/local_search_service/local_search_service.h"
#include "chromeos/components/local_search_service/local_search_service_sync.h"
#include "chromeos/constants/chromeos_features.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -129,7 +129,7 @@ class SearchHandlerTest : public testing::Test {
}
base::test::TaskEnvironment task_environment_;
local_search_service::LocalSearchService local_search_service_;
local_search_service::LocalSearchServiceSync local_search_service_;
SearchTagRegistry search_tag_registry_;
FakeOsSettingsSections fake_sections_;
FakeHierarchy fake_hierarchy_;
......
......@@ -11,7 +11,7 @@
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_concept.h"
#include "chromeos/components/local_search_service/local_search_service.h"
#include "chromeos/components/local_search_service/local_search_service_sync.h"
#include "chromeos/constants/chromeos_features.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -53,7 +53,7 @@ SearchTagRegistry::ScopedTagUpdater::~ScopedTagUpdater() {
bool is_pending_add = map_entry.second.second;
// If tag metadata is present for this tag, it has already been added and is
// present in LocalSearchService.
// present in LocalSearchServiceSync.
bool is_concept_already_added =
registry_->GetTagMetadata(result_id) != nullptr;
......@@ -99,8 +99,8 @@ void SearchTagRegistry::ScopedTagUpdater::ProcessPendingSearchTags(
}
SearchTagRegistry::SearchTagRegistry(
local_search_service::LocalSearchService* local_search_service)
: index_(local_search_service->GetIndex(
local_search_service::LocalSearchServiceSync* local_search_service)
: index_(local_search_service->GetIndexSync(
local_search_service::IndexId::kCrosSettings,
local_search_service::Backend::kLinearMap,
g_browser_process ? g_browser_process->local_state() : nullptr)) {}
......@@ -121,7 +121,7 @@ SearchTagRegistry::ScopedTagUpdater SearchTagRegistry::StartUpdate() {
void SearchTagRegistry::AddSearchTags(
const std::vector<const SearchConcept*>& search_tags) {
index_->AddOrUpdate(ConceptVectorToDataVector(search_tags));
index_->AddOrUpdateSync(ConceptVectorToDataVector(search_tags));
// Add each concept to the map. Note that it is safe to take the address of
// each concept because all concepts are allocated via static
......@@ -141,7 +141,7 @@ void SearchTagRegistry::RemoveSearchTags(
data_ids.push_back(std::move(result_id));
}
index_->Delete(data_ids);
index_->DeleteSync(data_ids);
NotifyRegistryUpdated();
}
......
......@@ -13,13 +13,13 @@
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "chrome/browser/ui/webui/settings/chromeos/os_settings_section.h"
#include "chromeos/components/local_search_service/index.h"
#include "chromeos/components/local_search_service/index_sync.h"
namespace chromeos {
namespace local_search_service {
class Index;
class LocalSearchService;
class IndexSync;
class LocalSearchServiceSync;
} // namespace local_search_service
namespace settings {
......@@ -27,7 +27,7 @@ namespace settings {
struct SearchConcept;
// Processes all registered search tags by adding/removing them from
// LocalSearchService and providing metadata via GetTagMetadata().
// LocalSearchServiceSync and providing metadata via GetTagMetadata().
class SearchTagRegistry {
public:
class Observer : public base::CheckedObserver {
......@@ -64,7 +64,7 @@ class SearchTagRegistry {
};
SearchTagRegistry(
local_search_service::LocalSearchService* local_search_service);
local_search_service::LocalSearchServiceSync* local_search_service);
SearchTagRegistry(const SearchTagRegistry& other) = delete;
SearchTagRegistry& operator=(const SearchTagRegistry& other) = delete;
virtual ~SearchTagRegistry();
......@@ -79,8 +79,8 @@ class SearchTagRegistry {
ScopedTagUpdater StartUpdate();
// Returns the tag metadata associated with |result_id|, which is the ID
// returned by the LocalSearchService. If no metadata is available, null is
// returned.
// returned by the LocalSearchServiceSync. If no metadata is available, null
// is returned.
const SearchConcept* GetTagMetadata(const std::string& result_id) const;
private:
FRIEND_TEST_ALL_PREFIXES(SearchTagRegistryTest, AddAndRemove);
......@@ -94,11 +94,11 @@ class SearchTagRegistry {
const std::vector<const SearchConcept*>& search_tags);
void NotifyRegistryUpdated();
// Index used by the LocalSearchService for string matching.
local_search_service::Index* index_;
// Index used by the LocalSearchServiceSync for string matching.
local_search_service::IndexSync* index_;
// In-memory cache of all results which have been added to the
// LocalSearchService. Contents are kept in sync with |index_|.
// LocalSearchServiceSync. Contents are kept in sync with |index_|.
std::unordered_map<std::string, const SearchConcept*>
result_id_to_metadata_list_map_;
......
......@@ -9,8 +9,8 @@
#include "chrome/browser/ui/webui/settings/chromeos/constants/routes.mojom.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_concept.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/components/local_search_service/index.h"
#include "chromeos/components/local_search_service/local_search_service.h"
#include "chromeos/components/local_search_service/index_sync.h"
#include "chromeos/components/local_search_service/local_search_service_sync.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
......@@ -69,17 +69,17 @@ class SearchTagRegistryTest : public testing::Test {
// testing::Test:
void SetUp() override {
search_tag_registry_.AddObserver(&observer_);
index_ = local_search_service_.GetIndex(
index_ = local_search_service_.GetIndexSync(
local_search_service::IndexId::kCrosSettings,
local_search_service::Backend::kLinearMap, nullptr /* local_state */);
}
void TearDown() override { search_tag_registry_.RemoveObserver(&observer_); }
local_search_service::LocalSearchService local_search_service_;
local_search_service::LocalSearchServiceSync local_search_service_;
SearchTagRegistry search_tag_registry_;
FakeObserver observer_;
local_search_service::Index* index_;
local_search_service::IndexSync* index_;
};
TEST_F(SearchTagRegistryTest, AddAndRemove) {
......@@ -91,11 +91,11 @@ TEST_F(SearchTagRegistryTest, AddAndRemove) {
// Nothing should have happened yet, since |updater| has not gone out of
// scope.
EXPECT_EQ(0u, index_->GetSize());
EXPECT_EQ(0u, index_->GetSizeSync());
EXPECT_EQ(0u, observer_.num_calls());
}
// Now that it went out of scope, the update should have occurred.
EXPECT_EQ(3u, index_->GetSize());
EXPECT_EQ(3u, index_->GetSizeSync());
EXPECT_EQ(1u, observer_.num_calls());
std::string first_tag_id =
......@@ -115,11 +115,11 @@ TEST_F(SearchTagRegistryTest, AddAndRemove) {
// Tags should not have been removed yet, since |updater| has not gone out
// of scope.
EXPECT_EQ(3u, index_->GetSize());
EXPECT_EQ(3u, index_->GetSizeSync());
EXPECT_EQ(1u, observer_.num_calls());
}
// Now that it went out of scope, the update should have occurred.
EXPECT_EQ(0u, index_->GetSize());
EXPECT_EQ(0u, index_->GetSizeSync());
EXPECT_EQ(2u, observer_.num_calls());
// The tag should no longer be accessible via GetTagMetadata().
......
......@@ -8,18 +8,18 @@ source_set("local_search_service") {
sources = [
"content_extraction_utils.cc",
"content_extraction_utils.h",
"index.cc",
"index.h",
"index_sync.cc",
"index_sync.h",
"inverted_index.cc",
"inverted_index.h",
"inverted_index_search.cc",
"inverted_index_search.h",
"linear_map_search.cc",
"linear_map_search.h",
"local_search_service.cc",
"local_search_service.h",
"local_search_service_factory.cc",
"local_search_service_factory.h",
"local_search_service_sync.cc",
"local_search_service_sync.h",
"local_search_service_sync_factory.cc",
"local_search_service_sync_factory.h",
"pref_names.cc",
"pref_names.h",
"search_metrics_reporter.cc",
......@@ -93,7 +93,7 @@ source_set("unit_tests") {
"inverted_index_unittest.cc",
"linear_map_search_unittest.cc",
"local_search_service_proxy_unittest.cc",
"local_search_service_unittest.cc",
"local_search_service_sync_unittest.cc",
"search_metrics_reporter_unittest.cc",
"search_utils_unittest.cc",
]
......
......@@ -5,12 +5,12 @@
#include "chromeos/components/local_search_service/index_proxy.h"
#include "base/optional.h"
#include "chromeos/components/local_search_service/index.h"
#include "chromeos/components/local_search_service/index_sync.h"
namespace chromeos {
namespace local_search_service {
IndexProxy::IndexProxy(Index* index) : index_(index) {
IndexProxy::IndexProxy(IndexSync* index) : index_(index) {
DCHECK(index_);
}
......@@ -22,19 +22,19 @@ void IndexProxy::BindReceiver(
}
void IndexProxy::GetSize(GetSizeCallback callback) {
const uint64_t num_items = index_->GetSize();
const uint64_t num_items = index_->GetSizeSync();
std::move(callback).Run(num_items);
}
void IndexProxy::AddOrUpdate(const std::vector<Data>& data,
AddOrUpdateCallback callback) {
index_->AddOrUpdate(data);
index_->AddOrUpdateSync(data);
std::move(callback).Run();
}
void IndexProxy::Delete(const std::vector<std::string>& ids,
DeleteCallback callback) {
const uint64_t num_deleted = index_->Delete(ids);
const uint64_t num_deleted = index_->DeleteSync(ids);
std::move(callback).Run(num_deleted);
}
......@@ -42,7 +42,7 @@ void IndexProxy::Find(const base::string16& query,
uint32_t max_results,
FindCallback callback) {
std::vector<Result> results;
ResponseStatus status = index_->Find(query, max_results, &results);
ResponseStatus status = index_->FindSync(query, max_results, &results);
if (status != ResponseStatus::kSuccess) {
std::move(callback).Run(status, base::nullopt);
} else {
......@@ -51,7 +51,7 @@ void IndexProxy::Find(const base::string16& query,
}
void IndexProxy::ClearIndex(ClearIndexCallback callback) {
index_->ClearIndex();
index_->ClearIndexSync();
std::move(callback).Run();
}
......
......@@ -15,11 +15,11 @@
namespace chromeos {
namespace local_search_service {
class Index;
class IndexSync;
class IndexProxy : public mojom::IndexProxy {
public:
explicit IndexProxy(Index* index);
explicit IndexProxy(IndexSync* index);
~IndexProxy() override;
void BindReceiver(mojo::PendingReceiver<mojom::IndexProxy> receiver);
......@@ -36,7 +36,7 @@ class IndexProxy : public mojom::IndexProxy {
void ClearIndex(ClearIndexCallback callback) override;
private:
Index* const index_;
IndexSync* const index_;
mojo::ReceiverSet<mojom::IndexProxy> receivers_;
};
......
......@@ -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 "chromeos/components/local_search_service/index.h"
#include "chromeos/components/local_search_service/index_sync.h"
#include <utility>
......@@ -20,7 +20,7 @@ void LogIndexIdAndBackendType(const std::string& histogram_prefix,
}
std::string IndexIdBasedHistogramPrefix(IndexId index_id) {
const std::string prefix = "LocalSearchService.";
const std::string prefix = "LocalSearchServiceSync.";
switch (index_id) {
case IndexId::kCrosSettings:
return prefix + "CrosSettings";
......@@ -30,7 +30,9 @@ std::string IndexIdBasedHistogramPrefix(IndexId index_id) {
}
} // namespace
Index::Index(IndexId index_id, Backend backend, PrefService* local_state) {
IndexSync::IndexSync(IndexId index_id,
Backend backend,
PrefService* local_state) {
histogram_prefix_ = IndexIdBasedHistogramPrefix(index_id);
DCHECK(!histogram_prefix_.empty());
LogIndexIdAndBackendType(histogram_prefix_, backend);
......@@ -45,11 +47,11 @@ Index::Index(IndexId index_id, Backend backend, PrefService* local_state) {
reporter_->SetIndexId(index_id);
}
Index::~Index() = default;
IndexSync::~IndexSync() = default;
void Index::MaybeLogSearchResultsStats(ResponseStatus status,
size_t num_results,
base::TimeDelta latency) {
void IndexSync::MaybeLogSearchResultsStats(ResponseStatus status,
size_t num_results,
base::TimeDelta latency) {
if (reporter_)
reporter_->OnSearchPerformed();
......@@ -62,19 +64,19 @@ void Index::MaybeLogSearchResultsStats(ResponseStatus status,
}
}
void Index::MaybeLogIndexSize() {
const uint64_t index_size = GetSize();
void IndexSync::MaybeLogIndexSize() {
const uint64_t index_size = GetSizeSync();
if (index_size != 0u) {
base::UmaHistogramCounts10000(histogram_prefix_ + ".NumberDocuments",
index_size);
}
}
void Index::SetSearchParams(const SearchParams& search_params) {
void IndexSync::SetSearchParams(const SearchParams& search_params) {
search_params_ = search_params;
}
SearchParams Index::GetSearchParamsForTesting() {
SearchParams IndexSync::GetSearchParamsForTesting() {
return search_params_;
}
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_INDEX_H_
#define CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_INDEX_H_
#ifndef CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_INDEX_SYNC_H_
#define CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_INDEX_SYNC_H_
#include <map>
#include <memory>
......@@ -23,39 +23,39 @@ class PrefService;
namespace chromeos {
namespace local_search_service {
// A local search service Index.
// A local search service IndexSync.
// It is the client-facing API for search and indexing. It can be implemented
// with different backends that provide actual data storage/indexing/search
// functions.
class Index {
class IndexSync {
public:
Index(IndexId index_id, Backend backend, PrefService* local_state);
virtual ~Index();
IndexSync(IndexId index_id, Backend backend, PrefService* local_state);
virtual ~IndexSync();
Index(const Index&) = delete;
Index& operator=(const Index&) = delete;
IndexSync(const IndexSync&) = delete;
IndexSync& operator=(const IndexSync&) = delete;
// Returns number of data items.
virtual uint64_t GetSize() = 0;
virtual uint64_t GetSizeSync() = 0;
// Adds or updates data.
// IDs of data should not be empty.
virtual void AddOrUpdate(const std::vector<Data>& data) = 0;
virtual void AddOrUpdateSync(const std::vector<Data>& data) = 0;
// Deletes data with |ids| and returns number of items deleted.
// If an id doesn't exist in the Index, no operation will be done.
// IDs should not be empty.
virtual uint32_t Delete(const std::vector<std::string>& ids) = 0;
virtual uint32_t DeleteSync(const std::vector<std::string>& ids) = 0;
// Clears all data in the index.
virtual void ClearIndex() = 0;
virtual void ClearIndexSync() = 0;
// Returns matching results for a given query.
// Zero |max_results| means no max.
// Search behaviour depends on the implementation.
virtual ResponseStatus Find(const base::string16& query,
uint32_t max_results,
std::vector<Result>* results) = 0;
virtual ResponseStatus FindSync(const base::string16& query,
uint32_t max_results,
std::vector<Result>* results) = 0;
// Logs daily search metrics if |reporter_| is non-null. Also logs other
// UMA metrics (number results and search latency).
......@@ -79,10 +79,10 @@ class Index {
private:
std::string histogram_prefix_;
std::unique_ptr<SearchMetricsReporter> reporter_;
base::WeakPtrFactory<Index> weak_ptr_factory_{this};
base::WeakPtrFactory<IndexSync> weak_ptr_factory_{this};
};
} // namespace local_search_service
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_INDEX_H_
#endif // CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_INDEX_SYNC_H_
......@@ -62,7 +62,7 @@ ExtractedContent ExtractDocumentsContent(const std::vector<Data>& data) {
InvertedIndexSearch::InvertedIndexSearch(IndexId index_id,
PrefService* local_state)
: Index(index_id, Backend::kInvertedIndex, local_state),
: IndexSync(index_id, Backend::kInvertedIndex, local_state),
inverted_index_(std::make_unique<InvertedIndex>()),
blocking_task_runner_(base::ThreadPool::CreateSequencedTaskRunner(
{base::TaskPriority::BEST_EFFORT, base::MayBlock(),
......@@ -72,12 +72,12 @@ InvertedIndexSearch::~InvertedIndexSearch() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
uint64_t InvertedIndexSearch::GetSize() {
uint64_t InvertedIndexSearch::GetSizeSync() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return inverted_index_->NumberDocuments();
}
void InvertedIndexSearch::AddOrUpdate(
void InvertedIndexSearch::AddOrUpdateSync(
const std::vector<local_search_service::Data>& data) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!data.empty());
......@@ -89,7 +89,7 @@ void InvertedIndexSearch::AddOrUpdate(
weak_ptr_factory_.GetWeakPtr()));
}
uint32_t InvertedIndexSearch::Delete(const std::vector<std::string>& ids) {
uint32_t InvertedIndexSearch::DeleteSync(const std::vector<std::string>& ids) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!ids.empty());
......@@ -113,13 +113,13 @@ uint32_t InvertedIndexSearch::Delete(const std::vector<std::string>& ids) {
return ids.size();
}
void InvertedIndexSearch::ClearIndex() {
void InvertedIndexSearch::ClearIndexSync() {
inverted_index_->ClearInvertedIndex();
}
ResponseStatus InvertedIndexSearch::Find(const base::string16& query,
uint32_t max_results,
std::vector<Result>* results) {
ResponseStatus InvertedIndexSearch::FindSync(const base::string16& query,
uint32_t max_results,
std::vector<Result>* results) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const base::TimeTicks start = base::TimeTicks::Now();
DCHECK(results);
......@@ -129,7 +129,7 @@ ResponseStatus InvertedIndexSearch::Find(const base::string16& query,
MaybeLogSearchResultsStats(status, 0u, base::TimeDelta());
return status;
}
if (GetSize() == 0u) {
if (GetSizeSync() == 0u) {
const ResponseStatus status = ResponseStatus::kEmptyIndex;
MaybeLogSearchResultsStats(status, 0u, base::TimeDelta());
return status;
......
......@@ -14,7 +14,7 @@
#include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string16.h"
#include "chromeos/components/local_search_service/index.h"
#include "chromeos/components/local_search_service/index_sync.h"
#include "chromeos/components/local_search_service/shared_structs.h"
namespace chromeos {
......@@ -24,7 +24,7 @@ class InvertedIndex;
// An implementation of Index.
// A search via the inverted index backend with TF-IDF based document ranking.
class InvertedIndexSearch : public Index {
class InvertedIndexSearch : public IndexSync {
public:
InvertedIndexSearch(IndexId index_id, PrefService* local_state);
~InvertedIndexSearch() override;
......@@ -33,24 +33,24 @@ class InvertedIndexSearch : public Index {
InvertedIndexSearch& operator=(const InvertedIndexSearch&) = delete;
// Index overrides:
uint64_t GetSize() override;
uint64_t GetSizeSync() override;
// TODO(jiameng): we always build the index after documents are updated. May
// revise this strategy if there is a different use case.
void AddOrUpdate(const std::vector<Data>& data) override;
void AddOrUpdateSync(const std::vector<Data>& data) override;
// TODO(jiameng): we always build the index after documents are deleted. May
// revise this strategy if there is a different use case.
// TODO(jiameng): for inverted index, the Delete function returns |ids| size,
// and not actual number of documents deleted. This would change in the next
// cl when these operations become async.
uint32_t Delete(const std::vector<std::string>& ids) override;
void ClearIndex() override;
uint32_t DeleteSync(const std::vector<std::string>& ids) override;
void ClearIndexSync() override;
// Returns matching results for a given query by approximately matching the
// query with terms in the documents. Documents are ranked by TF-IDF scores.
// Scores in results are positive but not guaranteed to be in any particular
// range.
ResponseStatus Find(const base::string16& query,
uint32_t max_results,
std::vector<Result>* results) override;
ResponseStatus FindSync(const base::string16& query,
uint32_t max_results,
std::vector<Result>* results) override;
// Returns document id and number of occurrences of |term|.
// Document ids are sorted in alphabetical order.
......
......@@ -48,9 +48,9 @@ TEST_F(InvertedIndexSearchTest, Add) {
{"id2", {{"cid_3", "help article on wi-fi"}}}};
const std::vector<Data> data = CreateTestData(data_to_register);
search_->AddOrUpdate(data);
search_->AddOrUpdateSync(data);
Wait();
EXPECT_EQ(search_->GetSize(), 2u);
EXPECT_EQ(search_->GetSizeSync(), 2u);
{
// "network" does not exist in the index.
......@@ -104,9 +104,9 @@ TEST_F(InvertedIndexSearchTest, Update) {
{"id2", {{"cid_3", "help article on wi-fi"}}}};
const std::vector<Data> data = CreateTestData(data_to_register);
search_->AddOrUpdate(data);
search_->AddOrUpdateSync(data);
Wait();
EXPECT_EQ(search_->GetSize(), 2u);
EXPECT_EQ(search_->GetSizeSync(), 2u);
const std::map<std::string, std::vector<ContentWithId>> data_to_update = {
{"id1",
......@@ -115,9 +115,9 @@ TEST_F(InvertedIndexSearchTest, Update) {
{"id3", {{"cid_3", "Google Map"}}}};
const std::vector<Data> updated_data = CreateTestData(data_to_update);
search_->AddOrUpdate(updated_data);
search_->AddOrUpdateSync(updated_data);
Wait();
EXPECT_EQ(search_->GetSize(), 3u);
EXPECT_EQ(search_->GetSizeSync(), 3u);
{
const TermOccurrence doc_with_freq =
......@@ -146,7 +146,7 @@ TEST_F(InvertedIndexSearchTest, Update) {
}
}
TEST_F(InvertedIndexSearchTest, Delete) {
TEST_F(InvertedIndexSearchTest, DeleteSync) {
const std::map<std::string, std::vector<ContentWithId>> data_to_register = {
{"id1",
{{"cid_1", "This is a help wi-fi article"},
......@@ -154,11 +154,11 @@ TEST_F(InvertedIndexSearchTest, Delete) {
{"id2", {{"cid_3", "help article on wi-fi"}}}};
const std::vector<Data> data = CreateTestData(data_to_register);
search_->AddOrUpdate(data);
search_->AddOrUpdateSync(data);
Wait();
EXPECT_EQ(search_->GetSize(), 2u);
EXPECT_EQ(search_->GetSizeSync(), 2u);
EXPECT_EQ(search_->Delete({"id1", "id3"}), 2u);
EXPECT_EQ(search_->DeleteSync({"id1", "id3"}), 2u);
Wait();
{
......@@ -170,7 +170,7 @@ TEST_F(InvertedIndexSearchTest, Delete) {
}
}
TEST_F(InvertedIndexSearchTest, ClearIndex) {
TEST_F(InvertedIndexSearchTest, ClearIndexSync) {
const std::map<std::string, std::vector<ContentWithId>> data_to_register = {
{"id1",
{{"cid_1", "This is a help wi-fi article"},
......@@ -179,13 +179,13 @@ TEST_F(InvertedIndexSearchTest, ClearIndex) {
const std::vector<Data> data = CreateTestData(data_to_register);
search_->AddOrUpdate(data);
search_->AddOrUpdateSync(data);
Wait();
EXPECT_EQ(search_->GetSize(), 2u);
EXPECT_EQ(search_->GetSizeSync(), 2u);
search_->ClearIndex();
search_->ClearIndexSync();
Wait();
EXPECT_EQ(search_->GetSize(), 0u);
EXPECT_EQ(search_->GetSizeSync(), 0u);
}
TEST_F(InvertedIndexSearchTest, Find) {
......@@ -198,44 +198,45 @@ TEST_F(InvertedIndexSearchTest, Find) {
// Nothing has been added to the index.
std::vector<Result> results;
EXPECT_EQ(
search_->Find(base::UTF8ToUTF16("network"), /*max_results=*/10, &results),
ResponseStatus::kEmptyIndex);
EXPECT_EQ(search_->FindSync(base::UTF8ToUTF16("network"), /*max_results=*/10,
&results),
ResponseStatus::kEmptyIndex);
EXPECT_TRUE(results.empty());
// Data is added and then deleted from index, making the index empty.
search_->AddOrUpdate(data);
search_->AddOrUpdateSync(data);
Wait();
EXPECT_EQ(search_->GetSize(), 2u);
EXPECT_EQ(search_->Delete({"id1", "id2"}), 2u);
EXPECT_EQ(search_->GetSizeSync(), 2u);
EXPECT_EQ(search_->DeleteSync({"id1", "id2"}), 2u);
Wait();
EXPECT_EQ(search_->GetSize(), 0u);
EXPECT_EQ(search_->GetSizeSync(), 0u);
EXPECT_EQ(
search_->Find(base::UTF8ToUTF16("network"), /*max_results=*/10, &results),
ResponseStatus::kEmptyIndex);
EXPECT_EQ(search_->FindSync(base::UTF8ToUTF16("network"), /*max_results=*/10,
&results),
ResponseStatus::kEmptyIndex);
EXPECT_TRUE(results.empty());
// Index is populated again, but query is empty.
search_->AddOrUpdate(data);
search_->AddOrUpdateSync(data);
Wait();
EXPECT_EQ(search_->GetSize(), 2u);
EXPECT_EQ(search_->GetSizeSync(), 2u);
EXPECT_EQ(search_->Find(base::UTF8ToUTF16(""), /*max_results=*/10, &results),
ResponseStatus::kEmptyQuery);
EXPECT_EQ(
search_->FindSync(base::UTF8ToUTF16(""), /*max_results=*/10, &results),
ResponseStatus::kEmptyQuery);
EXPECT_TRUE(results.empty());
// No document is found for a given query.
EXPECT_EQ(search_->Find(base::UTF8ToUTF16("networkstuff"), /*max_results=*/10,
&results),
EXPECT_EQ(search_->FindSync(base::UTF8ToUTF16("networkstuff"),
/*max_results=*/10, &results),
ResponseStatus::kSuccess);
EXPECT_TRUE(results.empty());
{
// A document is found.
// Query's case is normalized.
EXPECT_EQ(search_->Find(base::UTF8ToUTF16("ANOTHER networkstuff"),
/*max_results=*/10, &results),
EXPECT_EQ(search_->FindSync(base::UTF8ToUTF16("ANOTHER networkstuff"),
/*max_results=*/10, &results),
ResponseStatus::kSuccess);
EXPECT_EQ(results.size(), 1u);
......@@ -251,8 +252,8 @@ TEST_F(InvertedIndexSearchTest, Find) {
{
// Two documents are found.
EXPECT_EQ(search_->Find(base::UTF8ToUTF16("another help"),
/*max_results=*/10, &results),
EXPECT_EQ(search_->FindSync(base::UTF8ToUTF16("another help"),
/*max_results=*/10, &results),
ResponseStatus::kSuccess);
EXPECT_EQ(results.size(), 2u);
......@@ -282,8 +283,8 @@ TEST_F(InvertedIndexSearchTest, Find) {
{
// Same as above, but max number of results is set to 1.
EXPECT_EQ(search_->Find(base::UTF8ToUTF16("another help"),
/*max_results=*/1, &results),
EXPECT_EQ(search_->FindSync(base::UTF8ToUTF16("another help"),
/*max_results=*/1, &results),
ResponseStatus::kSuccess);
EXPECT_EQ(results.size(), 1u);
EXPECT_EQ(results[0].id, "id1");
......@@ -291,14 +292,14 @@ TEST_F(InvertedIndexSearchTest, Find) {
{
// Same as above, but set max_results to 0, meaning no max.
EXPECT_EQ(search_->Find(base::UTF8ToUTF16("another help"),
/*max_results=*/0, &results),
EXPECT_EQ(search_->FindSync(base::UTF8ToUTF16("another help"),
/*max_results=*/0, &results),
ResponseStatus::kSuccess);
EXPECT_EQ(results.size(), 2u);
}
}
TEST_F(InvertedIndexSearchTest, SequenceOfDeletes) {
TEST_F(InvertedIndexSearchTest, SequenceOfDeleteSyncs) {
const std::map<std::string, std::vector<ContentWithId>> data_to_register = {
{"id1",
{{"cid_1", "This is a help wi-fi article"},
......@@ -306,7 +307,7 @@ TEST_F(InvertedIndexSearchTest, SequenceOfDeletes) {
{"id2", {{"cid_3", "help article on wi-fi"}}}};
const std::vector<Data> data = CreateTestData(data_to_register);
search_->AddOrUpdate(data);
search_->AddOrUpdateSync(data);
const std::map<std::string, std::vector<ContentWithId>> data_to_update = {
{"id1",
......@@ -315,14 +316,14 @@ TEST_F(InvertedIndexSearchTest, SequenceOfDeletes) {
{"id3", {{"cid_3", "Google Map"}}}};
const std::vector<Data> updated_data = CreateTestData(data_to_update);
search_->AddOrUpdate(updated_data);
search_->AddOrUpdateSync(updated_data);
EXPECT_EQ(search_->Delete({"id1"}), 1u);
EXPECT_EQ(search_->Delete({"id2", "id3"}), 2u);
EXPECT_EQ(search_->DeleteSync({"id1"}), 1u);
EXPECT_EQ(search_->DeleteSync({"id2", "id3"}), 2u);
// Force all operations to complete.
Wait();
EXPECT_EQ(search_->GetSize(), 0u);
EXPECT_EQ(search_->GetSizeSync(), 0u);
}
} // namespace local_search_service
......
......@@ -70,15 +70,15 @@ bool IsItemRelevant(const TokenizedString& query,
} // namespace
LinearMapSearch::LinearMapSearch(IndexId index_id, PrefService* local_state)
: Index(index_id, Backend::kLinearMap, local_state) {}
: IndexSync(index_id, Backend::kLinearMap, local_state) {}
LinearMapSearch::~LinearMapSearch() = default;
uint64_t LinearMapSearch::GetSize() {
uint64_t LinearMapSearch::GetSizeSync() {
return data_.size();
}
void LinearMapSearch::AddOrUpdate(
void LinearMapSearch::AddOrUpdateSync(
const std::vector<local_search_service::Data>& data) {
for (const auto& item : data) {
const auto& id = item.id;
......@@ -92,7 +92,7 @@ void LinearMapSearch::AddOrUpdate(
MaybeLogIndexSize();
}
uint32_t LinearMapSearch::Delete(const std::vector<std::string>& ids) {
uint32_t LinearMapSearch::DeleteSync(const std::vector<std::string>& ids) {
uint32_t num_deleted = 0u;
for (const auto& id : ids) {
DCHECK(!id.empty());
......@@ -109,13 +109,13 @@ uint32_t LinearMapSearch::Delete(const std::vector<std::string>& ids) {
return num_deleted;
}
void LinearMapSearch::ClearIndex() {
void LinearMapSearch::ClearIndexSync() {
data_.clear();
}
ResponseStatus LinearMapSearch::Find(const base::string16& query,
uint32_t max_results,
std::vector<Result>* results) {
ResponseStatus LinearMapSearch::FindSync(const base::string16& query,
uint32_t max_results,
std::vector<Result>* results) {
const base::TimeTicks start = base::TimeTicks::Now();
DCHECK(results);
results->clear();
......
......@@ -12,7 +12,7 @@
#include "base/macros.h"
#include "base/strings/string16.h"
#include "chromeos/components/local_search_service/index.h"
#include "chromeos/components/local_search_service/index_sync.h"
#include "chromeos/components/local_search_service/shared_structs.h"
class PrefService;
......@@ -29,7 +29,7 @@ namespace local_search_service {
// A search backend that linearly scans all documents in the storage and finds
// documents that match the input query. Search is done by matching query with
// documents' search tags.
class LinearMapSearch : public Index {
class LinearMapSearch : public IndexSync {
public:
LinearMapSearch(IndexId index_id, PrefService* local_state);
~LinearMapSearch() override;
......@@ -38,16 +38,16 @@ class LinearMapSearch : public Index {
LinearMapSearch& operator=(const LinearMapSearch&) = delete;
// Index overrides:
uint64_t GetSize() override;
void AddOrUpdate(const std::vector<Data>& data) override;
uint32_t Delete(const std::vector<std::string>& ids) override;
void ClearIndex() override;
uint64_t GetSizeSync() override;
void AddOrUpdateSync(const std::vector<Data>& data) override;
uint32_t DeleteSync(const std::vector<std::string>& ids) override;
void ClearIndexSync() override;
// For each data in the index, we return the 1st search tag that matches
// the query (i.e. above the threshold). Client should put the most
// important search tag first when registering the data in the index.
ResponseStatus Find(const base::string16& query,
uint32_t max_results,
std::vector<Result>* results) override;
ResponseStatus FindSync(const base::string16& query,
uint32_t max_results,
std::vector<Result>* results) override;
private:
// Returns all search results for a given query.
......
......@@ -40,7 +40,8 @@ void FindAndCheckResults(LinearMapSearch* index,
DCHECK(index);
std::vector<Result> results;
auto status = index->Find(base::UTF8ToUTF16(query), max_results, &results);
auto status =
index->FindSync(base::UTF8ToUTF16(query), max_results, &results);
EXPECT_EQ(status, expected_status);
......@@ -107,8 +108,8 @@ TEST_F(LinearMapSearchTest, RelevanceThreshold) {
const std::map<std::string, std::vector<ContentWithId>> data_to_register = {
{"id1", {{"tag1", "Wi-Fi"}}}, {"id2", {{"tag2", "famous"}}}};
std::vector<Data> data = CreateTestData(data_to_register);
index_->AddOrUpdate(data);
EXPECT_EQ(index_->GetSize(), 2u);
index_->AddOrUpdateSync(data);
EXPECT_EQ(index_->GetSizeSync(), 2u);
{
SearchParams search_params;
search_params.relevance_threshold = 0.0;
......@@ -145,8 +146,8 @@ TEST_F(LinearMapSearchTest, MaxResults) {
{"id1", {{"tag1", "abcde"}, {"tag2", "Wi-Fi"}}},
{"id2", {{"tag3", "wifi"}}}};
std::vector<Data> data = CreateTestData(data_to_register);
index_->AddOrUpdate(data);
EXPECT_EQ(index_->GetSize(), 2u);
index_->AddOrUpdateSync(data);
EXPECT_EQ(index_->GetSizeSync(), 2u);
SearchParams search_params;
search_params.relevance_threshold = 0.3;
index_->SetSearchParams(search_params);
......@@ -173,8 +174,8 @@ TEST_F(LinearMapSearchTest, ResultFound) {
std::vector<Data> data = CreateTestData(data_to_register);
EXPECT_EQ(data.size(), 2u);
index_->AddOrUpdate(data);
EXPECT_EQ(index_->GetSize(), 2u);
index_->AddOrUpdateSync(data);
EXPECT_EQ(index_->GetSizeSync(), 2u);
// Find result with query "id1". It returns an exact match.
const std::vector<ResultWithIds> expected_results = {{"id1", {"cid1"}}};
......@@ -192,11 +193,11 @@ TEST_F(LinearMapSearchTest, ClearIndex) {
std::vector<Data> data = CreateTestData(data_to_register);
EXPECT_EQ(data.size(), 2u);
index_->AddOrUpdate(data);
EXPECT_EQ(index_->GetSize(), 2u);
index_->AddOrUpdateSync(data);
EXPECT_EQ(index_->GetSizeSync(), 2u);
index_->ClearIndex();
EXPECT_EQ(index_->GetSize(), 0u);
index_->ClearIndexSync();
EXPECT_EQ(index_->GetSizeSync(), 0u);
}
} // namespace local_search_service
......
......@@ -5,7 +5,7 @@
#include "chromeos/components/local_search_service/local_search_service_proxy.h"
#include "chromeos/components/local_search_service/index_proxy.h"
#include "chromeos/components/local_search_service/local_search_service.h"
#include "chromeos/components/local_search_service/local_search_service_sync.h"
#include "chromeos/components/local_search_service/shared_structs.h"
#include "components/prefs/pref_service.h"
......@@ -13,7 +13,7 @@ namespace chromeos {
namespace local_search_service {
LocalSearchServiceProxy::LocalSearchServiceProxy(
local_search_service::LocalSearchService* local_search_service)
local_search_service::LocalSearchServiceSync* local_search_service)
: service_(local_search_service) {
DCHECK(service_);
}
......@@ -34,7 +34,7 @@ void LocalSearchServiceProxy::GetIndex(
mojo::PendingReceiver<mojom::IndexProxy> index_receiver) {
auto it = indices_.find(index_id);
if (it == indices_.end()) {
Index* index = service_->GetIndex(index_id, backend, local_state);
IndexSync* index = service_->GetIndexSync(index_id, backend, local_state);
it = indices_.emplace(index_id, std::make_unique<IndexProxy>(index)).first;
}
it->second->BindReceiver(std::move(index_receiver));
......
......@@ -17,7 +17,7 @@ class PrefService;
namespace chromeos {
namespace local_search_service {
class LocalSearchService;
class LocalSearchServiceSync;
class IndexProxy;
enum class IndexId;
enum class Backend;
......@@ -25,7 +25,8 @@ enum class Backend;
class LocalSearchServiceProxy : public mojom::LocalSearchServiceProxy,
public KeyedService {
public:
explicit LocalSearchServiceProxy(LocalSearchService* local_search_service);
explicit LocalSearchServiceProxy(
LocalSearchServiceSync* local_search_service);
~LocalSearchServiceProxy() override;
LocalSearchServiceProxy(const LocalSearchServiceProxy&) = delete;
......@@ -53,7 +54,7 @@ class LocalSearchServiceProxy : public mojom::LocalSearchServiceProxy,
mojo::PendingReceiver<mojom::IndexProxy> index_receiver);
private:
LocalSearchService* const service_;
LocalSearchServiceSync* const service_;
mojo::ReceiverSet<mojom::LocalSearchServiceProxy> receivers_;
std::map<IndexId, std::unique_ptr<IndexProxy>> indices_;
};
......
......@@ -4,8 +4,8 @@
#include "chromeos/components/local_search_service/local_search_service_proxy_factory.h"
#include "chromeos/components/local_search_service/local_search_service_factory.h"
#include "chromeos/components/local_search_service/local_search_service_proxy.h"
#include "chromeos/components/local_search_service/local_search_service_sync_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace chromeos {
......@@ -29,7 +29,7 @@ LocalSearchServiceProxyFactory::LocalSearchServiceProxyFactory()
: BrowserContextKeyedServiceFactory(
"LocalSearchServiceProxy",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(LocalSearchServiceFactory::GetInstance());
DependsOn(LocalSearchServiceSyncFactory::GetInstance());
}
LocalSearchServiceProxyFactory::~LocalSearchServiceProxyFactory() = default;
......@@ -44,7 +44,7 @@ KeyedService* LocalSearchServiceProxyFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
DCHECK(context);
return new LocalSearchServiceProxy(
LocalSearchServiceFactory::GetForBrowserContext(context));
LocalSearchServiceSyncFactory::GetForBrowserContext(context));
}
} // namespace local_search_service
......
......@@ -8,7 +8,7 @@
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "chromeos/components/local_search_service/index_proxy.h"
#include "chromeos/components/local_search_service/local_search_service.h"
#include "chromeos/components/local_search_service/local_search_service_sync.h"
#include "chromeos/components/local_search_service/mojom/types.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -29,7 +29,7 @@ class LocalSearchServiceProxyTest : public testing::Test {
private:
base::test::TaskEnvironment task_environment_;
LocalSearchService service_;
LocalSearchServiceSync service_;
std::unique_ptr<LocalSearchServiceProxy> service_proxy_;
};
......
......@@ -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 "chromeos/components/local_search_service/local_search_service.h"
#include "chromeos/components/local_search_service/local_search_service_sync.h"
#include <utility>
......@@ -12,13 +12,13 @@
namespace chromeos {
namespace local_search_service {
LocalSearchService::LocalSearchService() = default;
LocalSearchServiceSync::LocalSearchServiceSync() = default;
LocalSearchService::~LocalSearchService() = default;
LocalSearchServiceSync::~LocalSearchServiceSync() = default;
Index* LocalSearchService::GetIndex(IndexId index_id,
Backend backend,
PrefService* local_state) {
IndexSync* LocalSearchServiceSync::GetIndexSync(IndexId index_id,
Backend backend,
PrefService* local_state) {
auto it = indices_.find(index_id);
if (it == indices_.end()) {
switch (backend) {
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_H_
#define CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_H_
#ifndef CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_SYNC_H_
#define CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_SYNC_H_
#include <map>
#include <memory>
......@@ -18,24 +18,26 @@ namespace chromeos {
namespace local_search_service {
class Index;
class IndexSync;
// LocalSearchService creates and owns content-specific Indices. Clients can
// call it |GetIndex| method to get an Index for a given index id.
class LocalSearchService : public KeyedService {
// LocalSearchServiceSync creates and owns content-specific Indices. Clients can
// call it |GetIndexSync| method to get an IndexSync for a given index id.
class LocalSearchServiceSync : public KeyedService {
public:
LocalSearchService();
~LocalSearchService() override;
LocalSearchService(const LocalSearchService&) = delete;
LocalSearchService& operator=(const LocalSearchService&) = delete;
LocalSearchServiceSync();
~LocalSearchServiceSync() override;
LocalSearchServiceSync(const LocalSearchServiceSync&) = delete;
LocalSearchServiceSync& operator=(const LocalSearchServiceSync&) = delete;
Index* GetIndex(IndexId index_id, Backend backend, PrefService* local_state);
IndexSync* GetIndexSync(IndexId index_id,
Backend backend,
PrefService* local_state);
private:
std::map<IndexId, std::unique_ptr<Index>> indices_;
std::map<IndexId, std::unique_ptr<IndexSync>> indices_;
};
} // namespace local_search_service
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_H_
#endif // CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_SYNC_H_
......@@ -2,41 +2,41 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/components/local_search_service/local_search_service_factory.h"
#include "chromeos/components/local_search_service/local_search_service_sync_factory.h"
#include "chromeos/components/local_search_service/local_search_service.h"
#include "chromeos/components/local_search_service/local_search_service_sync.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace chromeos {
namespace local_search_service {
LocalSearchService* LocalSearchServiceFactory::GetForBrowserContext(
LocalSearchServiceSync* LocalSearchServiceSyncFactory::GetForBrowserContext(
content::BrowserContext* context) {
return static_cast<LocalSearchService*>(
LocalSearchServiceFactory::GetInstance()->GetServiceForBrowserContext(
return static_cast<LocalSearchServiceSync*>(
LocalSearchServiceSyncFactory::GetInstance()->GetServiceForBrowserContext(
context, true /* create */));
}
LocalSearchServiceFactory* LocalSearchServiceFactory::GetInstance() {
return base::Singleton<LocalSearchServiceFactory>::get();
LocalSearchServiceSyncFactory* LocalSearchServiceSyncFactory::GetInstance() {
return base::Singleton<LocalSearchServiceSyncFactory>::get();
}
LocalSearchServiceFactory::LocalSearchServiceFactory()
LocalSearchServiceSyncFactory::LocalSearchServiceSyncFactory()
: BrowserContextKeyedServiceFactory(
"LocalSearchService",
"LocalSearchServiceSync",
BrowserContextDependencyManager::GetInstance()) {}
LocalSearchServiceFactory::~LocalSearchServiceFactory() = default;
LocalSearchServiceSyncFactory::~LocalSearchServiceSyncFactory() = default;
content::BrowserContext* LocalSearchServiceFactory::GetBrowserContextToUse(
content::BrowserContext* LocalSearchServiceSyncFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
// The service should exist in incognito mode.
return context;
}
KeyedService* LocalSearchServiceFactory::BuildServiceInstanceFor(
KeyedService* LocalSearchServiceSyncFactory::BuildServiceInstanceFor(
content::BrowserContext* /* context */) const {
return new LocalSearchService();
return new LocalSearchServiceSync();
}
} // namespace local_search_service
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_FACTORY_H_
#define CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_FACTORY_H_
#ifndef CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_SYNC_FACTORY_H_
#define CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_SYNC_FACTORY_H_
#include "base/macros.h"
#include "base/memory/singleton.h"
......@@ -13,24 +13,24 @@ namespace chromeos {
namespace local_search_service {
class LocalSearchService;
class LocalSearchServiceSync;
class LocalSearchServiceFactory : public BrowserContextKeyedServiceFactory {
class LocalSearchServiceSyncFactory : public BrowserContextKeyedServiceFactory {
public:
static LocalSearchService* GetForBrowserContext(
static LocalSearchServiceSync* GetForBrowserContext(
content::BrowserContext* context);
static LocalSearchServiceFactory* GetInstance();
static LocalSearchServiceSyncFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<LocalSearchServiceFactory>;
friend struct base::DefaultSingletonTraits<LocalSearchServiceSyncFactory>;
LocalSearchServiceFactory();
~LocalSearchServiceFactory() override;
LocalSearchServiceSyncFactory();
~LocalSearchServiceSyncFactory() override;
LocalSearchServiceFactory(const LocalSearchServiceFactory&) = delete;
LocalSearchServiceFactory& operator=(const LocalSearchServiceFactory&) =
delete;
LocalSearchServiceSyncFactory(const LocalSearchServiceSyncFactory&) = delete;
LocalSearchServiceSyncFactory& operator=(
const LocalSearchServiceSyncFactory&) = delete;
// BrowserContextKeyedServiceFactory overrides.
content::BrowserContext* GetBrowserContextToUse(
......@@ -42,4 +42,4 @@ class LocalSearchServiceFactory : public BrowserContextKeyedServiceFactory {
} // namespace local_search_service
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_FACTORY_H_
#endif // CHROMEOS_COMPONENTS_LOCAL_SEARCH_SERVICE_LOCAL_SEARCH_SERVICE_SYNC_FACTORY_H_
......@@ -10,36 +10,36 @@
#include <vector>
#include "base/test/task_environment.h"
#include "chromeos/components/local_search_service/index.h"
#include "chromeos/components/local_search_service/local_search_service.h"
#include "chromeos/components/local_search_service/index_sync.h"
#include "chromeos/components/local_search_service/local_search_service_sync.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace local_search_service {
class LocalSearchServiceTest : public testing::Test {
class LocalSearchServiceSyncTest : public testing::Test {
protected:
LocalSearchService service_;
LocalSearchServiceSync service_;
base::test::TaskEnvironment task_environment_{
base::test::TaskEnvironment::MainThreadType::DEFAULT,
base::test::TaskEnvironment::ThreadPoolExecutionMode::QUEUED};
};
TEST_F(LocalSearchServiceTest, GetLinearMapSearch) {
Index* const index = service_.GetIndex(
TEST_F(LocalSearchServiceSyncTest, GetLinearMapSearch) {
IndexSync* const index = service_.GetIndexSync(
IndexId::kCrosSettings, Backend::kLinearMap, nullptr /* local_state */);
CHECK(index);
EXPECT_EQ(index->GetSize(), 0u);
EXPECT_EQ(index->GetSizeSync(), 0u);
}
TEST_F(LocalSearchServiceTest, GetInvertedIndexSearch) {
Index* const index =
service_.GetIndex(IndexId::kCrosSettings, Backend::kInvertedIndex,
nullptr /* local_state */);
TEST_F(LocalSearchServiceSyncTest, GetInvertedIndexSearch) {
IndexSync* const index =
service_.GetIndexSync(IndexId::kCrosSettings, Backend::kInvertedIndex,
nullptr /* local_state */);
CHECK(index);
EXPECT_EQ(index->GetSize(), 0u);
EXPECT_EQ(index->GetSizeSync(), 0u);
}
} // namespace local_search_service
......
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