forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Omnibox: Make QueryInOmniboxFactory so Java bridge is all-static.
QueryInOmnibox functionality is intrinsically profile-keyed, since it relies on two other profile-keyed services (AutocompleteClassifier and TemplateURLService). This suggests that QueryInOmnibox should also be a BrowserContextKeyedService, just like those two classes. If QueryInOmnibox is profile-keyed, it would be burdensome to have the Java side manage its own instances, so this CL also makes all the Java exposed methods static, with a Profile key. Bug: 874592 Change-Id: Ic8de22b4d19479a349129e24b9e8732a06002ff0 Reviewed-on: https://chromium-review.googlesource.com/1199818 Reviewed-by: Ted Choc <tedchoc@chromium.org> Commit-Queue: Tommy Li <tommycli@chromium.org> Cr-Commit-Position: refs/heads/master@{#588567}
- Loading branch information
Tommy C. Li
authored and
Commit Bot
committed
Sep 4, 2018
1 parent
9b3146a
commit d5db3d9
Showing
8 changed files
with
135 additions
and
108 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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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/ui/omnibox/query_in_omnibox_factory.h" | ||
|
||
#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | ||
#include "chrome/browser/profiles/incognito_helpers.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/search_engines/template_url_service_factory.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
#include "components/omnibox/browser/query_in_omnibox.h" | ||
|
||
// static | ||
QueryInOmnibox* QueryInOmniboxFactory::GetForProfile(Profile* profile) { | ||
return static_cast<QueryInOmnibox*>( | ||
GetInstance()->GetServiceForBrowserContext(profile, true)); | ||
} | ||
|
||
// static | ||
QueryInOmniboxFactory* QueryInOmniboxFactory::GetInstance() { | ||
return base::Singleton<QueryInOmniboxFactory>::get(); | ||
} | ||
|
||
// static | ||
std::unique_ptr<KeyedService> QueryInOmniboxFactory::BuildInstanceFor( | ||
content::BrowserContext* context) { | ||
Profile* profile = static_cast<Profile*>(context); | ||
return std::make_unique<QueryInOmnibox>( | ||
AutocompleteClassifierFactory::GetForProfile(profile), | ||
TemplateURLServiceFactory::GetForProfile(profile)); | ||
} | ||
|
||
QueryInOmniboxFactory::QueryInOmniboxFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"QueryInOmnibox", | ||
BrowserContextDependencyManager::GetInstance()) { | ||
DependsOn(AutocompleteClassifierFactory::GetInstance()); | ||
DependsOn(TemplateURLServiceFactory::GetInstance()); | ||
} | ||
|
||
QueryInOmniboxFactory::~QueryInOmniboxFactory() {} | ||
|
||
content::BrowserContext* QueryInOmniboxFactory::GetBrowserContextToUse( | ||
content::BrowserContext* context) const { | ||
return chrome::GetBrowserContextRedirectedInIncognito(context); | ||
} | ||
|
||
bool QueryInOmniboxFactory::ServiceIsNULLWhileTesting() const { | ||
return true; | ||
} | ||
|
||
KeyedService* QueryInOmniboxFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* profile) const { | ||
return BuildInstanceFor(static_cast<Profile*>(profile)).release(); | ||
} |
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,45 @@ | ||
// 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_UI_OMNIBOX_QUERY_IN_OMNIBOX_FACTORY_H_ | ||
#define CHROME_BROWSER_UI_OMNIBOX_QUERY_IN_OMNIBOX_FACTORY_H_ | ||
|
||
#include <memory> | ||
|
||
#include "base/macros.h" | ||
#include "base/memory/singleton.h" | ||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" | ||
|
||
class QueryInOmnibox; | ||
class Profile; | ||
|
||
// Singleton that owns all QueryInOmnibox instances and associates them with | ||
// Profiles. | ||
class QueryInOmniboxFactory : public BrowserContextKeyedServiceFactory { | ||
public: | ||
// Returns the QueryInOmnibox for |profile|. | ||
static QueryInOmnibox* GetForProfile(Profile* profile); | ||
|
||
static QueryInOmniboxFactory* GetInstance(); | ||
|
||
static std::unique_ptr<KeyedService> BuildInstanceFor( | ||
content::BrowserContext* context); | ||
|
||
private: | ||
friend struct base::DefaultSingletonTraits<QueryInOmniboxFactory>; | ||
|
||
QueryInOmniboxFactory(); | ||
~QueryInOmniboxFactory() override; | ||
|
||
// BrowserContextKeyedServiceFactory: | ||
content::BrowserContext* GetBrowserContextToUse( | ||
content::BrowserContext* context) const override; | ||
bool ServiceIsNULLWhileTesting() const override; | ||
KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* profile) const override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(QueryInOmniboxFactory); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_OMNIBOX_QUERY_IN_OMNIBOX_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