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

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

Issue 1686833003: Remove HostDesktopType from profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@metro-mode-16
Patch Set: desktop linux and mac 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 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 Profile* profile_; 112 Profile* profile_;
113 ProfileManager::CreateCallback callback_; 113 ProfileManager::CreateCallback callback_;
114 114
115 DISALLOW_COPY_AND_ASSIGN(BrowserAddedForProfileObserver); 115 DISALLOW_COPY_AND_ASSIGN(BrowserAddedForProfileObserver);
116 }; 116 };
117 117
118 void OpenBrowserWindowForProfile( 118 void OpenBrowserWindowForProfile(
119 ProfileManager::CreateCallback callback, 119 ProfileManager::CreateCallback callback,
120 bool always_create, 120 bool always_create,
121 bool is_new_profile, 121 bool is_new_profile,
122 chrome::HostDesktopType desktop_type,
123 Profile* profile, 122 Profile* profile,
124 Profile::CreateStatus status) { 123 Profile::CreateStatus status) {
125 DCHECK_CURRENTLY_ON(BrowserThread::UI); 124 DCHECK_CURRENTLY_ON(BrowserThread::UI);
126 125
127 if (status != Profile::CREATE_STATUS_INITIALIZED) 126 if (status != Profile::CREATE_STATUS_INITIALIZED)
128 return; 127 return;
129 128
130 chrome::startup::IsProcessStartup is_process_startup = 129 chrome::startup::IsProcessStartup is_process_startup =
131 chrome::startup::IS_NOT_PROCESS_STARTUP; 130 chrome::startup::IS_NOT_PROCESS_STARTUP;
132 chrome::startup::IsFirstRun is_first_run = chrome::startup::IS_NOT_FIRST_RUN; 131 chrome::startup::IsFirstRun is_first_run = chrome::startup::IS_NOT_FIRST_RUN;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // up calling LaunchBrowser and opens a new window. If for whatever reason 171 // up calling LaunchBrowser and opens a new window. If for whatever reason
173 // that fails, either something has crashed, or the observer will be cleaned 172 // that fails, either something has crashed, or the observer will be cleaned
174 // up when a different browser for this profile is opened. 173 // up when a different browser for this profile is opened.
175 if (!callback.is_null()) 174 if (!callback.is_null())
176 new BrowserAddedForProfileObserver(profile, callback); 175 new BrowserAddedForProfileObserver(profile, callback);
177 176
178 // We already dealt with the case when |always_create| was false and a browser 177 // We already dealt with the case when |always_create| was false and a browser
179 // existed, which means that here a browser definitely needs to be created. 178 // existed, which means that here a browser definitely needs to be created.
180 // Passing true for |always_create| means we won't duplicate the code that 179 // Passing true for |always_create| means we won't duplicate the code that
181 // tries to find a browser. 180 // tries to find a browser.
182 profiles::FindOrCreateNewWindowForProfile( 181 profiles::FindOrCreateNewWindowForProfile(profile, is_process_startup,
183 profile, 182 is_first_run, true);
184 is_process_startup,
185 is_first_run,
186 desktop_type,
187 true);
188 } 183 }
189 184
190 // Called after a |system_profile| is available to be used by the user manager. 185 // Called after a |system_profile| is available to be used by the user manager.
191 // Based on the value of |tutorial_mode| we determine a url to be displayed 186 // Based on the value of |tutorial_mode| we determine a url to be displayed
192 // by the webui and run the |callback|, if it exists. After opening a profile, 187 // by the webui and run the |callback|, if it exists. After opening a profile,
193 // perform |profile_open_action|. 188 // perform |profile_open_action|.
194 void OnUserManagerSystemProfileCreated( 189 void OnUserManagerSystemProfileCreated(
195 const base::FilePath& profile_path_to_focus, 190 const base::FilePath& profile_path_to_focus,
196 profiles::UserManagerTutorialMode tutorial_mode, 191 profiles::UserManagerTutorialMode tutorial_mode,
197 profiles::UserManagerProfileSelected profile_open_action, 192 profiles::UserManagerProfileSelected profile_open_action,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (entry->GetUserName() == profile_email) 258 if (entry->GetUserName() == profile_email)
264 return entry->GetPath(); 259 return entry->GetPath();
265 } 260 }
266 return base::FilePath(); 261 return base::FilePath();
267 } 262 }
268 263
269 void FindOrCreateNewWindowForProfile( 264 void FindOrCreateNewWindowForProfile(
270 Profile* profile, 265 Profile* profile,
271 chrome::startup::IsProcessStartup process_startup, 266 chrome::startup::IsProcessStartup process_startup,
272 chrome::startup::IsFirstRun is_first_run, 267 chrome::startup::IsFirstRun is_first_run,
273 chrome::HostDesktopType desktop_type,
274 bool always_create) { 268 bool always_create) {
275 DCHECK(profile); 269 DCHECK(profile);
276 270
277 if (!always_create) { 271 if (!always_create) {
278 Browser* browser = chrome::FindTabbedBrowser(profile, false); 272 Browser* browser = chrome::FindTabbedBrowser(profile, false);
279 if (browser) { 273 if (browser) {
280 browser->window()->Activate(); 274 browser->window()->Activate();
281 return; 275 return;
282 } 276 }
283 } 277 }
284 278
285 content::RecordAction(UserMetricsAction("NewWindow")); 279 content::RecordAction(UserMetricsAction("NewWindow"));
286 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 280 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
287 StartupBrowserCreator browser_creator; 281 StartupBrowserCreator browser_creator;
288 browser_creator.LaunchBrowser( 282 browser_creator.LaunchBrowser(
289 command_line, profile, base::FilePath(), process_startup, is_first_run); 283 command_line, profile, base::FilePath(), process_startup, is_first_run);
290 } 284 }
291 285
292 #if !defined(OS_ANDROID) 286 #if !defined(OS_ANDROID)
293 void SwitchToProfile(const base::FilePath& path, 287 void SwitchToProfile(const base::FilePath& path,
294 chrome::HostDesktopType desktop_type,
295 bool always_create, 288 bool always_create,
296 ProfileManager::CreateCallback callback, 289 ProfileManager::CreateCallback callback,
297 ProfileMetrics::ProfileOpen metric) { 290 ProfileMetrics::ProfileOpen metric) {
298 ProfileMetrics::LogProfileSwitch(metric, 291 ProfileMetrics::LogProfileSwitch(metric,
299 g_browser_process->profile_manager(), 292 g_browser_process->profile_manager(),
300 path); 293 path);
301 g_browser_process->profile_manager()->CreateProfileAsync( 294 g_browser_process->profile_manager()->CreateProfileAsync(
302 path, 295 path,
303 base::Bind(&OpenBrowserWindowForProfile, 296 base::Bind(&OpenBrowserWindowForProfile, callback, always_create, false),
304 callback, 297 base::string16(), std::string(), std::string());
305 always_create,
306 false,
307 desktop_type),
308 base::string16(),
309 std::string(),
310 std::string());
311 } 298 }
312 299
313 void SwitchToGuestProfile(chrome::HostDesktopType desktop_type, 300 void SwitchToGuestProfile(ProfileManager::CreateCallback callback) {
314 ProfileManager::CreateCallback callback) {
315 const base::FilePath& path = ProfileManager::GetGuestProfilePath(); 301 const base::FilePath& path = ProfileManager::GetGuestProfilePath();
316 ProfileMetrics::LogProfileSwitch(ProfileMetrics::SWITCH_PROFILE_GUEST, 302 ProfileMetrics::LogProfileSwitch(ProfileMetrics::SWITCH_PROFILE_GUEST,
317 g_browser_process->profile_manager(), 303 g_browser_process->profile_manager(),
318 path); 304 path);
319 g_browser_process->profile_manager()->CreateProfileAsync( 305 g_browser_process->profile_manager()->CreateProfileAsync(
320 path, 306 path, base::Bind(&OpenBrowserWindowForProfile, callback, false, false),
321 base::Bind(&OpenBrowserWindowForProfile, 307 base::string16(), std::string(), std::string());
322 callback,
323 false,
324 false,
325 desktop_type),
326 base::string16(),
327 std::string(),
328 std::string());
329 } 308 }
330 #endif 309 #endif
331 310
332 bool HasProfileSwitchTargets(Profile* profile) { 311 bool HasProfileSwitchTargets(Profile* profile) {
333 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; 312 size_t min_profiles = profile->IsGuestSession() ? 1 : 2;
334 size_t number_of_profiles = 313 size_t number_of_profiles =
335 g_browser_process->profile_manager()->GetNumberOfProfiles(); 314 g_browser_process->profile_manager()->GetNumberOfProfiles();
336 return number_of_profiles >= min_profiles; 315 return number_of_profiles >= min_profiles;
337 } 316 }
338 317
339 void CreateAndSwitchToNewProfile(chrome::HostDesktopType desktop_type, 318 void CreateAndSwitchToNewProfile(ProfileManager::CreateCallback callback,
340 ProfileManager::CreateCallback callback,
341 ProfileMetrics::ProfileAdd metric) { 319 ProfileMetrics::ProfileAdd metric) {
342 ProfileInfoCache& cache = 320 ProfileInfoCache& cache =
343 g_browser_process->profile_manager()->GetProfileInfoCache(); 321 g_browser_process->profile_manager()->GetProfileInfoCache();
344 322
345 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); 323 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex();
346 ProfileManager::CreateMultiProfileAsync( 324 ProfileManager::CreateMultiProfileAsync(
347 cache.ChooseNameForNewProfile(placeholder_avatar_index), 325 cache.ChooseNameForNewProfile(placeholder_avatar_index),
348 profiles::GetDefaultAvatarIconUrl(placeholder_avatar_index), 326 profiles::GetDefaultAvatarIconUrl(placeholder_avatar_index),
349 base::Bind(&OpenBrowserWindowForProfile, 327 base::Bind(&OpenBrowserWindowForProfile, callback, true, true),
350 callback,
351 true,
352 true,
353 desktop_type),
354 std::string()); 328 std::string());
355 ProfileMetrics::LogProfileAddNewUser(metric); 329 ProfileMetrics::LogProfileAddNewUser(metric);
356 } 330 }
357 331
358 void GuestBrowserCloseSuccess(const base::FilePath& profile_path) { 332 void GuestBrowserCloseSuccess(const base::FilePath& profile_path) {
359 UserManager::Show(base::FilePath(), 333 UserManager::Show(base::FilePath(),
360 profiles::USER_MANAGER_NO_TUTORIAL, 334 profiles::USER_MANAGER_NO_TUTORIAL,
361 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 335 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
362 } 336 }
363 337
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 PrefService* local_state = g_browser_process->local_state(); 533 PrefService* local_state = g_browser_process->local_state();
560 const bool dismissed = local_state->GetBoolean( 534 const bool dismissed = local_state->GetBoolean(
561 prefs::kProfileAvatarRightClickTutorialDismissed); 535 prefs::kProfileAvatarRightClickTutorialDismissed);
562 536
563 // Don't show the tutorial if it's already been dismissed or if right-clicking 537 // Don't show the tutorial if it's already been dismissed or if right-clicking
564 // wouldn't show any targets. 538 // wouldn't show any targets.
565 return !dismissed && HasProfileSwitchTargets(profile); 539 return !dismissed && HasProfileSwitchTargets(profile);
566 } 540 }
567 541
568 } // namespace profiles 542 } // namespace profiles
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_window.h ('k') | chrome/browser/profiles/profile_window_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698