Commit dfc36de4 authored by Jiaquan He's avatar Jiaquan He Committed by Commit Bot

app_list: fix a search icon bug.

This commit fixes a regression of crrev.com/c/874526.

Bug: 804517
Change-Id: Ib1150d51a35251bb9fcaa9853b41db55a50633f1
Reviewed-on: https://chromium-review.googlesource.com/887825Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Jiaquan He <hejq@google.com>
Cr-Commit-Position: refs/heads/master@{#532052}
parent a324bac1
......@@ -20,6 +20,7 @@
#include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service.h"
......@@ -58,6 +59,7 @@ AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller)
model_(nullptr),
search_model_(nullptr),
model_updater_(nullptr),
template_url_service_observer_(this),
observer_binding_(this),
weak_ptr_factory_(this) {
CHECK(controller_);
......@@ -100,6 +102,8 @@ void AppListViewDelegate::SetProfile(Profile* new_profile) {
model_updater_ = nullptr;
}
template_url_service_observer_.RemoveAll();
profile_ = new_profile;
if (!profile_)
return;
......@@ -111,6 +115,10 @@ void AppListViewDelegate::SetProfile(Profile* new_profile) {
DCHECK(!profile_->IsGuestSession() || profile_->IsOffTheRecord())
<< "Guest mode must use incognito profile";
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(profile_);
template_url_service_observer_.Add(template_url_service);
app_list::AppListSyncableService* syncable_service =
app_list::AppListSyncableServiceFactory::GetForProfile(profile_);
model_ = syncable_service->GetModel();
......@@ -127,6 +135,7 @@ void AppListViewDelegate::SetProfile(Profile* new_profile) {
std::make_unique<AppSyncUIStateWatcher>(profile_, model_updater_);
SetUpSearchUI();
OnTemplateURLServiceChanged();
// Clear search query.
model_updater_->UpdateSearchBox(base::string16(),
......@@ -224,6 +233,18 @@ void AppListViewDelegate::RemoveObserver(
observers_.RemoveObserver(observer);
}
void AppListViewDelegate::OnTemplateURLServiceChanged() {
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(profile_);
const TemplateURL* default_provider =
template_url_service->GetDefaultSearchProvider();
const bool is_google =
default_provider->GetEngineType(
template_url_service->search_terms_data()) == SEARCH_ENGINE_GOOGLE;
model_updater_->SetSearchEngineIsGoogle(is_google);
}
void AppListViewDelegate::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
......
......@@ -18,6 +18,8 @@
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "chrome/browser/ui/app_list/chrome_app_list_model_updater.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
......@@ -41,7 +43,8 @@ class Profile;
class AppListViewDelegate : public app_list::AppListViewDelegate,
public ash::mojom::WallpaperObserver,
public content::NotificationObserver {
public content::NotificationObserver,
public TemplateURLServiceObserver {
public:
// Constructs Chrome's AppListViewDelegate with a NULL Profile.
// Does not take ownership of |controller|. TODO(tapted): It should.
......@@ -73,6 +76,9 @@ class AppListViewDelegate : public app_list::AppListViewDelegate,
void AddObserver(app_list::AppListViewDelegateObserver* observer) override;
void RemoveObserver(app_list::AppListViewDelegateObserver* observer) override;
// Overridden from TemplateURLServiceObserver:
void OnTemplateURLServiceChanged() override;
private:
// Callback for ash::mojom::GetWallpaperColors.
void OnGetWallpaperColorsCallback(const std::vector<SkColor>& colors);
......@@ -108,6 +114,9 @@ class AppListViewDelegate : public app_list::AppListViewDelegate,
std::unique_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_;
ScopedObserver<TemplateURLService, AppListViewDelegate>
template_url_service_observer_;
// Registers for NOTIFICATION_APP_TERMINATING to unload custom launcher pages.
content::NotificationRegistrar registrar_;
......
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