Commit b5bbd1e3 authored by Nazerke's avatar Nazerke Committed by Commit Bot

[iOS][coordinator] Modernize History Coordinator.

This CL modernizes the HistoryCoordinator
 - to use |browser| in the initializer
 - to remove the public property for browserstate and dispatcher.
 - to use self.browser to get browserstate and dispatcher values.

Bug: 1029346, 1048408
Change-Id: I303cc9ce692c15f582f8648a8049ea2251148746
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2063128Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#742598}
parent 6581f8e2
...@@ -23,6 +23,7 @@ source_set("history") { ...@@ -23,6 +23,7 @@ source_set("history") {
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/favicon", "//ios/chrome/browser/favicon",
"//ios/chrome/browser/history", "//ios/chrome/browser/history",
"//ios/chrome/browser/main:public",
"//ios/chrome/browser/sync", "//ios/chrome/browser/sync",
"//ios/chrome/browser/ui/context_menu", "//ios/chrome/browser/ui/context_menu",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators", "//ios/chrome/browser/ui/coordinators:chrome_coordinators",
......
...@@ -12,21 +12,27 @@ ...@@ -12,21 +12,27 @@
enum class UrlLoadStrategy; enum class UrlLoadStrategy;
@protocol ApplicationCommands;
@protocol BrowsingDataCommands;
@protocol HistoryPresentationDelegate; @protocol HistoryPresentationDelegate;
// Coordinator that presents History. // Coordinator that presents History.
@interface HistoryCoordinator : ChromeCoordinator @interface HistoryCoordinator : ChromeCoordinator
// The dispatcher for this Coordinator.
@property(nonatomic, weak) id<ApplicationCommands, BrowsingDataCommands> // Unavailable, use -initWithBaseViewController:browser:.
dispatcher; - (instancetype)initWithBaseViewController:(UIViewController*)viewController
NS_UNAVAILABLE;
// Unavailable, use -initWithBaseViewController:browser:.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browserState:(ChromeBrowserState*)browserState
NS_UNAVAILABLE;
// Opaque instructions on how to open urls. // Opaque instructions on how to open urls.
@property(nonatomic) UrlLoadStrategy loadStrategy; @property(nonatomic) UrlLoadStrategy loadStrategy;
// Delegate used to make the Tab UI visible. // Delegate used to make the Tab UI visible.
@property(nonatomic, weak) id<HistoryPresentationDelegate> presentationDelegate; @property(nonatomic, weak) id<HistoryPresentationDelegate> presentationDelegate;
// Stops this Coordinator then calls |completionHandler|. // Stops this Coordinator then calls |completionHandler|.
- (void)stopWithCompletion:(ProceduralBlock)completionHandler; - (void)stopWithCompletion:(ProceduralBlock)completionHandler;
@end @end
#endif // IOS_CHROME_BROWSER_UI_HISTORY_HISTORY_COORDINATOR_H_ #endif // IOS_CHROME_BROWSER_UI_HISTORY_HISTORY_COORDINATOR_H_
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "components/keyed_service/core/service_access_type.h" #include "components/keyed_service/core/service_access_type.h"
#include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service.h"
#include "ios/chrome/browser/history/history_service_factory.h" #include "ios/chrome/browser/history/history_service_factory.h"
#import "ios/chrome/browser/main/browser.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h" #include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h" #import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h"
#import "ios/chrome/browser/ui/history/history_clear_browsing_data_coordinator.h" #import "ios/chrome/browser/ui/history/history_clear_browsing_data_coordinator.h"
...@@ -50,7 +51,6 @@ ...@@ -50,7 +51,6 @@
@end @end
@implementation HistoryCoordinator @implementation HistoryCoordinator
@synthesize dispatcher = _dispatcher;
@synthesize historyClearBrowsingDataCoordinator = @synthesize historyClearBrowsingDataCoordinator =
_historyClearBrowsingDataCoordinator; _historyClearBrowsingDataCoordinator;
@synthesize historyNavigationController = _historyNavigationController; @synthesize historyNavigationController = _historyNavigationController;
...@@ -61,22 +61,24 @@ ...@@ -61,22 +61,24 @@
- (void)start { - (void)start {
// Initialize and configure HistoryTableViewController. // Initialize and configure HistoryTableViewController.
self.historyTableViewController = [[HistoryTableViewController alloc] init]; self.historyTableViewController = [[HistoryTableViewController alloc] init];
self.historyTableViewController.browserState = self.browserState; self.historyTableViewController.browserState =
self.browser->GetBrowserState();
self.historyTableViewController.loadStrategy = self.loadStrategy; self.historyTableViewController.loadStrategy = self.loadStrategy;
// Initialize and set HistoryMediator // Initialize and set HistoryMediator
self.mediator = self.mediator = [[HistoryMediator alloc]
[[HistoryMediator alloc] initWithBrowserState:self.browserState]; initWithBrowserState:self.browser->GetBrowserState()];
self.historyTableViewController.imageDataSource = self.mediator; self.historyTableViewController.imageDataSource = self.mediator;
// Initialize and configure HistoryServices. // Initialize and configure HistoryServices.
_browsingHistoryDriver = std::make_unique<IOSBrowsingHistoryDriver>( _browsingHistoryDriver = std::make_unique<IOSBrowsingHistoryDriver>(
self.browserState, self.historyTableViewController); self.browser->GetBrowserState(), self.historyTableViewController);
_browsingHistoryService = std::make_unique<history::BrowsingHistoryService>( _browsingHistoryService = std::make_unique<history::BrowsingHistoryService>(
_browsingHistoryDriver.get(), _browsingHistoryDriver.get(),
ios::HistoryServiceFactory::GetForBrowserState( ios::HistoryServiceFactory::GetForBrowserState(
self.browserState, ServiceAccessType::EXPLICIT_ACCESS), self.browser->GetBrowserState(), ServiceAccessType::EXPLICIT_ACCESS),
ProfileSyncServiceFactory::GetForBrowserState(self.browserState)); ProfileSyncServiceFactory::GetForBrowserState(
self.browser->GetBrowserState()));
self.historyTableViewController.historyService = self.historyTableViewController.historyService =
_browsingHistoryService.get(); _browsingHistoryService.get();
...@@ -154,16 +156,20 @@ ...@@ -154,16 +156,20 @@
} }
- (void)displayPrivacySettings { - (void)displayPrivacySettings {
self.historyClearBrowsingDataCoordinator = self.historyClearBrowsingDataCoordinator =
[[HistoryClearBrowsingDataCoordinator alloc] [[HistoryClearBrowsingDataCoordinator alloc]
initWithBaseViewController:self.historyNavigationController initWithBaseViewController:self.historyNavigationController
browserState:self.browserState]; browserState:self.browser->GetBrowserState()];
self.historyClearBrowsingDataCoordinator.localDispatcher = self; self.historyClearBrowsingDataCoordinator.localDispatcher = self;
self.historyClearBrowsingDataCoordinator.presentationDelegate = self.historyClearBrowsingDataCoordinator.presentationDelegate =
self.presentationDelegate; self.presentationDelegate;
self.historyClearBrowsingDataCoordinator.loadStrategy = self.loadStrategy; self.historyClearBrowsingDataCoordinator.loadStrategy = self.loadStrategy;
self.historyClearBrowsingDataCoordinator.dispatcher = self.dispatcher; // TODO(crbug.com/1048407): Remove dispatcher as the property of
[self.historyClearBrowsingDataCoordinator start]; // HistoryClearBrowsingDataCoordinator.
self.historyClearBrowsingDataCoordinator.dispatcher =
static_cast<id<ApplicationCommands, BrowsingDataCommands>>(
self.browser->GetCommandDispatcher());
[self.historyClearBrowsingDataCoordinator start];
} }
@end @end
...@@ -231,11 +231,10 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO }; ...@@ -231,11 +231,10 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
- (void)showHistory { - (void)showHistory {
self.historyCoordinator = [[HistoryCoordinator alloc] self.historyCoordinator = [[HistoryCoordinator alloc]
initWithBaseViewController:self.mainController.currentBVC initWithBaseViewController:self.mainController.currentBVC
browserState:self.mainController.mainBrowserState]; browser:self.mainInterface.browser];
self.historyCoordinator.loadStrategy = self.historyCoordinator.loadStrategy =
[self currentPageIsIncognito] ? UrlLoadStrategy::ALWAYS_IN_INCOGNITO [self currentPageIsIncognito] ? UrlLoadStrategy::ALWAYS_IN_INCOGNITO
: UrlLoadStrategy::NORMAL; : UrlLoadStrategy::NORMAL;
self.historyCoordinator.dispatcher = self.mainController.mainBVC.dispatcher;
[self.historyCoordinator start]; [self.historyCoordinator start];
} }
......
...@@ -418,13 +418,10 @@ ...@@ -418,13 +418,10 @@
// |loadStrategy| to YES to ALWAYS_NEW_FOREGROUND_TAB. // |loadStrategy| to YES to ALWAYS_NEW_FOREGROUND_TAB.
self.historyCoordinator = [[HistoryCoordinator alloc] self.historyCoordinator = [[HistoryCoordinator alloc]
initWithBaseViewController:self.baseViewController initWithBaseViewController:self.baseViewController
browserState:self.regularBrowser->GetBrowserState()]; browser:self.regularBrowser];
self.historyCoordinator.loadStrategy = self.historyCoordinator.loadStrategy =
UrlLoadStrategy::ALWAYS_NEW_FOREGROUND_TAB; UrlLoadStrategy::ALWAYS_NEW_FOREGROUND_TAB;
self.historyCoordinator.presentationDelegate = self; self.historyCoordinator.presentationDelegate = self;
self.historyCoordinator.dispatcher =
static_cast<id<ApplicationCommands, BrowsingDataCommands>>(
self.dispatcher);
[self.historyCoordinator start]; [self.historyCoordinator start];
} }
......
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