Fix Mac App Launcher observer lifetime on AppListItemList
commit14123e73e132d1cf6fa0d70d65aa703246778df2
authortapted <tapted@chromium.org>
Tue, 23 Sep 2014 07:14:45 +0000 (23 00:14 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 23 Sep 2014 07:15:05 +0000 (23 07:15 +0000)
treef48a203cda7f9a2467aebf2465495616b6fcc823
parent9880b46388bca521003ce8439a10036727a19862
Fix Mac App Launcher observer lifetime on AppListItemList

r295646 moved ownership of the AppListViewDelegate out of the
AppListViewController which meant that the Mac AppList began removing
itself as an observer from the wrong model. This happens because, in
Chrome, the AppListViewDelegate changes the return from GetModel() when
the profile is switched, but doesn't currently have a way of notifying
the AppList that this is happening.

To fix, AppListServiceMac needs to explicitly clear the delegate on the
Chrome side before asking the view delegate to switch out its model
(which happens via AppListServiceImpl::GetViewDelegate(Profile*).

Views platforms are not affected, because they retain a raw pointer to
the AppListModel* separately from AppListViewDelegate::GetModel(). This
only works because the AppListModel* sticks around until Chrome
shutdown, when it's torn down with the other keyed services via the
~ProfileManager() destructor.

This delayed destruction means that verifying observers in a test needs
a lot of plumbing in non-test code (see patchset1). Instead, a DCHECK is
added in AppListItemList to ensure RemoveObserver always removes
something, then test coverage is given by
AppListServiceImplBrowserTest.ShowLoadedProfiles.

This CL fixes part of the flakiness in the app list interactive uitests
on Mac (http://crbug.com/415264), but I've discovered other sources of
flakiness to fix before re-enabling those tests. It should, however, fix
the recent crashes (http://crbug.com/416345).

BUG=415264, 416345
TEST=AppListServiceImplBrowserTest.ShowLoadedProfiles
TEST=crbug/416345: have multiple profiles and switch between them in the
app launcher on mac many times. Chrome shouldn't crash.

Review URL: https://codereview.chromium.org/592983002

Cr-Commit-Position: refs/heads/master@{#296152}
chrome/browser/ui/app_list/app_list_service_mac.mm
ui/app_list/app_list_item_list.cc