Commit 9357950d authored by Yi Su's avatar Yi Su Committed by Commit Bot

Add TemplateURLServiceObserverBridge for SettingsTableVC.

Use TemplateURLServiceObserverBridge to update the default search
engine name on the "Search Engine" item in SettingsTableVC.

Bug: 661915
Change-Id: I24c034c688bab086330da1e2c67ba30c2109ce9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1554766
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#648608}
parent 72606387
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "ios/chrome/browser/ios_chrome_flag_descriptions.h" #include "ios/chrome/browser/ios_chrome_flag_descriptions.h"
#include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h" #include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
#include "ios/chrome/browser/pref_names.h" #include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/search_engines/search_engine_observer_bridge.h"
#include "ios/chrome/browser/search_engines/template_url_service_factory.h" #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service.h" #import "ios/chrome/browser/signin/authentication_service.h"
#include "ios/chrome/browser/signin/authentication_service_factory.h" #include "ios/chrome/browser/signin/authentication_service_factory.h"
...@@ -202,14 +203,16 @@ void IdentityObserverBridge::OnPrimaryAccountCleared( ...@@ -202,14 +203,16 @@ void IdentityObserverBridge::OnPrimaryAccountCleared(
GoogleServicesSettingsCoordinatorDelegate, GoogleServicesSettingsCoordinatorDelegate,
PrefObserverDelegate, PrefObserverDelegate,
SettingsControllerProtocol, SettingsControllerProtocol,
SearchEngineObserving,
SettingsMainPageCommands, SettingsMainPageCommands,
SigninPresenter, SigninPresenter,
SigninPromoViewConsumer, SigninPromoViewConsumer,
SyncObserverModelBridge> { SyncObserverModelBridge> {
// The current browser state that hold the settings. Never off the record. // The current browser state that hold the settings. Never off the record.
ios::ChromeBrowserState* _browserState; // weak ios::ChromeBrowserState* _browserState; // weak
// Bridge for TemplateURLServiceObserver.
std::unique_ptr<IdentityObserverBridge> _notificationBridge; std::unique_ptr<SearchEngineObserverBridge> _searchEngineObserverBridge;
std::unique_ptr<IdentityObserverBridge> _identityObserverBridge;
std::unique_ptr<SyncObserverBridge> _syncObserverBridge; std::unique_ptr<SyncObserverBridge> _syncObserverBridge;
// Whether the impression of the Signin button has already been recorded. // Whether the impression of the Signin button has already been recorded.
BOOL _hasRecordedSigninImpression; BOOL _hasRecordedSigninImpression;
...@@ -288,7 +291,11 @@ void IdentityObserverBridge::OnPrimaryAccountCleared( ...@@ -288,7 +291,11 @@ void IdentityObserverBridge::OnPrimaryAccountCleared(
if (self) { if (self) {
_browserState = browserState; _browserState = browserState;
self.title = l10n_util::GetNSStringWithFixup(IDS_IOS_SETTINGS_TITLE); self.title = l10n_util::GetNSStringWithFixup(IDS_IOS_SETTINGS_TITLE);
_notificationBridge.reset(new IdentityObserverBridge(_browserState, self)); _searchEngineObserverBridge.reset(new SearchEngineObserverBridge(
self,
ios::TemplateURLServiceFactory::GetForBrowserState(_browserState)));
_identityObserverBridge.reset(
new IdentityObserverBridge(_browserState, self));
syncer::SyncService* syncService = syncer::SyncService* syncService =
ProfileSyncServiceFactory::GetForBrowserState(_browserState); ProfileSyncServiceFactory::GetForBrowserState(_browserState);
_syncObserverBridge.reset(new SyncObserverBridge(self, syncService)); _syncObserverBridge.reset(new SyncObserverBridge(self, syncService));
...@@ -344,7 +351,7 @@ void IdentityObserverBridge::OnPrimaryAccountCleared( ...@@ -344,7 +351,7 @@ void IdentityObserverBridge::OnPrimaryAccountCleared(
- (void)stopBrowserStateServiceObservers { - (void)stopBrowserStateServiceObservers {
_syncObserverBridge.reset(); _syncObserverBridge.reset();
_notificationBridge.reset(); _identityObserverBridge.reset();
_identityServiceObserver.reset(); _identityServiceObserver.reset();
[_showMemoryDebugToolsEnabled setObserver:nil]; [_showMemoryDebugToolsEnabled setObserver:nil];
[_articlesEnabled setObserver:nil]; [_articlesEnabled setObserver:nil];
...@@ -366,14 +373,6 @@ void IdentityObserverBridge::OnPrimaryAccountCleared( ...@@ -366,14 +373,6 @@ void IdentityObserverBridge::OnPrimaryAccountCleared(
UINavigationItemLargeTitleDisplayModeAlways; UINavigationItemLargeTitleDisplayModeAlways;
} }
// TODO(crbug.com/661915): Refactor TemplateURLObserver and re-implement this so
// it observes the default search engine name instead of reloading on
// ViewWillAppear.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self updateSearchCell];
}
#pragma mark SettingsRootTableViewController #pragma mark SettingsRootTableViewController
- (void)loadModel { - (void)loadModel {
...@@ -690,17 +689,6 @@ void IdentityObserverBridge::OnPrimaryAccountCleared( ...@@ -690,17 +689,6 @@ void IdentityObserverBridge::OnPrimaryAccountCleared(
} }
#endif // CHROMIUM_BUILD && !defined(NDEBUG) #endif // CHROMIUM_BUILD && !defined(NDEBUG)
#pragma mark Item Updaters
- (void)updateSearchCell {
NSString* defaultSearchEngineName =
base::SysUTF16ToNSString(GetDefaultSearchEngineName(
ios::TemplateURLServiceFactory::GetForBrowserState(_browserState)));
_defaultSearchEngineItem.detailText = defaultSearchEngineName;
[self reconfigureCellsForItems:@[ _defaultSearchEngineItem ]];
}
#pragma mark Item Constructors #pragma mark Item Constructors
- (TableViewDetailIconItem*)detailItemWithType:(NSInteger)type - (TableViewDetailIconItem*)detailItemWithType:(NSInteger)type
...@@ -1211,6 +1199,15 @@ void IdentityObserverBridge::OnPrimaryAccountCleared( ...@@ -1211,6 +1199,15 @@ void IdentityObserverBridge::OnPrimaryAccountCleared(
return _resizedImage; return _resizedImage;
} }
#pragma mark - SearchEngineObserverBridge
- (void)searchEngineChanged {
_defaultSearchEngineItem.detailText =
base::SysUTF16ToNSString(GetDefaultSearchEngineName(
ios::TemplateURLServiceFactory::GetForBrowserState(_browserState)));
[self reconfigureCellsForItems:@[ _defaultSearchEngineItem ]];
}
#pragma mark ChromeIdentityServiceObserver #pragma mark ChromeIdentityServiceObserver
- (void)profileUpdate:(ChromeIdentity*)identity { - (void)profileUpdate:(ChromeIdentity*)identity {
......
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