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

Side by Side Diff: chrome/browser/profiles/profile_manager.cc

Issue 10823217: Create/Delete windows profile shortcuts (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 <set> 5 #include <set>
6 6
7 #include "chrome/browser/profiles/profile_manager.h" 7 #include "chrome/browser/profiles/profile_manager.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 this, 262 this,
263 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, 263 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
264 content::NotificationService::AllSources()); 264 content::NotificationService::AllSources());
265 registrar_.Add( 265 registrar_.Add(
266 this, 266 this,
267 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 267 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
268 content::NotificationService::AllSources()); 268 content::NotificationService::AllSources());
269 } 269 }
270 270
271 ProfileManager::~ProfileManager() { 271 ProfileManager::~ProfileManager() {
272 #if defined(OS_WIN)
273 if (profile_shortcut_manager_.get())
274 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get());
275 #endif
276 } 272 }
277 273
278 FilePath ProfileManager::GetDefaultProfileDir( 274 FilePath ProfileManager::GetDefaultProfileDir(
279 const FilePath& user_data_dir) { 275 const FilePath& user_data_dir) {
280 FilePath default_profile_dir(user_data_dir); 276 FilePath default_profile_dir(user_data_dir);
281 default_profile_dir = 277 default_profile_dir =
282 default_profile_dir.AppendASCII(chrome::kInitialProfile); 278 default_profile_dir.AppendASCII(chrome::kInitialProfile);
283 return default_profile_dir; 279 return default_profile_dir;
284 } 280 }
285 281
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 RegisterProfile(CreateProfileAsyncHelper(profile_path, this), false); 443 RegisterProfile(CreateProfileAsyncHelper(profile_path, this), false);
448 ProfileInfoCache& cache = GetProfileInfoCache(); 444 ProfileInfoCache& cache = GetProfileInfoCache();
449 // Get the icon index from the user's icon url 445 // Get the icon index from the user's icon url
450 size_t icon_index; 446 size_t icon_index;
451 std::string icon_url_std = UTF16ToASCII(icon_url); 447 std::string icon_url_std = UTF16ToASCII(icon_url);
452 if (cache.IsDefaultAvatarIconUrl(icon_url_std, &icon_index)) { 448 if (cache.IsDefaultAvatarIconUrl(icon_url_std, &icon_index)) {
453 // add profile to cache with user selected name and avatar 449 // add profile to cache with user selected name and avatar
454 cache.AddProfileToCache(profile_path, name, string16(), icon_index); 450 cache.AddProfileToCache(profile_path, name, string16(), icon_index);
455 } 451 }
456 info->callbacks.push_back(callback); 452 info->callbacks.push_back(callback);
453 if (profile_shortcut_manager_ && !name.empty() &&
454 !icon_url.empty()) {
455 BrowserThread::PostTask(
456 BrowserThread::FILE, FROM_HERE,
457 base::Bind(&ProfileShortcutManager::CreateChromeDesktopShortcut,
458 base::Unretained(profile_shortcut_manager_), profile_path, name,
459 ResourceBundle::GetSharedInstance().GetNativeImageNamed(
460 cache.GetDefaultAvatarIconResourceIDAtIndex(icon_index))));
461 }
457 } 462 }
458 } 463 }
459 464
460 // static 465 // static
461 void ProfileManager::CreateDefaultProfileAsync(const CreateCallback& callback) { 466 void ProfileManager::CreateDefaultProfileAsync(const CreateCallback& callback) {
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
463 ProfileManager* profile_manager = g_browser_process->profile_manager(); 468 ProfileManager* profile_manager = g_browser_process->profile_manager();
464 469
465 FilePath default_profile_dir = profile_manager->user_data_dir_; 470 FilePath default_profile_dir = profile_manager->user_data_dir_;
466 // TODO(mirandac): current directory will not always be default in the future 471 // TODO(mirandac): current directory will not always be default in the future
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 last_active->GetPath().BaseName().MaybeAsASCII()); 671 last_active->GetPath().BaseName().MaybeAsASCII());
667 } 672 }
668 } 673 }
669 #endif // !defined(OS_ANDROID) 674 #endif // !defined(OS_ANDROID)
670 675
671 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { 676 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) {
672 DoFinalInitForServices(profile, go_off_the_record); 677 DoFinalInitForServices(profile, go_off_the_record);
673 InitProfileUserPrefs(profile); 678 InitProfileUserPrefs(profile);
674 AddProfileToCache(profile); 679 AddProfileToCache(profile);
675 DoFinalInitLogging(profile); 680 DoFinalInitLogging(profile);
676 #if defined(OS_WIN) 681 profile_shortcut_manager_ = NULL;
sail 2012/08/13 22:09:36 this should be in the constructor's initializer li
Halli 2012/08/14 18:25:57 Done.
677 CreateDesktopShortcut(profile); 682 if (ProfileShortcutManager::IsFeatureEnabled()) {
sail 2012/08/13 22:09:36 don't need braces also, this probably belongs in t
Halli 2012/08/14 18:25:57 Done.
678 #endif 683 profile_shortcut_manager_ = ProfileShortcutManager::Create();
684 }
679 685
680 ProfileMetrics::LogNumberOfProfiles(this, ProfileMetrics::ADD_PROFILE_EVENT); 686 ProfileMetrics::LogNumberOfProfiles(this, ProfileMetrics::ADD_PROFILE_EVENT);
681 content::NotificationService::current()->Notify( 687 content::NotificationService::current()->Notify(
682 chrome::NOTIFICATION_PROFILE_ADDED, 688 chrome::NOTIFICATION_PROFILE_ADDED,
683 content::Source<Profile>(profile), 689 content::Source<Profile>(profile),
684 content::NotificationService::NoDetails()); 690 content::NotificationService::NoDetails());
685 691
686 } 692 }
687 693
688 void ProfileManager::DoFinalInitForServices(Profile* profile, 694 void ProfileManager::DoFinalInitForServices(Profile* profile,
(...skipping 29 matching lines...) Expand all
718 return Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); 724 return Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
719 } 725 }
720 726
721 Profile* ProfileManager::CreateProfileAsyncHelper(const FilePath& path, 727 Profile* ProfileManager::CreateProfileAsyncHelper(const FilePath& path,
722 Delegate* delegate) { 728 Delegate* delegate) {
723 return Profile::CreateProfile(path, 729 return Profile::CreateProfile(path,
724 delegate, 730 delegate,
725 Profile::CREATE_MODE_ASYNCHRONOUS); 731 Profile::CREATE_MODE_ASYNCHRONOUS);
726 } 732 }
727 733
728 #if defined(OS_WIN)
729 ProfileShortcutManagerWin* ProfileManager::CreateShortcutManager() {
730 return new ProfileShortcutManagerWin();
731 }
732 #endif
733
734 void ProfileManager::OnProfileCreated(Profile* profile, 734 void ProfileManager::OnProfileCreated(Profile* profile,
735 bool success, 735 bool success,
736 bool is_new_profile) { 736 bool is_new_profile) {
737 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 737 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
738 738
739 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath()); 739 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath());
740 DCHECK(iter != profiles_info_.end()); 740 DCHECK(iter != profiles_info_.end());
741 ProfileInfo* info = iter->second.get(); 741 ProfileInfo* info = iter->second.get();
742 742
743 std::vector<CreateCallback> callbacks; 743 std::vector<CreateCallback> callbacks;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 return false; 824 return false;
825 } else { 825 } else {
826 return pair1.first < pair2.first; 826 return pair1.first < pair2.first;
827 } 827 }
828 } 828 }
829 829
830 ProfileInfoCache& ProfileManager::GetProfileInfoCache() { 830 ProfileInfoCache& ProfileManager::GetProfileInfoCache() {
831 if (!profile_info_cache_.get()) { 831 if (!profile_info_cache_.get()) {
832 profile_info_cache_.reset(new ProfileInfoCache( 832 profile_info_cache_.reset(new ProfileInfoCache(
833 g_browser_process->local_state(), user_data_dir_)); 833 g_browser_process->local_state(), user_data_dir_));
834 #if defined(OS_WIN)
835 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
836 ProfileShortcutManagerWin* shortcut_manager = CreateShortcutManager();
837 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
838 if (dist && dist->CanCreateDesktopShortcuts() && shortcut_manager &&
839 !command_line.HasSwitch(switches::kDisableDesktopShortcuts)) {
840 profile_shortcut_manager_.reset(shortcut_manager);
841 profile_info_cache_->AddObserver(profile_shortcut_manager_.get());
842 }
843 #endif
844 } 834 }
845 return *profile_info_cache_.get(); 835 return *profile_info_cache_.get();
846 } 836 }
847 837
848 void ProfileManager::AddProfileToCache(Profile* profile) { 838 void ProfileManager::AddProfileToCache(Profile* profile) {
849 ProfileInfoCache& cache = GetProfileInfoCache(); 839 ProfileInfoCache& cache = GetProfileInfoCache();
850 if (profile->GetPath().DirName() != cache.GetUserDataDir()) 840 if (profile->GetPath().DirName() != cache.GetUserDataDir())
851 return; 841 return;
852 842
853 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) 843 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos)
854 return; 844 return;
855 845
856 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString( 846 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString(
857 prefs::kGoogleServicesUsername)); 847 prefs::kGoogleServicesUsername));
858 848
859 // Profile name and avatar are set by InitProfileUserPrefs and stored in the 849 // Profile name and avatar are set by InitProfileUserPrefs and stored in the
860 // profile. Use those values to setup the cache entry. 850 // profile. Use those values to setup the cache entry.
861 string16 profile_name = UTF8ToUTF16(profile->GetPrefs()->GetString( 851 string16 profile_name = UTF8ToUTF16(profile->GetPrefs()->GetString(
862 prefs::kProfileName)); 852 prefs::kProfileName));
863 853
864 size_t icon_index = profile->GetPrefs()->GetInteger( 854 size_t icon_index = profile->GetPrefs()->GetInteger(
865 prefs::kProfileAvatarIndex); 855 prefs::kProfileAvatarIndex);
866 856
867 cache.AddProfileToCache(profile->GetPath(), 857 cache.AddProfileToCache(profile->GetPath(),
868 profile_name, 858 profile_name,
869 username, 859 username,
870 icon_index); 860 icon_index);
871 } 861 }
872 862
873 #if defined(OS_WIN)
874 void ProfileManager::CreateDesktopShortcut(Profile* profile) {
875 // TODO(sail): Disable creating new shortcuts for now.
876 return;
877
878 // Some distributions and tests cannot create desktop shortcuts, in which case
879 // profile_shortcut_manager_ will not be set.
880 if (!profile_shortcut_manager_.get())
881 return;
882
883 bool shortcut_created =
884 profile->GetPrefs()->GetBoolean(prefs::kProfileShortcutCreated);
885 if (!shortcut_created && GetNumberOfProfiles() > 1) {
886 profile_shortcut_manager_->AddProfileShortcut(profile->GetPath());
887
888 // We only ever create the shortcut for a profile once, so set a pref
889 // reminding us to skip this in the future.
890 profile->GetPrefs()->SetBoolean(prefs::kProfileShortcutCreated, true);
891 }
892 }
893 #endif
894
895 void ProfileManager::InitProfileUserPrefs(Profile* profile) { 863 void ProfileManager::InitProfileUserPrefs(Profile* profile) {
896 ProfileInfoCache& cache = GetProfileInfoCache(); 864 ProfileInfoCache& cache = GetProfileInfoCache();
897 865
898 if (profile->GetPath().DirName() != cache.GetUserDataDir()) 866 if (profile->GetPath().DirName() != cache.GetUserDataDir())
899 return; 867 return;
900 868
901 // Initialize the user preferences (name and avatar) only if the profile 869 // Initialize the user preferences (name and avatar) only if the profile
902 // doesn't have default preferenc values for them. 870 // doesn't have default preferenc values for them.
903 if (HasAnyDefaultUserPrefs(profile)) { 871 if (HasAnyDefaultUserPrefs(profile)) {
904 size_t profile_cache_index = 872 size_t profile_cache_index =
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( 943 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(
976 profile)) { 944 profile)) {
977 ProfileSyncServiceFactory::GetInstance()->GetForProfile( 945 ProfileSyncServiceFactory::GetInstance()->GetForProfile(
978 profile)->DisableForUser(); 946 profile)->DisableForUser();
979 } 947 }
980 } 948 }
981 949
982 QueueProfileDirectoryForDeletion(profile_dir); 950 QueueProfileDirectoryForDeletion(profile_dir);
983 cache.DeleteProfileFromCache(profile_dir); 951 cache.DeleteProfileFromCache(profile_dir);
984 952
953 // Delete possible shortcuts for this profile
954 if (profile_shortcut_manager_)
955 profile_shortcut_manager_->DeleteChromeDesktopShortcut(profile_dir);
956
985 ProfileMetrics::LogNumberOfProfiles(this, 957 ProfileMetrics::LogNumberOfProfiles(this,
986 ProfileMetrics::DELETE_PROFILE_EVENT); 958 ProfileMetrics::DELETE_PROFILE_EVENT);
987 } 959 }
988 960
989 // static 961 // static
990 bool ProfileManager::IsMultipleProfilesEnabled() { 962 bool ProfileManager::IsMultipleProfilesEnabled() {
991 #if defined(OS_CHROMEOS) 963 #if defined(OS_CHROMEOS)
992 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) 964 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles))
993 return false; 965 return false;
994 #endif 966 #endif
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, 1002 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks,
1031 Profile* profile, 1003 Profile* profile,
1032 Profile::CreateStatus status) { 1004 Profile::CreateStatus status) {
1033 for (size_t i = 0; i < callbacks.size(); ++i) 1005 for (size_t i = 0; i < callbacks.size(); ++i)
1034 callbacks[i].Run(profile, status); 1006 callbacks[i].Run(profile, status);
1035 } 1007 }
1036 1008
1037 ProfileManager::ProfileInfo::~ProfileInfo() { 1009 ProfileManager::ProfileInfo::~ProfileInfo() {
1038 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); 1010 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release());
1039 } 1011 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698