-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[omnibox][calc] Create
ProviderStateService
to cache across windows.
Before this CL, the calc provider uses a local field `cache_` to cache calc matches. Providers are created per window. So the `cache_` isn't shared across windows. If you open 2 browser windows, they can show different cached calc matches based on your previous inputs in each window. This CL creates a `ProviderStateService` to manage provider state that needs to be shared across windows. The calc cache is the only state it holds with this CL. We can move the doc and HUP caches here as well in the future. Also adds a 'Omnibox.NumCalculatorMatches' histogram. Bug: 1470347 Change-Id: I0980213450864f5ecd7de022a703a3a01a0184f1 Low-Coverage-Reason: TRIVIAL_CHANGE for chrome_autocomplete_provider_client.cc & autocomplete_provider_client_impl.mm . Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4867171 Commit-Queue: manuk hovanesian <manukh@chromium.org> Reviewed-by: Ryan Sultanem <rsult@google.com> Reviewed-by: Stepan Khapugin <stkhapugin@chromium.org> Reviewed-by: Orin Jaworski <orinj@chromium.org> Cr-Commit-Position: refs/heads/main@{#1215490}
- Loading branch information
manukh
authored and
Chromium LUCI CQ
committed
Oct 26, 2023
1 parent
ea9cc41
commit 35ad23e
Showing
24 changed files
with
592 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
chrome/browser/autocomplete/provider_state_service_factory.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/autocomplete/provider_state_service_factory.h" | ||
|
||
#include <memory> | ||
|
||
#include "base/no_destructor.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/profiles/profile_selections.h" | ||
#include "components/omnibox/browser/provider_state_service.h" | ||
#include "content/public/browser/browser_context.h" | ||
|
||
// static | ||
ProviderStateService* ProviderStateServiceFactory::GetForProfile( | ||
Profile* profile) { | ||
return static_cast<ProviderStateService*>( | ||
GetInstance()->GetServiceForBrowserContext(profile, true)); | ||
} | ||
|
||
// static | ||
ProviderStateServiceFactory* ProviderStateServiceFactory::GetInstance() { | ||
static base::NoDestructor<ProviderStateServiceFactory> instance; | ||
return instance.get(); | ||
} | ||
|
||
ProviderStateServiceFactory::ProviderStateServiceFactory() | ||
: ProfileKeyedServiceFactory("ProviderStateService", | ||
ProfileSelections::Builder() | ||
.WithAshInternals(ProfileSelection::kNone) | ||
.Build()) {} | ||
|
||
ProviderStateServiceFactory::~ProviderStateServiceFactory() = default; | ||
|
||
std::unique_ptr<KeyedService> | ||
ProviderStateServiceFactory::BuildServiceInstanceForBrowserContext( | ||
content::BrowserContext* context) const { | ||
return std::make_unique<ProviderStateService>(); | ||
} |
39 changes: 39 additions & 0 deletions
39
chrome/browser/autocomplete/provider_state_service_factory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_AUTOCOMPLETE_PROVIDER_STATE_SERVICE_FACTORY_H_ | ||
#define CHROME_BROWSER_AUTOCOMPLETE_PROVIDER_STATE_SERVICE_FACTORY_H_ | ||
|
||
#include "base/no_destructor.h" | ||
#include "chrome/browser/profiles/profile_keyed_service_factory.h" | ||
|
||
class KeyedService; | ||
class Profile; | ||
struct ProviderStateService; | ||
|
||
namespace content { | ||
class BrowserContext; | ||
} | ||
|
||
class ProviderStateServiceFactory : public ProfileKeyedServiceFactory { | ||
public: | ||
static ProviderStateService* GetForProfile(Profile* profile); | ||
static ProviderStateServiceFactory* GetInstance(); | ||
|
||
ProviderStateServiceFactory(const ProviderStateServiceFactory&) = delete; | ||
ProviderStateServiceFactory& operator=(const ProviderStateServiceFactory&) = | ||
delete; | ||
|
||
private: | ||
friend base::NoDestructor<ProviderStateServiceFactory>; | ||
|
||
ProviderStateServiceFactory(); | ||
~ProviderStateServiceFactory() override; | ||
|
||
// Overrides from BrowserContextKeyedServiceFactory: | ||
std::unique_ptr<KeyedService> BuildServiceInstanceForBrowserContext( | ||
content::BrowserContext* context) const override; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_AUTOCOMPLETE_PROVIDER_STATE_FACTORY_H_ |
51 changes: 51 additions & 0 deletions
51
chrome/browser/autocomplete/provider_state_service_factory_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/autocomplete/provider_state_service_factory.h" | ||
|
||
#include "chrome/browser/profiles/profile_testing_helper.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
class ProviderStateServiceFactoryTest : public testing::Test { | ||
protected: | ||
ProfileTestingHelper profile_testing_helper_; | ||
}; | ||
|
||
TEST_F(ProviderStateServiceFactoryTest, PrefEnabledReturnsValidService) { | ||
profile_testing_helper_.SetUp(); | ||
|
||
EXPECT_TRUE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.regular_profile())); | ||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.incognito_profile())); | ||
|
||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.guest_profile())); | ||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.guest_profile_otr())); | ||
|
||
#if !BUILDFLAG(IS_CHROMEOS_ASH) && !BUILDFLAG(IS_ANDROID) | ||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.system_profile())); | ||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.system_profile_otr())); | ||
#endif // !BUILDFLAG(IS_CHROMEOS_ASH) && !BUILDFLAG(IS_ANDROID) | ||
|
||
#if BUILDFLAG(IS_CHROMEOS_ASH) | ||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.signin_profile())); | ||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.signin_profile_otr())); | ||
|
||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.lockscreen_profile())); | ||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.lockscreen_profile_otr())); | ||
|
||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.lockscreenapp_profile())); | ||
EXPECT_FALSE(ProviderStateServiceFactory::GetForProfile( | ||
profile_testing_helper_.lockscreenapp_profile_otr())); | ||
#endif // BUILDFLAG(IS_CHROMEOS_ASH) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.