Commit 21e4b95e authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[iOS] Fix post-first run tasks in multiwindow.

Due to a mistake in refactoring, the EULA was never marked as read, and
the location pop-up was never shown. Fix these by moving relevant code
to scene controller.

It seems like running this code multiple times (if multiwindow is used
in FRE) is safe and will not cause issues.

Bug: 1145063
Change-Id: If61e1fdb75b8cf6e1743c543d4570279f1f7a2d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2517953
Auto-Submit: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824034}
parent 1056ad8f
...@@ -63,7 +63,6 @@ ...@@ -63,7 +63,6 @@
#import "ios/chrome/browser/external_files/external_file_remover_impl.h" #import "ios/chrome/browser/external_files/external_file_remover_impl.h"
#include "ios/chrome/browser/feature_engagement/tracker_factory.h" #include "ios/chrome/browser/feature_engagement/tracker_factory.h"
#import "ios/chrome/browser/first_run/first_run.h" #import "ios/chrome/browser/first_run/first_run.h"
#include "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h"
#include "ios/chrome/browser/main/browser.h" #include "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/main/browser_list.h" #import "ios/chrome/browser/main/browser_list.h"
#import "ios/chrome/browser/main/browser_list_factory.h" #import "ios/chrome/browser/main/browser_list_factory.h"
...@@ -283,8 +282,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -283,8 +282,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
- (void)cleanupSnapshots; - (void)cleanupSnapshots;
// Cleanup discarded sessions on disk. // Cleanup discarded sessions on disk.
- (void)cleanupDiscardedSessions; - (void)cleanupDiscardedSessions;
// Sets a LocalState pref marking the TOS EULA as accepted.
- (void)markEulaAsAccepted;
// Sends any feedback that happens to still be on local storage. // Sends any feedback that happens to still be on local storage.
- (void)sendQueuedFeedback; - (void)sendQueuedFeedback;
// Called whenever an orientation change is received. // Called whenever an orientation change is received.
...@@ -324,10 +321,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -324,10 +321,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
- (void)scheduleDeleteTempPasswordsDirectory; - (void)scheduleDeleteTempPasswordsDirectory;
// Crashes the application if requested. // Crashes the application if requested.
- (void)crashIfRequested; - (void)crashIfRequested;
// Handles the notification that first run modal dialog UI is about to complete.
- (void)handleFirstRunUIWillFinish;
// Handles the notification that first run modal dialog UI completed.
- (void)handleFirstRunUIDidFinish;
// Performs synchronous browser state initialization steps. // Performs synchronous browser state initialization steps.
- (void)initializeBrowserState:(ChromeBrowserState*)browserState; - (void)initializeBrowserState:(ChromeBrowserState*)browserState;
// Helper methods to initialize the application to a specific stage. // Helper methods to initialize the application to a specific stage.
...@@ -593,27 +586,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -593,27 +586,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
ios::TemplateURLServiceFactory::GetForBrowserState(browserState)); ios::TemplateURLServiceFactory::GetForBrowserState(browserState));
} }
- (void)handleFirstRunUIWillFinish {
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:kChromeFirstRunUIWillFinishNotification
object:nil];
[self markEulaAsAccepted];
}
- (void)handleFirstRunUIDidFinish {
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:kChromeFirstRunUIDidFinishNotification
object:nil];
// As soon as First Run has finished, give OmniboxGeolocationController an
// opportunity to present the iOS system location alert.
[[OmniboxGeolocationController sharedInstance]
triggerSystemPromptForNewUser:YES];
}
#pragma mark - AppStateObserver #pragma mark - AppStateObserver
// Called when the first scene becomes active. // Called when the first scene becomes active.
...@@ -1081,22 +1053,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -1081,22 +1053,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
} }
} }
- (void)prepareForFirstRunUI {
// Register for notification when First Run is completed.
// Some initializations are held back until First Run modal dialog
// is dismissed.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handleFirstRunUIWillFinish)
name:kChromeFirstRunUIWillFinishNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handleFirstRunUIDidFinish)
name:kChromeFirstRunUIDidFinishNotification
object:nil];
}
- (void)crashIfRequested { - (void)crashIfRequested {
if (experimental_flags::IsStartupCrashEnabled()) { if (experimental_flags::IsStartupCrashEnabled()) {
// Flush out the value cached for breakpad::SetUploadingEnabled(). // Flush out the value cached for breakpad::SetUploadingEnabled().
...@@ -1173,15 +1129,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -1173,15 +1129,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
sessions_storage_util::ResetDiscardedSessions(); sessions_storage_util::ResetDiscardedSessions();
} }
- (void)markEulaAsAccepted {
PrefService* prefs = GetApplicationContext()->GetLocalState();
if (!prefs->GetBoolean(prefs::kEulaAccepted))
prefs->SetBoolean(prefs::kEulaAccepted, true);
prefs->CommitPendingWrite();
}
#pragma mark - BrowsingDataCommands #pragma mark - BrowsingDataCommands
- (void)removeBrowsingDataForBrowserState:(ChromeBrowserState*)browserState - (void)removeBrowsingDataForBrowserState:(ChromeBrowserState*)browserState
......
...@@ -68,6 +68,7 @@ source_set("scene") { ...@@ -68,6 +68,7 @@ source_set("scene") {
"//components/previous_session_info", "//components/previous_session_info",
"//components/signin/public/identity_manager", "//components/signin/public/identity_manager",
"//components/url_formatter", "//components/url_formatter",
"//components/web_resource",
"//ios/chrome/app:app", "//ios/chrome/app:app",
"//ios/chrome/app:blocking_scene_commands", "//ios/chrome/app:blocking_scene_commands",
"//ios/chrome/app:mode", "//ios/chrome/app:mode",
......
...@@ -11,9 +11,11 @@ ...@@ -11,9 +11,11 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "components/prefs/pref_service.h"
#import "components/previous_session_info/previous_session_info.h" #import "components/previous_session_info/previous_session_info.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
#include "components/url_formatter/url_formatter.h" #include "components/url_formatter/url_formatter.h"
#include "components/web_resource/web_resource_pref_names.h"
#import "ios/chrome/app/application_delegate/app_state.h" #import "ios/chrome/app/application_delegate/app_state.h"
#import "ios/chrome/app/application_delegate/startup_information.h" #import "ios/chrome/app/application_delegate/startup_information.h"
#include "ios/chrome/app/application_delegate/tab_opening.h" #include "ios/chrome/app/application_delegate/tab_opening.h"
...@@ -23,6 +25,7 @@ ...@@ -23,6 +25,7 @@
#include "ios/chrome/app/application_mode.h" #include "ios/chrome/app/application_mode.h"
#import "ios/chrome/app/chrome_overlay_window.h" #import "ios/chrome/app/chrome_overlay_window.h"
#import "ios/chrome/app/deferred_initialization_runner.h" #import "ios/chrome/app/deferred_initialization_runner.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/browsing_data/browsing_data_remove_mask.h" #include "ios/chrome/browser/browsing_data/browsing_data_remove_mask.h"
#include "ios/chrome/browser/browsing_data/browsing_data_remover.h" #include "ios/chrome/browser/browsing_data/browsing_data_remover.h"
...@@ -38,6 +41,7 @@ ...@@ -38,6 +41,7 @@
#include "ios/chrome/browser/crash_report/crash_report_helper.h" #include "ios/chrome/browser/crash_report/crash_report_helper.h"
#import "ios/chrome/browser/crash_report/crash_restore_helper.h" #import "ios/chrome/browser/crash_report/crash_restore_helper.h"
#import "ios/chrome/browser/first_run/first_run.h" #import "ios/chrome/browser/first_run/first_run.h"
#include "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h"
#import "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h" #import "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h"
#import "ios/chrome/browser/main/browser.h" #import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/main/browser_list.h" #import "ios/chrome/browser/main/browser_list.h"
...@@ -837,6 +841,12 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -837,6 +841,12 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
selector:@selector(handleFirstRunUIWillFinish) selector:@selector(handleFirstRunUIWillFinish)
name:kChromeFirstRunUIWillFinishNotification name:kChromeFirstRunUIWillFinishNotification
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handleFirstRunUIDidFinish)
name:kChromeFirstRunUIDidFinishNotification
object:nil];
Browser* browser = self.mainInterface.browser; Browser* browser = self.mainInterface.browser;
id<ApplicationCommands, BrowsingDataCommands> welcomeHandler = id<ApplicationCommands, BrowsingDataCommands> welcomeHandler =
static_cast<id<ApplicationCommands, BrowsingDataCommands>>( static_cast<id<ApplicationCommands, BrowsingDataCommands>>(
...@@ -860,7 +870,17 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -860,7 +870,17 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
completion:nil]; completion:nil];
} }
// Sets a LocalState pref marking the TOS EULA as accepted.
- (void)markEulaAsAccepted {
PrefService* prefs = GetApplicationContext()->GetLocalState();
if (!prefs->GetBoolean(prefs::kEulaAccepted))
prefs->SetBoolean(prefs::kEulaAccepted, true);
prefs->CommitPendingWrite();
}
- (void)handleFirstRunUIWillFinish { - (void)handleFirstRunUIWillFinish {
[self markEulaAsAccepted];
DCHECK(self.sceneState.presentingFirstRunUI); DCHECK(self.sceneState.presentingFirstRunUI);
_firstRunUIBlocker.reset(); _firstRunUIBlocker.reset();
self.sceneState.presentingFirstRunUI = NO; self.sceneState.presentingFirstRunUI = NO;
...@@ -873,6 +893,19 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -873,6 +893,19 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
} }
} }
// Handles the notification that first run modal dialog UI completed.
- (void)handleFirstRunUIDidFinish {
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:kChromeFirstRunUIDidFinishNotification
object:nil];
// As soon as First Run has finished, give OmniboxGeolocationController an
// opportunity to present the iOS system location alert.
[[OmniboxGeolocationController sharedInstance]
triggerSystemPromptForNewUser:YES];
}
// Presents the sign-in upgrade promo if is relevant and possible. // Presents the sign-in upgrade promo if is relevant and possible.
// Returns YES if the promo is shown. // Returns YES if the promo is shown.
- (BOOL)presentSigninUpgradePromoIfPossible { - (BOOL)presentSigninUpgradePromoIfPossible {
......
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