Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/browser/ui/app_list/app_list_view_delegate.cc

Issue 1631373003: Refactor ProfileInfoCache in c/b/ui/app_list (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change to std::cref Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm>
10 #include <functional>
9 #include <vector> 11 #include <vector>
10 12
11 #include "apps/custom_launcher_page_contents.h" 13 #include "apps/custom_launcher_page_contents.h"
12 #include "base/callback.h" 14 #include "base/callback.h"
13 #include "base/command_line.h" 15 #include "base/command_line.h"
14 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
15 #include "base/metrics/user_metrics.h" 17 #include "base/metrics/user_metrics.h"
16 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
17 #include "base/profiler/scoped_tracker.h" 19 #include "base/profiler/scoped_tracker.h"
18 #include "base/stl_util.h" 20 #include "base/stl_util.h"
19 #include "build/build_config.h" 21 #include "build/build_config.h"
20 #include "chrome/browser/apps/scoped_keep_alive.h" 22 #include "chrome/browser/apps/scoped_keep_alive.h"
21 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/chrome_notification_types.h" 24 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/profiles/profile_info_cache.h" 25 #include "chrome/browser/profiles/profile_attributes_entry.h"
26 #include "chrome/browser/profiles/profile_attributes_storage.h"
24 #include "chrome/browser/profiles/profile_manager.h" 27 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/browser/search/hotword_service.h" 28 #include "chrome/browser/search/hotword_service.h"
26 #include "chrome/browser/search/hotword_service_factory.h" 29 #include "chrome/browser/search/hotword_service_factory.h"
27 #include "chrome/browser/search_engines/template_url_service_factory.h" 30 #include "chrome/browser/search_engines/template_url_service_factory.h"
28 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 31 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
29 #include "chrome/browser/ui/app_list/app_list_service.h" 32 #include "chrome/browser/ui/app_list/app_list_service.h"
30 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" 33 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
31 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" 34 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
32 #include "chrome/browser/ui/app_list/launcher_page_event_dispatcher.h" 35 #include "chrome/browser/ui/app_list/launcher_page_event_dispatcher.h"
33 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" 36 #include "chrome/browser/ui/app_list/search/search_controller_factory.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 base::Callback<void(const base::FilePath&)> callback, 103 base::Callback<void(const base::FilePath&)> callback,
101 scoped_ptr<web_app::ShortcutInfo> info) { 104 scoped_ptr<web_app::ShortcutInfo> info) {
102 content::BrowserThread::PostTaskAndReplyWithResult( 105 content::BrowserThread::PostTaskAndReplyWithResult(
103 content::BrowserThread::FILE, FROM_HERE, 106 content::BrowserThread::FILE, FROM_HERE,
104 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, 107 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir,
105 base::Passed(&info)), 108 base::Passed(&info)),
106 callback); 109 callback);
107 } 110 }
108 #endif 111 #endif
109 112
110 void PopulateUsers(const ProfileInfoCache& profile_info, 113 void PopulateUsers(const base::FilePath& active_profile_path,
111 const base::FilePath& active_profile_path,
112 app_list::AppListViewDelegate::Users* users) { 114 app_list::AppListViewDelegate::Users* users) {
113 users->clear(); 115 users->clear();
114 const size_t count = profile_info.GetNumberOfProfiles(); 116 std::vector<ProfileAttributesEntry*> entries = g_browser_process->
115 for (size_t i = 0; i < count; ++i) { 117 profile_manager()->GetProfileAttributesStorage().
118 GetAllProfilesAttributes();
119 ProfileAttributesEntry::SortComparator comp;
120 std::sort(entries.begin(), entries.end(), std::cref(comp));
lwchkg 2016/02/03 17:18:38 Tried a few methods for one day... most failing ex
121 for (const auto entry : entries) {
116 app_list::AppListViewDelegate::User user; 122 app_list::AppListViewDelegate::User user;
117 user.name = profile_info.GetNameOfProfileAtIndex(i); 123 user.name = entry->GetName();
118 user.email = profile_info.GetUserNameOfProfileAtIndex(i); 124 user.email = entry->GetUserName();
119 user.profile_path = profile_info.GetPathOfProfileAtIndex(i); 125 user.profile_path = entry->GetPath();
120 user.active = active_profile_path == user.profile_path; 126 user.active = active_profile_path == user.profile_path;
121 users->push_back(user); 127 users->push_back(user);
122 } 128 }
123 } 129 }
124 130
125 // Gets a list of URLs of the custom launcher pages to show in the launcher. 131 // 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 132 // Returns a URL for each installed launcher page. If --custom-launcher-page is
127 // specified and valid, also includes that URL. 133 // specified and valid, also includes that URL.
128 void GetCustomLauncherPageUrls(content::BrowserContext* browser_context, 134 void GetCustomLauncherPageUrls(content::BrowserContext* browser_context,
129 std::vector<GURL>* urls) { 135 std::vector<GURL>* urls) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 i != profiles.end(); 198 i != profiles.end();
193 ++i) { 199 ++i) {
194 SigninManagerBase* manager = 200 SigninManagerBase* manager =
195 SigninManagerFactory::GetForProfileIfExists(*i); 201 SigninManagerFactory::GetForProfileIfExists(*i);
196 if (manager) { 202 if (manager) {
197 DCHECK(!scoped_observer_.IsObserving(manager)); 203 DCHECK(!scoped_observer_.IsObserving(manager));
198 scoped_observer_.Add(manager); 204 scoped_observer_.Add(manager);
199 } 205 }
200 } 206 }
201 207
202 profile_manager->GetProfileInfoCache().AddObserver(this); 208 profile_manager->GetProfileAttributesStorage().AddObserver(this);
203 speech_ui_.reset(new app_list::SpeechUIModel); 209 speech_ui_.reset(new app_list::SpeechUIModel);
204 210
205 #if defined(GOOGLE_CHROME_BUILD) 211 #if defined(GOOGLE_CHROME_BUILD)
206 gfx::ImageSkia* image; 212 gfx::ImageSkia* image;
207 { 213 {
208 // TODO(tapted): Remove ScopedTracker below once crbug.com/431326 is fixed. 214 // TODO(tapted): Remove ScopedTracker below once crbug.com/431326 is fixed.
209 tracked_objects::ScopedTracker tracking_profile( 215 tracked_objects::ScopedTracker tracking_profile(
210 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 GetImageSkiaNamed()")); 216 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 GetImageSkiaNamed()"));
211 image = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 217 image = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
212 IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH); 218 IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH);
213 } 219 }
214 220
215 speech_ui_->set_logo(*image); 221 speech_ui_->set_logo(*image);
216 #endif 222 #endif
217 223
218 registrar_.Add(this, 224 registrar_.Add(this,
219 chrome::NOTIFICATION_APP_TERMINATING, 225 chrome::NOTIFICATION_APP_TERMINATING,
220 content::NotificationService::AllSources()); 226 content::NotificationService::AllSources());
221 } 227 }
222 228
223 AppListViewDelegate::~AppListViewDelegate() { 229 AppListViewDelegate::~AppListViewDelegate() {
224 // Note that the destructor is not always called. E.g. on Mac, this is owned 230 // 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 231 // by a leaky singleton. Essential shutdown work must be done by observing
226 // chrome::NOTIFICATION_APP_TERMINATING. 232 // chrome::NOTIFICATION_APP_TERMINATING.
227 SetProfile(NULL); 233 SetProfile(NULL);
228 g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( 234 g_browser_process->profile_manager()->GetProfileAttributesStorage().
229 this); 235 RemoveObserver(this);
230 236
231 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); 237 SigninManagerFactory* factory = SigninManagerFactory::GetInstance();
232 if (factory) 238 if (factory)
233 factory->RemoveObserver(this); 239 factory->RemoveObserver(this);
234 } 240 }
235 241
236 void AppListViewDelegate::SetProfile(Profile* new_profile) { 242 void AppListViewDelegate::SetProfile(Profile* new_profile) {
237 if (profile_ == new_profile) 243 if (profile_ == new_profile)
238 return; 244 return;
239 245
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 if (!profile_) 329 if (!profile_)
324 return; 330 return;
325 331
326 // Don't populate the app list users if we are on the ash desktop. 332 // Don't populate the app list users if we are on the ash desktop.
327 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( 333 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow(
328 controller_->GetAppListWindow()); 334 controller_->GetAppListWindow());
329 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) 335 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH)
330 return; 336 return;
331 337
332 // Populate the app list users. 338 // Populate the app list users.
333 PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(), 339 PopulateUsers(profile_->GetPath(), &users_);
334 profile_->GetPath(),
335 &users_);
336 340
337 FOR_EACH_OBSERVER( 341 FOR_EACH_OBSERVER(
338 app_list::AppListViewDelegateObserver, observers_, OnProfilesChanged()); 342 app_list::AppListViewDelegateObserver, observers_, OnProfilesChanged());
339 } 343 }
340 344
341 void AppListViewDelegate::SetUpCustomLauncherPages() { 345 void AppListViewDelegate::SetUpCustomLauncherPages() {
342 std::vector<GURL> custom_launcher_page_urls; 346 std::vector<GURL> custom_launcher_page_urls;
343 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); 347 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls);
344 if (custom_launcher_page_urls.empty()) 348 if (custom_launcher_page_urls.empty())
345 return; 349 return;
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 830
827 // SigninManagerFactory is not a leaky singleton (unlike this class), and 831 // SigninManagerFactory is not a leaky singleton (unlike this class), and
828 // its destructor will check that it has no remaining observers. 832 // its destructor will check that it has no remaining observers.
829 scoped_observer_.RemoveAll(); 833 scoped_observer_.RemoveAll();
830 SigninManagerFactory::GetInstance()->RemoveObserver(this); 834 SigninManagerFactory::GetInstance()->RemoveObserver(this);
831 break; 835 break;
832 default: 836 default:
833 NOTREACHED(); 837 NOTREACHED();
834 } 838 }
835 } 839 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698