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

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

Issue 564453003: Access to Chrome via the System Tray should go through the User Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Estade comments Created 6 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/profiles/profile_window.h" 5 #include "chrome/browser/profiles/profile_window.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 const char kNewProfileManagementExperimentInternalName[] = 44 const char kNewProfileManagementExperimentInternalName[] =
45 "enable-new-profile-management"; 45 "enable-new-profile-management";
46 46
47 // Handles running a callback when a new Browser for the given profile 47 // Handles running a callback when a new Browser for the given profile
48 // has been completely created. 48 // has been completely created.
49 class BrowserAddedForProfileObserver : public chrome::BrowserListObserver { 49 class BrowserAddedForProfileObserver : public chrome::BrowserListObserver {
50 public: 50 public:
51 BrowserAddedForProfileObserver( 51 BrowserAddedForProfileObserver(
52 Profile* profile, 52 Profile* profile,
53 profiles::ProfileSwitchingDoneCallback callback) 53 ProfileManager::CreateCallback callback)
54 : profile_(profile), 54 : profile_(profile),
55 callback_(callback) { 55 callback_(callback) {
56 DCHECK(!callback_.is_null()); 56 DCHECK(!callback_.is_null());
57 BrowserList::AddObserver(this); 57 BrowserList::AddObserver(this);
58 } 58 }
59 virtual ~BrowserAddedForProfileObserver() { 59 virtual ~BrowserAddedForProfileObserver() {
60 } 60 }
61 61
62 private: 62 private:
63 // Overridden from BrowserListObserver: 63 // Overridden from BrowserListObserver:
64 virtual void OnBrowserAdded(Browser* browser) OVERRIDE { 64 virtual void OnBrowserAdded(Browser* browser) OVERRIDE {
65 if (browser->profile() == profile_) { 65 if (browser->profile() == profile_) {
66 BrowserList::RemoveObserver(this); 66 BrowserList::RemoveObserver(this);
67 callback_.Run(); 67 callback_.Run(profile_, Profile::CREATE_STATUS_ALREADY_CREATED);
68 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 68 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
69 } 69 }
70 } 70 }
71 71
72 // Profile for which the browser should be opened. 72 // Profile for which the browser should be opened.
73 Profile* profile_; 73 Profile* profile_;
74 profiles::ProfileSwitchingDoneCallback callback_; 74 ProfileManager::CreateCallback callback_;
75 75
76 DISALLOW_COPY_AND_ASSIGN(BrowserAddedForProfileObserver); 76 DISALLOW_COPY_AND_ASSIGN(BrowserAddedForProfileObserver);
77 }; 77 };
78 78
79 void OpenBrowserWindowForProfile( 79 void OpenBrowserWindowForProfile(
80 profiles::ProfileSwitchingDoneCallback callback, 80 ProfileManager::CreateCallback callback,
81 bool always_create, 81 bool always_create,
82 bool is_new_profile, 82 bool is_new_profile,
83 chrome::HostDesktopType desktop_type, 83 chrome::HostDesktopType desktop_type,
84 Profile* profile, 84 Profile* profile,
85 Profile::CreateStatus status) { 85 Profile::CreateStatus status) {
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
87 87
88 if (status != Profile::CREATE_STATUS_INITIALIZED) 88 if (status != Profile::CREATE_STATUS_INITIALIZED)
89 return; 89 return;
90 90
(...skipping 10 matching lines...) Expand all
101 // If |always_create| is false, and we have a |callback| to run, check 101 // If |always_create| is false, and we have a |callback| to run, check
102 // whether a browser already exists so that we can run the callback. We don't 102 // whether a browser already exists so that we can run the callback. We don't
103 // want to rely on the observer listening to OnBrowserSetLastActive in this 103 // want to rely on the observer listening to OnBrowserSetLastActive in this
104 // case, as you could manually activate an incorrect browser and trigger 104 // case, as you could manually activate an incorrect browser and trigger
105 // a false positive. 105 // a false positive.
106 if (!always_create) { 106 if (!always_create) {
107 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); 107 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type);
108 if (browser) { 108 if (browser) {
109 browser->window()->Activate(); 109 browser->window()->Activate();
110 if (!callback.is_null()) 110 if (!callback.is_null())
111 callback.Run(); 111 callback.Run(profile, Profile::CREATE_STATUS_ALREADY_CREATED);
112 return; 112 return;
113 } 113 }
114 } 114 }
115 115
116 // If there is a callback, create an observer to make sure it is only 116 // If there is a callback, create an observer to make sure it is only
117 // run when the browser has been completely created. This observer will 117 // run when the browser has been completely created. This observer will
118 // delete itself once that happens. This should not leak, because we are 118 // delete itself once that happens. This should not leak, because we are
119 // passing |always_create| = true to FindOrCreateNewWindow below, which ends 119 // passing |always_create| = true to FindOrCreateNewWindow below, which ends
120 // up calling LaunchBrowser and opens a new window. If for whatever reason 120 // up calling LaunchBrowser and opens a new window. If for whatever reason
121 // that fails, either something has crashed, or the observer will be cleaned 121 // that fails, either something has crashed, or the observer will be cleaned
122 // up when a different browser for this profile is opened. 122 // up when a different browser for this profile is opened.
123 if (!callback.is_null()) 123 if (!callback.is_null())
124 new BrowserAddedForProfileObserver(profile, callback); 124 new BrowserAddedForProfileObserver(profile, callback);
125 125
126 // We already dealt with the case when |always_create| was false and a browser 126 // We already dealt with the case when |always_create| was false and a browser
127 // existed, which means that here a browser definitely needs to be created. 127 // existed, which means that here a browser definitely needs to be created.
128 // Passing true for |always_create| means we won't duplicate the code that 128 // Passing true for |always_create| means we won't duplicate the code that
129 // tries to find a browser. 129 // tries to find a browser.
130 profiles::FindOrCreateNewWindowForProfile( 130 profiles::FindOrCreateNewWindowForProfile(
131 profile, 131 profile,
132 is_process_startup, 132 is_process_startup,
133 is_first_run, 133 is_first_run,
134 desktop_type, 134 desktop_type,
135 true); 135 true);
136 } 136 }
137 137
138 // Called after a |guest_profile| is available to be used by the user manager. 138 // Called after a |guest_profile| is available to be used by the user manager.
139 // Based on the value of |tutorial_mode| we determine a url to be displayed 139 // Based on the value of |tutorial_mode| we determine a url to be displayed
140 // by the webui and run the |callback|, if it exists. 140 // by the webui and run the |callback|, if it exists. After opening a profile,
141 // perform |profile_open_action|.
141 void OnUserManagerGuestProfileCreated( 142 void OnUserManagerGuestProfileCreated(
142 const base::FilePath& profile_path_to_focus, 143 const base::FilePath& profile_path_to_focus,
143 profiles::UserManagerTutorialMode tutorial_mode, 144 profiles::UserManagerTutorialMode tutorial_mode,
145 profiles::UserManagerProfileSelected profile_open_action,
144 const base::Callback<void(Profile*, const std::string&)>& callback, 146 const base::Callback<void(Profile*, const std::string&)>& callback,
145 Profile* guest_profile, 147 Profile* guest_profile,
146 Profile::CreateStatus status) { 148 Profile::CreateStatus status) {
147 if (status != Profile::CREATE_STATUS_INITIALIZED || callback.is_null()) 149 if (status != Profile::CREATE_STATUS_INITIALIZED || callback.is_null())
148 return; 150 return;
149 151
150 // Tell the webui which user should be focused. 152 // Tell the webui which user should be focused.
151 std::string page = chrome::kChromeUIUserManagerURL; 153 std::string page = chrome::kChromeUIUserManagerURL;
152 154
153 if (tutorial_mode == profiles::USER_MANAGER_TUTORIAL_OVERVIEW) { 155 if (tutorial_mode == profiles::USER_MANAGER_TUTORIAL_OVERVIEW) {
154 page += "#tutorial"; 156 page += "#tutorial";
noms (inactive) 2014/09/11 19:05:41 nit: maybe make this into a constant next to the o
Mike Lerman 2014/09/11 20:51:51 Sure.
155 } else if (!profile_path_to_focus.empty()) { 157 } else if (!profile_path_to_focus.empty()) {
156 const ProfileInfoCache& cache = 158 const ProfileInfoCache& cache =
157 g_browser_process->profile_manager()->GetProfileInfoCache(); 159 g_browser_process->profile_manager()->GetProfileInfoCache();
158 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus); 160 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus);
159 if (index != std::string::npos) { 161 if (index != std::string::npos) {
160 page += "#"; 162 page += "#";
161 page += base::IntToString(index); 163 page += base::IntToString(index);
162 } 164 }
165 } else if (profile_open_action ==
166 profiles::USER_MANAGER_SELECT_PROFILE_TASK_MANAGER) {
167 page += profiles::kUserManagerSelectProfileTaskManager;
168 } else if (profile_open_action ==
169 profiles::USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME) {
170 page += profiles::kUserManagerSelectProfileAboutChrome;
163 } 171 }
164
165 callback.Run(guest_profile, page); 172 callback.Run(guest_profile, page);
166 } 173 }
167 174
168 // Updates Chrome services that require notification when 175 // Updates Chrome services that require notification when
169 // the new_profile_management's status changes. 176 // the new_profile_management's status changes.
170 void UpdateServicesWithNewProfileManagementFlag(Profile* profile, 177 void UpdateServicesWithNewProfileManagementFlag(Profile* profile,
171 bool new_flag_status) { 178 bool new_flag_status) {
172 AccountReconcilor* account_reconcilor = 179 AccountReconcilor* account_reconcilor =
173 AccountReconcilorFactory::GetForProfile(profile); 180 AccountReconcilorFactory::GetForProfile(profile);
174 account_reconcilor->OnNewProfileManagementFlagChanged(new_flag_status); 181 account_reconcilor->OnNewProfileManagementFlagChanged(new_flag_status);
175 } 182 }
176 183
177 } // namespace 184 } // namespace
178 185
179 namespace profiles { 186 namespace profiles {
180 187
188 // User Manager parameters are prefixed with hash.
189 const char kUserManagerSelectProfileTaskManager[] = "#task-manager";
190 const char kUserManagerSelectProfileAboutChrome[] = "#about-chrome";
191
181 void FindOrCreateNewWindowForProfile( 192 void FindOrCreateNewWindowForProfile(
182 Profile* profile, 193 Profile* profile,
183 chrome::startup::IsProcessStartup process_startup, 194 chrome::startup::IsProcessStartup process_startup,
184 chrome::startup::IsFirstRun is_first_run, 195 chrome::startup::IsFirstRun is_first_run,
185 chrome::HostDesktopType desktop_type, 196 chrome::HostDesktopType desktop_type,
186 bool always_create) { 197 bool always_create) {
187 #if defined(OS_IOS) 198 #if defined(OS_IOS)
188 NOTREACHED(); 199 NOTREACHED();
189 #else 200 #else
190 DCHECK(profile); 201 DCHECK(profile);
(...skipping 11 matching lines...) Expand all
202 int return_code; 213 int return_code;
203 StartupBrowserCreator browser_creator; 214 StartupBrowserCreator browser_creator;
204 browser_creator.LaunchBrowser(command_line, profile, base::FilePath(), 215 browser_creator.LaunchBrowser(command_line, profile, base::FilePath(),
205 process_startup, is_first_run, &return_code); 216 process_startup, is_first_run, &return_code);
206 #endif // defined(OS_IOS) 217 #endif // defined(OS_IOS)
207 } 218 }
208 219
209 void SwitchToProfile(const base::FilePath& path, 220 void SwitchToProfile(const base::FilePath& path,
210 chrome::HostDesktopType desktop_type, 221 chrome::HostDesktopType desktop_type,
211 bool always_create, 222 bool always_create,
212 ProfileSwitchingDoneCallback callback, 223 ProfileManager::CreateCallback callback,
213 ProfileMetrics::ProfileOpen metric) { 224 ProfileMetrics::ProfileOpen metric) {
214 g_browser_process->profile_manager()->CreateProfileAsync( 225 g_browser_process->profile_manager()->CreateProfileAsync(
215 path, 226 path,
216 base::Bind(&OpenBrowserWindowForProfile, 227 base::Bind(&OpenBrowserWindowForProfile,
217 callback, 228 callback,
218 always_create, 229 always_create,
219 false, 230 false,
220 desktop_type), 231 desktop_type),
221 base::string16(), 232 base::string16(),
222 base::string16(), 233 base::string16(),
223 std::string()); 234 std::string());
224 ProfileMetrics::LogProfileSwitchUser(metric); 235 ProfileMetrics::LogProfileSwitchUser(metric);
225 } 236 }
226 237
227 void SwitchToGuestProfile(chrome::HostDesktopType desktop_type, 238 void SwitchToGuestProfile(chrome::HostDesktopType desktop_type,
228 ProfileSwitchingDoneCallback callback) { 239 ProfileManager::CreateCallback callback) {
229 g_browser_process->profile_manager()->CreateProfileAsync( 240 g_browser_process->profile_manager()->CreateProfileAsync(
230 ProfileManager::GetGuestProfilePath(), 241 ProfileManager::GetGuestProfilePath(),
231 base::Bind(&OpenBrowserWindowForProfile, 242 base::Bind(&OpenBrowserWindowForProfile,
232 callback, 243 callback,
233 false, 244 false,
234 false, 245 false,
235 desktop_type), 246 desktop_type),
236 base::string16(), 247 base::string16(),
237 base::string16(), 248 base::string16(),
238 std::string()); 249 std::string());
239 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); 250 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST);
240 } 251 }
241 252
242 void CreateAndSwitchToNewProfile(chrome::HostDesktopType desktop_type, 253 void CreateAndSwitchToNewProfile(chrome::HostDesktopType desktop_type,
243 ProfileSwitchingDoneCallback callback, 254 ProfileManager::CreateCallback callback,
244 ProfileMetrics::ProfileAdd metric) { 255 ProfileMetrics::ProfileAdd metric) {
245 ProfileInfoCache& cache = 256 ProfileInfoCache& cache =
246 g_browser_process->profile_manager()->GetProfileInfoCache(); 257 g_browser_process->profile_manager()->GetProfileInfoCache();
247 258
248 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); 259 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex();
249 ProfileManager::CreateMultiProfileAsync( 260 ProfileManager::CreateMultiProfileAsync(
250 cache.ChooseNameForNewProfile(placeholder_avatar_index), 261 cache.ChooseNameForNewProfile(placeholder_avatar_index),
251 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl( 262 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(
252 placeholder_avatar_index)), 263 placeholder_avatar_index)),
253 base::Bind(&OpenBrowserWindowForProfile, 264 base::Bind(&OpenBrowserWindowForProfile,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 DCHECK(profile); 298 DCHECK(profile);
288 if (profile) { 299 if (profile) {
289 BrowserList::CloseAllBrowsersWithProfile( 300 BrowserList::CloseAllBrowsersWithProfile(
290 profile, base::Bind(&LockBrowserCloseSuccess)); 301 profile, base::Bind(&LockBrowserCloseSuccess));
291 } 302 }
292 } 303 }
293 304
294 void CreateGuestProfileForUserManager( 305 void CreateGuestProfileForUserManager(
295 const base::FilePath& profile_path_to_focus, 306 const base::FilePath& profile_path_to_focus,
296 profiles::UserManagerTutorialMode tutorial_mode, 307 profiles::UserManagerTutorialMode tutorial_mode,
308 profiles::UserManagerProfileSelected profile_open_action,
297 const base::Callback<void(Profile*, const std::string&)>& callback) { 309 const base::Callback<void(Profile*, const std::string&)>& callback) {
298 // Create the guest profile, if necessary, and open the User Manager 310 // Create the guest profile, if necessary, and open the User Manager
299 // from the guest profile. 311 // from the guest profile.
300 g_browser_process->profile_manager()->CreateProfileAsync( 312 g_browser_process->profile_manager()->CreateProfileAsync(
301 ProfileManager::GetGuestProfilePath(), 313 ProfileManager::GetGuestProfilePath(),
302 base::Bind(&OnUserManagerGuestProfileCreated, 314 base::Bind(&OnUserManagerGuestProfileCreated,
303 profile_path_to_focus, 315 profile_path_to_focus,
304 tutorial_mode, 316 tutorial_mode,
317 profile_open_action,
305 callback), 318 callback),
306 base::string16(), 319 base::string16(),
307 base::string16(), 320 base::string16(),
308 std::string()); 321 std::string());
309 } 322 }
310 323
311 void ShowUserManagerMaybeWithTutorial(Profile* profile) { 324 void ShowUserManagerMaybeWithTutorial(Profile* profile) {
312 // Guest users cannot appear in the User Manager, nor display a tutorial. 325 // Guest users cannot appear in the User Manager, nor display a tutorial.
313 if (!profile || profile->IsGuestSession()) { 326 if (!profile || profile->IsGuestSession()) {
314 chrome::ShowUserManager(base::FilePath()); 327 chrome::ShowUserManager(base::FilePath());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 case BrowserWindow::AVATAR_BUBBLE_MODE_SHOW_ERROR: 399 case BrowserWindow::AVATAR_BUBBLE_MODE_SHOW_ERROR:
387 *bubble_view_mode = BUBBLE_VIEW_MODE_PROFILE_CHOOSER; 400 *bubble_view_mode = BUBBLE_VIEW_MODE_PROFILE_CHOOSER;
388 *tutorial_mode = TUTORIAL_MODE_SHOW_ERROR; 401 *tutorial_mode = TUTORIAL_MODE_SHOW_ERROR;
389 return; 402 return;
390 default: 403 default:
391 *bubble_view_mode = profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER; 404 *bubble_view_mode = profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER;
392 } 405 }
393 } 406 }
394 407
395 } // namespace profiles 408 } // namespace profiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698