Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" | 5 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "apps/custom_launcher_page_contents.h" | 9 #include "apps/custom_launcher_page_contents.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
| 29 #include "chrome/browser/ui/chrome_pages.h" | 29 #include "chrome/browser/ui/chrome_pages.h" |
| 30 #include "chrome/browser/ui/host_desktop.h" | 30 #include "chrome/browser/ui/host_desktop.h" |
| 31 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 31 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 32 #include "chrome/browser/web_applications/web_app.h" | 32 #include "chrome/browser/web_applications/web_app.h" |
| 33 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/extensions/extension_constants.h" | 34 #include "chrome/common/extensions/extension_constants.h" |
| 35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
| 36 #include "components/signin/core/browser/signin_manager.h" | 36 #include "components/signin/core/browser/signin_manager.h" |
| 37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/notification_service.h" | |
| 38 #include "content/public/browser/page_navigator.h" | 39 #include "content/public/browser/page_navigator.h" |
| 39 #include "content/public/browser/user_metrics.h" | 40 #include "content/public/browser/user_metrics.h" |
| 40 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 41 #include "extensions/browser/extension_registry.h" | 42 #include "extensions/browser/extension_registry.h" |
| 42 #include "extensions/common/constants.h" | 43 #include "extensions/common/constants.h" |
| 43 #include "extensions/common/extension_set.h" | 44 #include "extensions/common/extension_set.h" |
| 44 #include "extensions/common/manifest_constants.h" | 45 #include "extensions/common/manifest_constants.h" |
| 45 #include "extensions/common/manifest_handlers/launcher_page_info.h" | 46 #include "extensions/common/manifest_handlers/launcher_page_info.h" |
| 46 #include "grit/theme_resources.h" | 47 #include "grit/theme_resources.h" |
| 47 #include "ui/app_list/app_list_switches.h" | 48 #include "ui/app_list/app_list_switches.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 | 175 |
| 175 profile_manager->GetProfileInfoCache().AddObserver(this); | 176 profile_manager->GetProfileInfoCache().AddObserver(this); |
| 176 speech_ui_.reset(new app_list::SpeechUIModel); | 177 speech_ui_.reset(new app_list::SpeechUIModel); |
| 177 | 178 |
| 178 #if defined(GOOGLE_CHROME_BUILD) | 179 #if defined(GOOGLE_CHROME_BUILD) |
| 179 speech_ui_->set_logo( | 180 speech_ui_->set_logo( |
| 180 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 181 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 181 IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH)); | 182 IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH)); |
| 182 #endif | 183 #endif |
| 183 SetProfile(profile); | 184 SetProfile(profile); |
| 185 | |
| 186 registrar_.Add(this, | |
| 187 chrome::NOTIFICATION_APP_TERMINATING, | |
| 188 content::NotificationService::AllSources()); | |
| 184 } | 189 } |
| 185 | 190 |
| 186 AppListViewDelegate::~AppListViewDelegate() { | 191 AppListViewDelegate::~AppListViewDelegate() { |
| 192 // Note that the destructor is not always called. E.g. on Mac, this is owned | |
| 193 // by a leaky singleton. Essential shutdown work must be done by observing | |
| 194 // chrome::NOTIFICATION_APP_TERMINATING. | |
| 187 SetProfile(NULL); | 195 SetProfile(NULL); |
| 188 g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( | 196 g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( |
| 189 this); | 197 this); |
| 190 | 198 |
| 191 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); | 199 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); |
| 192 if (factory) | 200 if (factory) |
| 193 factory->RemoveObserver(this); | 201 factory->RemoveObserver(this); |
| 194 } | 202 } |
| 195 | 203 |
| 196 void AppListViewDelegate::SetProfile(Profile* new_profile) { | 204 void AppListViewDelegate::SetProfile(Profile* new_profile) { |
| 205 if (profile_ == new_profile) | |
|
Matt Giuca
2014/09/11 03:50:37
Are these profile checks (this one, and the next t
tapted
2014/09/11 04:57:45
They're needed, but only due to this change. Previ
Matt Giuca
2014/09/11 08:17:58
Acknowledged.
| |
| 206 return; | |
| 207 | |
| 197 if (profile_) { | 208 if (profile_) { |
| 198 // Note: |search_controller_| has a reference to |speech_ui_| so must be | 209 // Note: |search_controller_| has a reference to |speech_ui_| so must be |
| 199 // destroyed first. | 210 // destroyed first. |
| 200 search_controller_.reset(); | 211 search_controller_.reset(); |
| 201 custom_page_contents_.clear(); | 212 custom_page_contents_.clear(); |
| 202 app_list::StartPageService* start_page_service = | 213 app_list::StartPageService* start_page_service = |
| 203 app_list::StartPageService::Get(profile_); | 214 app_list::StartPageService::Get(profile_); |
| 204 if (start_page_service) | 215 if (start_page_service) |
| 205 start_page_service->RemoveObserver(this); | 216 start_page_service->RemoveObserver(this); |
| 206 #if defined(USE_ASH) | 217 #if defined(USE_ASH) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 : app_list::SPEECH_RECOGNITION_OFF); | 252 : app_list::SPEECH_RECOGNITION_OFF); |
| 242 | 253 |
| 243 search_controller_.reset(new app_list::SearchController(profile_, | 254 search_controller_.reset(new app_list::SearchController(profile_, |
| 244 model_->search_box(), | 255 model_->search_box(), |
| 245 model_->results(), | 256 model_->results(), |
| 246 speech_ui_.get(), | 257 speech_ui_.get(), |
| 247 controller_)); | 258 controller_)); |
| 248 } | 259 } |
| 249 | 260 |
| 250 void AppListViewDelegate::SetUpProfileSwitcher() { | 261 void AppListViewDelegate::SetUpProfileSwitcher() { |
| 262 // If a profile change is observed when there is no app list, there is nothing | |
| 263 // to update until SetProfile() calls this function again. | |
| 264 if (!profile_) | |
| 265 return; | |
| 266 | |
| 251 // Don't populate the app list users if we are on the ash desktop. | 267 // Don't populate the app list users if we are on the ash desktop. |
| 252 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 268 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 253 controller_->GetAppListWindow()); | 269 controller_->GetAppListWindow()); |
| 254 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) | 270 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) |
| 255 return; | 271 return; |
| 256 | 272 |
| 257 // Populate the app list users. | 273 // Populate the app list users. |
| 258 PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(), | 274 PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(), |
| 259 profile_->GetPath(), | 275 profile_->GetPath(), |
| 260 &users_); | 276 &users_); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 } | 448 } |
| 433 } | 449 } |
| 434 | 450 |
| 435 void AppListViewDelegate::Dismiss() { | 451 void AppListViewDelegate::Dismiss() { |
| 436 controller_->DismissView(); | 452 controller_->DismissView(); |
| 437 } | 453 } |
| 438 | 454 |
| 439 void AppListViewDelegate::ViewClosing() { | 455 void AppListViewDelegate::ViewClosing() { |
| 440 controller_->ViewClosing(); | 456 controller_->ViewClosing(); |
| 441 | 457 |
| 458 if (!profile_) | |
| 459 return; | |
| 460 | |
| 442 app_list::StartPageService* service = | 461 app_list::StartPageService* service = |
| 443 app_list::StartPageService::Get(profile_); | 462 app_list::StartPageService::Get(profile_); |
| 444 if (service) { | 463 if (service) { |
| 445 service->AppListHidden(); | 464 service->AppListHidden(); |
| 446 if (service->HotwordEnabled()) { | 465 if (service->HotwordEnabled()) { |
| 447 HotwordService* hotword_service = | 466 HotwordService* hotword_service = |
| 448 HotwordServiceFactory::GetForProfile(profile_); | 467 HotwordServiceFactory::GetForProfile(profile_); |
| 449 if (hotword_service) | 468 if (hotword_service) |
| 450 hotword_service->StopHotwordSession(this); | 469 hotword_service->StopHotwordSession(this); |
| 451 } | 470 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 | 635 |
| 617 void AppListViewDelegate::AddObserver( | 636 void AppListViewDelegate::AddObserver( |
| 618 app_list::AppListViewDelegateObserver* observer) { | 637 app_list::AppListViewDelegateObserver* observer) { |
| 619 observers_.AddObserver(observer); | 638 observers_.AddObserver(observer); |
| 620 } | 639 } |
| 621 | 640 |
| 622 void AppListViewDelegate::RemoveObserver( | 641 void AppListViewDelegate::RemoveObserver( |
| 623 app_list::AppListViewDelegateObserver* observer) { | 642 app_list::AppListViewDelegateObserver* observer) { |
| 624 observers_.RemoveObserver(observer); | 643 observers_.RemoveObserver(observer); |
| 625 } | 644 } |
| 645 | |
| 646 void AppListViewDelegate::Observe(int type, | |
| 647 const content::NotificationSource& source, | |
| 648 const content::NotificationDetails& details) { | |
| 649 switch (type) { | |
| 650 case chrome::NOTIFICATION_APP_TERMINATING: | |
| 651 SetProfile(NULL); // Ensures launcher page web contents are torn down. | |
| 652 | |
| 653 // Stop observing SigninManagers. SigninManagerFactory is not a leaky | |
| 654 // singleton like this, so will get offended without the following. | |
|
Matt Giuca
2014/09/11 03:50:37
Cute :) But can you be clear instead of saying "ge
tapted
2014/09/11 04:57:45
Done.
| |
| 655 scoped_observer_.RemoveAll(); | |
| 656 SigninManagerFactory::GetInstance()->RemoveObserver(this); | |
| 657 break; | |
| 658 default: | |
| 659 NOTREACHED(); | |
| 660 } | |
| 661 } | |
| OLD | NEW |