summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormlerman <mlerman@chromium.org>2015-04-22 06:09:34 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-22 13:09:40 +0000
commitef6d33eabfb3d553153217a3b874dd6a0cfdf961 (patch)
treecf19317089b6c8bbb42ec9030384c42085bffd68
parent732e5fd8f383344307338fecf199b8b3dbe9a80c (diff)
downloadchromium_src-ef6d33eabfb3d553153217a3b874dd6a0cfdf961.zip
chromium_src-ef6d33eabfb3d553153217a3b874dd6a0cfdf961.tar.gz
chromium_src-ef6d33eabfb3d553153217a3b874dd6a0cfdf961.tar.bz2
AppControllerMac updates the window when a Profile is deleted.
BUG=477392 TEST=(Mac only) Have at least two profiles. Open one of the profiles. navigate to generate browser history, verify it in the History Menu. Delete the profile; note that history should no longer show the deleted profile's history. Review URL: https://codereview.chromium.org/1097553002 Cr-Commit-Position: refs/heads/master@{#326281}
-rw-r--r--chrome/browser/app_controller_mac.h1
-rw-r--r--chrome/browser/app_controller_mac.mm13
-rw-r--r--chrome/browser/app_controller_mac_browsertest.mm66
-rw-r--r--chrome/browser/profiles/profile_manager.cc2
4 files changed, 79 insertions, 3 deletions
diff --git a/chrome/browser/app_controller_mac.h b/chrome/browser/app_controller_mac.h
index 53f5be6..8c69929 100644
--- a/chrome/browser/app_controller_mac.h
+++ b/chrome/browser/app_controller_mac.h
@@ -157,6 +157,7 @@ class WorkAreaWatcherObserver;
- (const std::vector<GURL>&)startupUrls;
- (BookmarkMenuBridge*)bookmarkMenuBridge;
+- (HistoryMenuBridge*)historyMenuBridge;
// Subscribes/unsubscribes from the work area change notification.
- (void)addObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer;
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index e888d39..91ae932 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -893,8 +893,13 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
// to the old profile.
// In a browser test, the application is not brought to the front, so
// |lastProfile_| might be null.
- if (!lastProfile_ || profilePath == lastProfile_->GetPath())
- lastProfile_ = g_browser_process->profile_manager()->GetLastUsedProfile();
+ if (!lastProfile_ || profilePath == lastProfile_->GetPath()) {
+ // Force windowChangedToProfile: to set the lastProfile_ and also update the
+ // relevant menuBridge objects.
+ lastProfile_ = nullptr;
+ [self windowChangedToProfile:g_browser_process->profile_manager()->
+ GetLastUsedProfile()];
+ }
auto it = profileBookmarkMenuBridgeMap_.find(profilePath);
if (it != profileBookmarkMenuBridgeMap_.end()) {
@@ -1549,6 +1554,10 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
return bookmarkMenuBridge_;
}
+- (HistoryMenuBridge*)historyMenuBridge {
+ return historyMenuBridge_.get();
+}
+
- (void)addObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer {
workAreaChangeObservers_.AddObserver(observer);
}
diff --git a/chrome/browser/app_controller_mac_browsertest.mm b/chrome/browser/app_controller_mac_browsertest.mm
index 52fa358..a5d8fd3 100644
--- a/chrome/browser/app_controller_mac_browsertest.mm
+++ b/chrome/browser/app_controller_mac_browsertest.mm
@@ -22,11 +22,13 @@
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h"
+#include "chrome/browser/ui/cocoa/history_menu_bridge.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/user_manager.h"
@@ -79,6 +81,13 @@ void SendAppleEventToOpenUrlToAppController(const GURL& url) {
method_invoke(controller, get_url, shortcut_event, NULL);
}
+void RunClosureWhenProfileInitialized(const base::Closure& closure,
+ Profile* profile,
+ Profile::CreateStatus status) {
+ if (status == Profile::CREATE_STATUS_INITIALIZED)
+ closure.Run();
+}
+
} // namespace
@interface TestOpenShortcutOnStartup : NSObject
@@ -427,6 +436,63 @@ class AppControllerMainMenuBrowserTest : public InProcessBrowserTest {
};
IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest,
+ HistoryMenuResetAfterProfileDeletion) {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ AppController* ac = [NSApp delegate];
+
+ // Use the existing profile as profile 1.
+ Profile* profile1 = browser()->profile();
+
+ // Create profile 2.
+ base::FilePath profile2_path =
+ profile_manager->GenerateNextProfileDirectoryPath();
+ base::RunLoop run_loop;
+ profile_manager->CreateProfileAsync(
+ profile2_path,
+ base::Bind(&RunClosureWhenProfileInitialized,
+ run_loop.QuitClosure()),
+ base::string16(),
+ base::string16(),
+ std::string());
+ run_loop.Run();
+ Profile* profile2 = profile_manager->GetProfileByPath(profile2_path);
+ ASSERT_TRUE(profile2);
+
+ // Switch the controller to profile1.
+ [ac windowChangedToProfile:profile1];
+ base::RunLoop().RunUntilIdle();
+
+ // Verify the controller's History Menu corresponds to profile1.
+ EXPECT_EQ([ac historyMenuBridge]->service(),
+ HistoryServiceFactory::GetForProfile(profile1,
+ ServiceAccessType::EXPLICIT_ACCESS));
+
+ // Switch the controller to profile2.
+ [ac windowChangedToProfile:profile2];
+ base::RunLoop().RunUntilIdle();
+
+ // Verify the controller's History Menu has changed.
+ EXPECT_EQ([ac historyMenuBridge]->service(),
+ HistoryServiceFactory::GetForProfile(profile2,
+ ServiceAccessType::EXPLICIT_ACCESS));
+ EXPECT_NE(
+ HistoryServiceFactory::GetForProfile(profile1,
+ ServiceAccessType::EXPLICIT_ACCESS),
+ HistoryServiceFactory::GetForProfile(profile2,
+ ServiceAccessType::EXPLICIT_ACCESS));
+
+ // Delete profile2.
+ profile_manager->ScheduleProfileForDeletion(
+ profile2->GetPath(), ProfileManager::CreateCallback());
+ base::RunLoop().RunUntilIdle();
+
+ // Verify the controller's history is back to profile1.
+ EXPECT_EQ([ac historyMenuBridge]->service(),
+ HistoryServiceFactory::GetForProfile(profile1,
+ ServiceAccessType::EXPLICIT_ACCESS));
+}
+
+IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest,
BookmarksMenuIsRestoredAfterProfileSwitch) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index 2e98ee4..c8a9732 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -713,7 +713,7 @@ void ProfileManager::ScheduleProfileForDeletion(
base::Unretained(this),
profile_dir,
last_non_supervised_profile_path,
- CreateCallback()),
+ callback),
base::string16(),
base::string16(),
std::string());