| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "apps/custom_launcher_page_contents.h" | 11 #include "apps/custom_launcher_page_contents.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/metrics/user_metrics.h" | 15 #include "base/metrics/user_metrics.h" |
| 16 #include "base/profiler/scoped_tracker.h" | 16 #include "base/profiler/scoped_tracker.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/apps/scoped_keep_alive.h" | 19 #include "chrome/browser/apps/scoped_keep_alive.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/profiles/profile_info_cache.h" | 22 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 23 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/search/hotword_service.h" | 25 #include "chrome/browser/search/hotword_service.h" |
| 25 #include "chrome/browser/search/hotword_service_factory.h" | 26 #include "chrome/browser/search/hotword_service_factory.h" |
| 26 #include "chrome/browser/search_engines/template_url_service_factory.h" | 27 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 27 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 28 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 28 #include "chrome/browser/ui/app_list/app_list_service.h" | 29 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 29 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 30 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 30 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 31 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
| 31 #include "chrome/browser/ui/app_list/launcher_page_event_dispatcher.h" | 32 #include "chrome/browser/ui/app_list/launcher_page_event_dispatcher.h" |
| 32 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" | 33 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 base::Callback<void(const base::FilePath&)> callback, | 101 base::Callback<void(const base::FilePath&)> callback, |
| 101 scoped_ptr<web_app::ShortcutInfo> info) { | 102 scoped_ptr<web_app::ShortcutInfo> info) { |
| 102 content::BrowserThread::PostTaskAndReplyWithResult( | 103 content::BrowserThread::PostTaskAndReplyWithResult( |
| 103 content::BrowserThread::FILE, FROM_HERE, | 104 content::BrowserThread::FILE, FROM_HERE, |
| 104 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, | 105 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, |
| 105 base::Passed(&info)), | 106 base::Passed(&info)), |
| 106 callback); | 107 callback); |
| 107 } | 108 } |
| 108 #endif | 109 #endif |
| 109 | 110 |
| 110 void PopulateUsers(const ProfileInfoCache& profile_info, | 111 void PopulateUsers(const base::FilePath& active_profile_path, |
| 111 const base::FilePath& active_profile_path, | |
| 112 app_list::AppListViewDelegate::Users* users) { | 112 app_list::AppListViewDelegate::Users* users) { |
| 113 users->clear(); | 113 users->clear(); |
| 114 const size_t count = profile_info.GetNumberOfProfiles(); | 114 std::vector<ProfileAttributesEntry*> entries = g_browser_process-> |
| 115 for (size_t i = 0; i < count; ++i) { | 115 profile_manager()->GetProfileAttributesStorage(). |
| 116 GetAllProfilesAttributesSortedByName(); |
| 117 for (const auto entry : entries) { |
| 116 app_list::AppListViewDelegate::User user; | 118 app_list::AppListViewDelegate::User user; |
| 117 user.name = profile_info.GetNameOfProfileAtIndex(i); | 119 user.name = entry->GetName(); |
| 118 user.email = profile_info.GetUserNameOfProfileAtIndex(i); | 120 user.email = entry->GetUserName(); |
| 119 user.profile_path = profile_info.GetPathOfProfileAtIndex(i); | 121 user.profile_path = entry->GetPath(); |
| 120 user.active = active_profile_path == user.profile_path; | 122 user.active = active_profile_path == user.profile_path; |
| 121 users->push_back(user); | 123 users->push_back(user); |
| 122 } | 124 } |
| 123 } | 125 } |
| 124 | 126 |
| 125 // Gets a list of URLs of the custom launcher pages to show in the launcher. | 127 // Gets a list of URLs of the custom launcher pages to show in the launcher. |
| 126 // Returns a URL for each installed launcher page. If --custom-launcher-page is | 128 // Returns a URL for each installed launcher page. If --custom-launcher-page is |
| 127 // specified and valid, also includes that URL. | 129 // specified and valid, also includes that URL. |
| 128 void GetCustomLauncherPageUrls(content::BrowserContext* browser_context, | 130 void GetCustomLauncherPageUrls(content::BrowserContext* browser_context, |
| 129 std::vector<GURL>* urls) { | 131 std::vector<GURL>* urls) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 i != profiles.end(); | 194 i != profiles.end(); |
| 193 ++i) { | 195 ++i) { |
| 194 SigninManagerBase* manager = | 196 SigninManagerBase* manager = |
| 195 SigninManagerFactory::GetForProfileIfExists(*i); | 197 SigninManagerFactory::GetForProfileIfExists(*i); |
| 196 if (manager) { | 198 if (manager) { |
| 197 DCHECK(!scoped_observer_.IsObserving(manager)); | 199 DCHECK(!scoped_observer_.IsObserving(manager)); |
| 198 scoped_observer_.Add(manager); | 200 scoped_observer_.Add(manager); |
| 199 } | 201 } |
| 200 } | 202 } |
| 201 | 203 |
| 202 profile_manager->GetProfileInfoCache().AddObserver(this); | 204 profile_manager->GetProfileAttributesStorage().AddObserver(this); |
| 203 speech_ui_.reset(new app_list::SpeechUIModel); | 205 speech_ui_.reset(new app_list::SpeechUIModel); |
| 204 | 206 |
| 205 #if defined(GOOGLE_CHROME_BUILD) | 207 #if defined(GOOGLE_CHROME_BUILD) |
| 206 gfx::ImageSkia* image; | 208 gfx::ImageSkia* image; |
| 207 { | 209 { |
| 208 // TODO(tapted): Remove ScopedTracker below once crbug.com/431326 is fixed. | 210 // TODO(tapted): Remove ScopedTracker below once crbug.com/431326 is fixed. |
| 209 tracked_objects::ScopedTracker tracking_profile( | 211 tracked_objects::ScopedTracker tracking_profile( |
| 210 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 GetImageSkiaNamed()")); | 212 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 GetImageSkiaNamed()")); |
| 211 image = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 213 image = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 212 IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH); | 214 IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH); |
| 213 } | 215 } |
| 214 | 216 |
| 215 speech_ui_->set_logo(*image); | 217 speech_ui_->set_logo(*image); |
| 216 #endif | 218 #endif |
| 217 | 219 |
| 218 registrar_.Add(this, | 220 registrar_.Add(this, |
| 219 chrome::NOTIFICATION_APP_TERMINATING, | 221 chrome::NOTIFICATION_APP_TERMINATING, |
| 220 content::NotificationService::AllSources()); | 222 content::NotificationService::AllSources()); |
| 221 } | 223 } |
| 222 | 224 |
| 223 AppListViewDelegate::~AppListViewDelegate() { | 225 AppListViewDelegate::~AppListViewDelegate() { |
| 224 // Note that the destructor is not always called. E.g. on Mac, this is owned | 226 // Note that the destructor is not always called. E.g. on Mac, this is owned |
| 225 // by a leaky singleton. Essential shutdown work must be done by observing | 227 // by a leaky singleton. Essential shutdown work must be done by observing |
| 226 // chrome::NOTIFICATION_APP_TERMINATING. | 228 // chrome::NOTIFICATION_APP_TERMINATING. |
| 227 SetProfile(NULL); | 229 SetProfile(NULL); |
| 228 g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( | 230 g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 229 this); | 231 RemoveObserver(this); |
| 230 | 232 |
| 231 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); | 233 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); |
| 232 if (factory) | 234 if (factory) |
| 233 factory->RemoveObserver(this); | 235 factory->RemoveObserver(this); |
| 234 } | 236 } |
| 235 | 237 |
| 236 void AppListViewDelegate::SetProfile(Profile* new_profile) { | 238 void AppListViewDelegate::SetProfile(Profile* new_profile) { |
| 237 if (profile_ == new_profile) | 239 if (profile_ == new_profile) |
| 238 return; | 240 return; |
| 239 | 241 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 if (!profile_) | 325 if (!profile_) |
| 324 return; | 326 return; |
| 325 | 327 |
| 326 // Don't populate the app list users if we are on the ash desktop. | 328 // Don't populate the app list users if we are on the ash desktop. |
| 327 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 329 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 328 controller_->GetAppListWindow()); | 330 controller_->GetAppListWindow()); |
| 329 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) | 331 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) |
| 330 return; | 332 return; |
| 331 | 333 |
| 332 // Populate the app list users. | 334 // Populate the app list users. |
| 333 PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(), | 335 PopulateUsers(profile_->GetPath(), &users_); |
| 334 profile_->GetPath(), | |
| 335 &users_); | |
| 336 | 336 |
| 337 FOR_EACH_OBSERVER( | 337 FOR_EACH_OBSERVER( |
| 338 app_list::AppListViewDelegateObserver, observers_, OnProfilesChanged()); | 338 app_list::AppListViewDelegateObserver, observers_, OnProfilesChanged()); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void AppListViewDelegate::SetUpCustomLauncherPages() { | 341 void AppListViewDelegate::SetUpCustomLauncherPages() { |
| 342 std::vector<GURL> custom_launcher_page_urls; | 342 std::vector<GURL> custom_launcher_page_urls; |
| 343 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); | 343 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); |
| 344 if (custom_launcher_page_urls.empty()) | 344 if (custom_launcher_page_urls.empty()) |
| 345 return; | 345 return; |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 | 822 |
| 823 // SigninManagerFactory is not a leaky singleton (unlike this class), and | 823 // SigninManagerFactory is not a leaky singleton (unlike this class), and |
| 824 // its destructor will check that it has no remaining observers. | 824 // its destructor will check that it has no remaining observers. |
| 825 scoped_observer_.RemoveAll(); | 825 scoped_observer_.RemoveAll(); |
| 826 SigninManagerFactory::GetInstance()->RemoveObserver(this); | 826 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
| 827 break; | 827 break; |
| 828 default: | 828 default: |
| 829 NOTREACHED(); | 829 NOTREACHED(); |
| 830 } | 830 } |
| 831 } | 831 } |
| OLD | NEW |