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 <algorithm> |
tapted
2016/01/31 23:04:37
but you should keep std::vector here (as well as a
| |
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/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
17 #include "base/profiler/scoped_tracker.h" | 17 #include "base/profiler/scoped_tracker.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "chrome/browser/apps/scoped_keep_alive.h" | 20 #include "chrome/browser/apps/scoped_keep_alive.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
23 #include "chrome/browser/profiles/profile_info_cache.h" | 23 #include "chrome/browser/profiles/profile_attributes_entry.h" |
24 #include "chrome/browser/profiles/profile_attributes_storage.h" | |
24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
25 #include "chrome/browser/search/hotword_service.h" | 26 #include "chrome/browser/search/hotword_service.h" |
26 #include "chrome/browser/search/hotword_service_factory.h" | 27 #include "chrome/browser/search/hotword_service_factory.h" |
27 #include "chrome/browser/search_engines/template_url_service_factory.h" | 28 #include "chrome/browser/search_engines/template_url_service_factory.h" |
28 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 29 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
29 #include "chrome/browser/ui/app_list/app_list_service.h" | 30 #include "chrome/browser/ui/app_list/app_list_service.h" |
30 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 31 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
31 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 32 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
32 #include "chrome/browser/ui/app_list/launcher_page_event_dispatcher.h" | 33 #include "chrome/browser/ui/app_list/launcher_page_event_dispatcher.h" |
33 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" | 34 #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, | 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 GetAllProfilesAttributes(); | |
117 std::sort(entries.begin(), entries.end(), | |
118 ProfileAttributesEntry::SortComparator( | |
119 ProfileAttributesEntry::SortComparator::GetCollator().get())); | |
120 for (const auto& entry : entries) { | |
lwchkg
2016/01/31 19:12:22
Should remove the & because the underlying data ar
| |
116 app_list::AppListViewDelegate::User user; | 121 app_list::AppListViewDelegate::User user; |
117 user.name = profile_info.GetNameOfProfileAtIndex(i); | 122 user.name = entry->GetName(); |
118 user.email = profile_info.GetUserNameOfProfileAtIndex(i); | 123 user.email = entry->GetUserName(); |
119 user.profile_path = profile_info.GetPathOfProfileAtIndex(i); | 124 user.profile_path = entry->GetPath(); |
120 user.active = active_profile_path == user.profile_path; | 125 user.active = active_profile_path == user.profile_path; |
121 users->push_back(user); | 126 users->push_back(user); |
122 } | 127 } |
123 } | 128 } |
124 | 129 |
125 // Gets a list of URLs of the custom launcher pages to show in the launcher. | 130 // 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 | 131 // Returns a URL for each installed launcher page. If --custom-launcher-page is |
127 // specified and valid, also includes that URL. | 132 // specified and valid, also includes that URL. |
128 void GetCustomLauncherPageUrls(content::BrowserContext* browser_context, | 133 void GetCustomLauncherPageUrls(content::BrowserContext* browser_context, |
129 std::vector<GURL>* urls) { | 134 std::vector<GURL>* urls) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 i != profiles.end(); | 197 i != profiles.end(); |
193 ++i) { | 198 ++i) { |
194 SigninManagerBase* manager = | 199 SigninManagerBase* manager = |
195 SigninManagerFactory::GetForProfileIfExists(*i); | 200 SigninManagerFactory::GetForProfileIfExists(*i); |
196 if (manager) { | 201 if (manager) { |
197 DCHECK(!scoped_observer_.IsObserving(manager)); | 202 DCHECK(!scoped_observer_.IsObserving(manager)); |
198 scoped_observer_.Add(manager); | 203 scoped_observer_.Add(manager); |
199 } | 204 } |
200 } | 205 } |
201 | 206 |
202 profile_manager->GetProfileInfoCache().AddObserver(this); | 207 profile_manager->GetProfileAttributesStorage().AddObserver(this); |
203 speech_ui_.reset(new app_list::SpeechUIModel); | 208 speech_ui_.reset(new app_list::SpeechUIModel); |
204 | 209 |
205 #if defined(GOOGLE_CHROME_BUILD) | 210 #if defined(GOOGLE_CHROME_BUILD) |
206 gfx::ImageSkia* image; | 211 gfx::ImageSkia* image; |
207 { | 212 { |
208 // TODO(tapted): Remove ScopedTracker below once crbug.com/431326 is fixed. | 213 // TODO(tapted): Remove ScopedTracker below once crbug.com/431326 is fixed. |
209 tracked_objects::ScopedTracker tracking_profile( | 214 tracked_objects::ScopedTracker tracking_profile( |
210 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 GetImageSkiaNamed()")); | 215 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 GetImageSkiaNamed()")); |
211 image = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 216 image = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
212 IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH); | 217 IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH); |
213 } | 218 } |
214 | 219 |
215 speech_ui_->set_logo(*image); | 220 speech_ui_->set_logo(*image); |
216 #endif | 221 #endif |
217 | 222 |
218 registrar_.Add(this, | 223 registrar_.Add(this, |
219 chrome::NOTIFICATION_APP_TERMINATING, | 224 chrome::NOTIFICATION_APP_TERMINATING, |
220 content::NotificationService::AllSources()); | 225 content::NotificationService::AllSources()); |
221 } | 226 } |
222 | 227 |
223 AppListViewDelegate::~AppListViewDelegate() { | 228 AppListViewDelegate::~AppListViewDelegate() { |
224 // Note that the destructor is not always called. E.g. on Mac, this is owned | 229 // 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 | 230 // by a leaky singleton. Essential shutdown work must be done by observing |
226 // chrome::NOTIFICATION_APP_TERMINATING. | 231 // chrome::NOTIFICATION_APP_TERMINATING. |
227 SetProfile(NULL); | 232 SetProfile(NULL); |
228 g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( | 233 g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
229 this); | 234 RemoveObserver(this); |
230 | 235 |
231 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); | 236 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); |
232 if (factory) | 237 if (factory) |
233 factory->RemoveObserver(this); | 238 factory->RemoveObserver(this); |
234 } | 239 } |
235 | 240 |
236 void AppListViewDelegate::SetProfile(Profile* new_profile) { | 241 void AppListViewDelegate::SetProfile(Profile* new_profile) { |
237 if (profile_ == new_profile) | 242 if (profile_ == new_profile) |
238 return; | 243 return; |
239 | 244 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 if (!profile_) | 328 if (!profile_) |
324 return; | 329 return; |
325 | 330 |
326 // Don't populate the app list users if we are on the ash desktop. | 331 // Don't populate the app list users if we are on the ash desktop. |
327 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 332 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
328 controller_->GetAppListWindow()); | 333 controller_->GetAppListWindow()); |
329 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) | 334 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) |
330 return; | 335 return; |
331 | 336 |
332 // Populate the app list users. | 337 // Populate the app list users. |
333 PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(), | 338 PopulateUsers(profile_->GetPath(), &users_); |
334 profile_->GetPath(), | |
335 &users_); | |
336 | 339 |
337 FOR_EACH_OBSERVER( | 340 FOR_EACH_OBSERVER( |
338 app_list::AppListViewDelegateObserver, observers_, OnProfilesChanged()); | 341 app_list::AppListViewDelegateObserver, observers_, OnProfilesChanged()); |
339 } | 342 } |
340 | 343 |
341 void AppListViewDelegate::SetUpCustomLauncherPages() { | 344 void AppListViewDelegate::SetUpCustomLauncherPages() { |
342 std::vector<GURL> custom_launcher_page_urls; | 345 std::vector<GURL> custom_launcher_page_urls; |
343 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); | 346 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); |
344 if (custom_launcher_page_urls.empty()) | 347 if (custom_launcher_page_urls.empty()) |
345 return; | 348 return; |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 | 829 |
827 // SigninManagerFactory is not a leaky singleton (unlike this class), and | 830 // SigninManagerFactory is not a leaky singleton (unlike this class), and |
828 // its destructor will check that it has no remaining observers. | 831 // its destructor will check that it has no remaining observers. |
829 scoped_observer_.RemoveAll(); | 832 scoped_observer_.RemoveAll(); |
830 SigninManagerFactory::GetInstance()->RemoveObserver(this); | 833 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
831 break; | 834 break; |
832 default: | 835 default: |
833 NOTREACHED(); | 836 NOTREACHED(); |
834 } | 837 } |
835 } | 838 } |
OLD | NEW |