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