Commit 3bcf8d15 authored by Owen Min's avatar Owen Min Committed by Commit Bot

Fix an issue that applicationDidFinishLaunching is not repposted properly.

The applicationDidFinishLaunching should be ran when controller is NOT nil.
Also, make it more clear that the notification is ran right after
the dialog is closed.

Bug: 844487
Change-Id: I8a66c0e79af92234fba9a19dcc36f11f3edb7545
Reviewed-on: https://chromium-review.googlesource.com/1134473Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575308}
parent abb1d1d0
...@@ -193,6 +193,10 @@ bool IsOpeningNewWindow(); ...@@ -193,6 +193,10 @@ bool IsOpeningNewWindow();
// already existed, notify the AppController of the profile in use. // already existed, notify the AppController of the profile in use.
void CreateGuestProfileIfNeeded(); void CreateGuestProfileIfNeeded();
// Called when Enterprise startup dialog is close and repost
// applicationDidFinished notification.
void EnterpriseStartupDialogClosed();
} // namespace app_controller_mac } // namespace app_controller_mac
#endif // CHROME_BROWSER_APP_CONTROLLER_MAC_H_ #endif // CHROME_BROWSER_APP_CONTROLLER_MAC_H_
...@@ -197,9 +197,6 @@ bool IsProfileSignedOut(Profile* profile) { ...@@ -197,9 +197,6 @@ bool IsProfileSignedOut(Profile* profile) {
return has_entry && entry->IsSigninRequired(); return has_entry && entry->IsSigninRequired();
} }
// Called when Chrome is launched successfully.
void LaunchFinished(NSNotification* notify);
} // namespace } // namespace
@interface AppController () <HandoffActiveURLObserverBridgeDelegate> @interface AppController () <HandoffActiveURLObserverBridgeDelegate>
...@@ -230,11 +227,6 @@ void LaunchFinished(NSNotification* notify); ...@@ -230,11 +227,6 @@ void LaunchFinished(NSNotification* notify);
// NTP after all the |urls| have been opened. // NTP after all the |urls| have been opened.
- (void)openUrlsReplacingNTP:(const std::vector<GURL>&)urls; - (void)openUrlsReplacingNTP:(const std::vector<GURL>&)urls;
// Finish Chrome launching. It usually called by -applicationDidFinishLaunching:
// notification. However, it will be delayed until Chrome browser window is
// really if there is the EnterpriseStartupDialog blocks Chrome window display.
- (void)doApplicationDidFinishLaunching:(NSNotification*)notify;
// Whether instances of this class should use the Handoff feature. // Whether instances of this class should use the Handoff feature.
- (BOOL)shouldUseHandoff; - (BOOL)shouldUseHandoff;
...@@ -742,7 +734,15 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session; ...@@ -742,7 +734,15 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
// This is called after profiles have been loaded and preferences registered. // This is called after profiles have been loaded and preferences registered.
// It is safe to access the default profile here. // It is safe to access the default profile here.
- (void)doApplicationDidFinishLaunching:(NSNotification*)notify { - (void)applicationDidFinishLaunching:(NSNotification*)notify {
if (g_browser_process->browser_policy_connector()
->machine_level_user_cloud_policy_controller()
->IsEnterpriseStartupDialogShowing()) {
// As Chrome is not ready when the Enterprise startup dialog is being shown.
// Store the notification as it will be reposted when the dialog is closed.
return;
}
MacStartupProfiler::GetInstance()->Profile( MacStartupProfiler::GetInstance()->Profile(
MacStartupProfiler::DID_FINISH_LAUNCHING); MacStartupProfiler::DID_FINISH_LAUNCHING);
MacStartupProfiler::GetInstance()->RecordMetrics(); MacStartupProfiler::GetInstance()->RecordMetrics();
...@@ -816,20 +816,6 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session; ...@@ -816,20 +816,6 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
#endif #endif
} }
- (void)applicationDidFinishLaunching:(NSNotification*)notify {
if (g_browser_process->browser_policy_connector()
->machine_level_user_cloud_policy_controller()
->IsEnterpriseStartupDialogShowing()) {
// Repost the function with a delayed task if the enterprise startup dialog
// is being displayed. Because Chrome is not ready when the dialog is shown.
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::BindOnce(&LaunchFinished, notify),
base::TimeDelta::FromSeconds(0));
} else {
[self doApplicationDidFinishLaunching:notify];
}
}
// Helper function for populating and displaying the in progress downloads at // Helper function for populating and displaying the in progress downloads at
// exit alert panel. // exit alert panel.
- (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount { - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount {
...@@ -1757,13 +1743,6 @@ void UpdateProfileInUse(Profile* profile, Profile::CreateStatus status) { ...@@ -1757,13 +1743,6 @@ void UpdateProfileInUse(Profile* profile, Profile::CreateStatus status) {
} }
} }
void LaunchFinished(NSNotification* notify) {
AppController* controller =
base::mac::ObjCCastStrict<AppController>([NSApp delegate]);
if (controller == nil)
[controller doApplicationDidFinishLaunching:notify];
}
} // namespace } // namespace
namespace app_controller_mac { namespace app_controller_mac {
...@@ -1779,4 +1758,15 @@ void CreateGuestProfileIfNeeded() { ...@@ -1779,4 +1758,15 @@ void CreateGuestProfileIfNeeded() {
std::string()); std::string());
} }
void EnterpriseStartupDialogClosed() {
AppController* controller =
base::mac::ObjCCastStrict<AppController>([NSApp delegate]);
if (controller != nil) {
NSNotification* notify = [NSNotification
notificationWithName:NSApplicationDidFinishLaunchingNotification
object:NSApp];
[controller applicationDidFinishLaunching:notify];
}
}
} // namespace app_controller_mac } // namespace app_controller_mac
...@@ -229,6 +229,7 @@ ...@@ -229,6 +229,7 @@
#include <Security/Security.h> #include <Security/Security.h>
#include "base/mac/scoped_nsautorelease_pool.h" #include "base/mac/scoped_nsautorelease_pool.h"
#include "chrome/browser/app_controller_mac.h"
#include "chrome/browser/mac/keystone_glue.h" #include "chrome/browser/mac/keystone_glue.h"
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
...@@ -756,7 +757,12 @@ bool WaitUntilMachineLevelUserCloudPolicyEnrollmentFinished( ...@@ -756,7 +757,12 @@ bool WaitUntilMachineLevelUserCloudPolicyEnrollmentFinished(
switch (connector->machine_level_user_cloud_policy_controller() switch (connector->machine_level_user_cloud_policy_controller()
->WaitUntilPolicyEnrollmentFinished()) { ->WaitUntilPolicyEnrollmentFinished()) {
case RegisterResult::kNoEnrollmentNeeded: case RegisterResult::kNoEnrollmentNeeded:
case RegisterResult::kEnrollmentSuccessBeforeDialogDisplayed:
return true;
case RegisterResult::kEnrollmentSuccess: case RegisterResult::kEnrollmentSuccess:
#if defined(OS_MACOSX)
app_controller_mac::EnterpriseStartupDialogClosed();
#endif
return true; return true;
case RegisterResult::kRestartDueToFailure: case RegisterResult::kRestartDueToFailure:
chrome::AttemptRestart(); chrome::AttemptRestart();
......
...@@ -427,6 +427,16 @@ IN_PROC_BROWSER_TEST_P(MachineLevelUserCloudPolicyEnrollmentTest, Test) { ...@@ -427,6 +427,16 @@ IN_PROC_BROWSER_TEST_P(MachineLevelUserCloudPolicyEnrollmentTest, Test) {
histogram_tester_.ExpectBucketCount(kEnrollmentResultMetrics, expected_result, histogram_tester_.ExpectBucketCount(kEnrollmentResultMetrics, expected_result,
1); 1);
histogram_tester_.ExpectTotalCount(kEnrollmentResultMetrics, 1); histogram_tester_.ExpectTotalCount(kEnrollmentResultMetrics, 1);
#if defined(OS_MACOSX)
// Verify the last mericis of launch is recorded in
// applicationDidFinishNotification.
if (is_enrollment_token_valid()) {
EXPECT_EQ(1u, histogram_tester_
.GetAllSamples("Startup.OSX.DockIconWillFinishBouncing")
.size());
}
#endif
} }
INSTANTIATE_TEST_CASE_P(, INSTANTIATE_TEST_CASE_P(,
......
...@@ -34,9 +34,12 @@ class MachineLevelUserCloudPolicyController { ...@@ -34,9 +34,12 @@ class MachineLevelUserCloudPolicyController {
enum class RegisterResult { enum class RegisterResult {
kNoEnrollmentNeeded, // The device won't be enrolled without an enrollment kNoEnrollmentNeeded, // The device won't be enrolled without an enrollment
// token. // token.
kEnrollmentSuccess, // The device has been enrolled successfully. kEnrollmentSuccessBeforeDialogDisplayed, // The enrollment process is
kQuitDueToFailure, // The enrollment has failed or aborted, user choose to // finished before dialog
// quit Chrome. // displayed.
kEnrollmentSuccess, // The device has been enrolled successfully
kQuitDueToFailure, // The enrollment has failed or aborted, user choose to
// quit Chrome.
kRestartDueToFailure, // The enrollment has failed, user choose to restart kRestartDueToFailure, // The enrollment has failed, user choose to restart
}; };
......
...@@ -44,7 +44,7 @@ RegisterResult MachineLevelUserCloudPolicyRegisterWatcher:: ...@@ -44,7 +44,7 @@ RegisterResult MachineLevelUserCloudPolicyRegisterWatcher::
// We are already enrolled successfully. // We are already enrolled successfully.
if (!token_storage->RetrieveDMToken().empty()) { if (!token_storage->RetrieveDMToken().empty()) {
return RegisterResult::kEnrollmentSuccess; return RegisterResult::kEnrollmentSuccessBeforeDialogDisplayed;
} }
EnterpriseStartupDialog::DialogResultCallback callback = base::BindOnce( EnterpriseStartupDialog::DialogResultCallback callback = base::BindOnce(
......
...@@ -151,7 +151,7 @@ class MachineLevelUserCloudPolicyRegisterWatcherTest : public ::testing::Test { ...@@ -151,7 +151,7 @@ class MachineLevelUserCloudPolicyRegisterWatcherTest : public ::testing::Test {
TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest, TEST_F(MachineLevelUserCloudPolicyRegisterWatcherTest,
NoEnrollmentNeededWithDMToken) { NoEnrollmentNeededWithDMToken) {
storage()->set_dm_token(kDMToken); storage()->set_dm_token(kDMToken);
EXPECT_EQ(RegisterResult::kEnrollmentSuccess, EXPECT_EQ(RegisterResult::kEnrollmentSuccessBeforeDialogDisplayed,
watcher()->WaitUntilCloudPolicyEnrollmentFinished()); watcher()->WaitUntilCloudPolicyEnrollmentFinished());
} }
......
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