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

Side by Side Diff: chrome/browser/ui/browser_init.cc

Issue 7520023: Converted IncognitoForced boolean policy into IncognitoModeAvailability enum policy. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Converted incognito pref functions to a class. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/browser_init.h" 5 #include "chrome/browser/ui/browser_init.h"
6 6
7 #include <algorithm> // For max(). 7 #include <algorithm> // For max().
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/defaults.h" 25 #include "chrome/browser/defaults.h"
26 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 26 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
27 #include "chrome/browser/extensions/extension_creator.h" 27 #include "chrome/browser/extensions/extension_creator.h"
28 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/extensions/pack_extension_job.h" 29 #include "chrome/browser/extensions/pack_extension_job.h"
30 #include "chrome/browser/first_run/first_run.h" 30 #include "chrome/browser/first_run/first_run.h"
31 #include "chrome/browser/net/predictor_api.h" 31 #include "chrome/browser/net/predictor_api.h"
32 #include "chrome/browser/net/url_fixer_upper.h" 32 #include "chrome/browser/net/url_fixer_upper.h"
33 #include "chrome/browser/notifications/desktop_notification_service.h" 33 #include "chrome/browser/notifications/desktop_notification_service.h"
34 #include "chrome/browser/prefs/incognito_mode_prefs.h"
34 #include "chrome/browser/prefs/pref_service.h" 35 #include "chrome/browser/prefs/pref_service.h"
35 #include "chrome/browser/prefs/session_startup_pref.h" 36 #include "chrome/browser/prefs/session_startup_pref.h"
36 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 37 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
37 #include "chrome/browser/printing/print_dialog_cloud.h" 38 #include "chrome/browser/printing/print_dialog_cloud.h"
38 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
39 #include "chrome/browser/profiles/profile_io_data.h" 40 #include "chrome/browser/profiles/profile_io_data.h"
40 #include "chrome/browser/search_engines/template_url.h" 41 #include "chrome/browser/search_engines/template_url.h"
41 #include "chrome/browser/search_engines/template_url_service.h" 42 #include "chrome/browser/search_engines/template_url_service.h"
42 #include "chrome/browser/search_engines/template_url_service_factory.h" 43 #include "chrome/browser/search_engines/template_url_service_factory.h"
43 #include "chrome/browser/sessions/session_restore.h" 44 #include "chrome/browser/sessions/session_restore.h"
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 behavior = SessionRestore::CLOBBER_CURRENT_TAB; 353 behavior = SessionRestore::CLOBBER_CURRENT_TAB;
353 } 354 }
354 SessionRestore::RestoreSession( 355 SessionRestore::RestoreSession(
355 profile_, browser_, behavior, std::vector<GURL>()); 356 profile_, browser_, behavior, std::vector<GURL>());
356 return true; 357 return true;
357 } 358 }
358 359
359 360
360 // Utility functions ---------------------------------------------------------- 361 // Utility functions ----------------------------------------------------------
361 362
363 bool IncognitoIsForced(const CommandLine& command_line,
364 const PrefService* prefs) {
365 IncognitoModePrefs::Availability incognito_avail =
366 IncognitoModePrefs::GetAvailability(prefs);
367 return incognito_avail != IncognitoModePrefs::DISABLED &&
368 (command_line.HasSwitch(switches::kIncognito) ||
369 incognito_avail == IncognitoModePrefs::FORCED);
370 }
371
362 SessionStartupPref GetSessionStartupPref(const CommandLine& command_line, 372 SessionStartupPref GetSessionStartupPref(const CommandLine& command_line,
363 Profile* profile) { 373 Profile* profile) {
364 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); 374 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile);
365 if (command_line.HasSwitch(switches::kRestoreLastSession)) 375 if (command_line.HasSwitch(switches::kRestoreLastSession))
366 pref.type = SessionStartupPref::LAST; 376 pref.type = SessionStartupPref::LAST;
367 if ((command_line.HasSwitch(switches::kIncognito) || 377 if (pref.type == SessionStartupPref::LAST &&
368 profile->GetPrefs()->GetBoolean(prefs::kIncognitoForced)) && 378 IncognitoIsForced(command_line, profile->GetPrefs())) {
369 pref.type == SessionStartupPref::LAST &&
370 profile->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) {
371 // We don't store session information when incognito. If the user has 379 // We don't store session information when incognito. If the user has
372 // chosen to restore last session and launched incognito, fallback to 380 // chosen to restore last session and launched incognito, fallback to
373 // default launch behavior. 381 // default launch behavior.
374 pref.type = SessionStartupPref::DEFAULT; 382 pref.type = SessionStartupPref::DEFAULT;
375 } 383 }
376 return pref; 384 return pref;
377 } 385 }
378 386
379 enum LaunchMode { 387 enum LaunchMode {
380 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut. 388 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut.
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 if (process_startup) { 537 if (process_startup) {
530 // NetworkStateNotifier has to be initialized before Launching browser 538 // NetworkStateNotifier has to be initialized before Launching browser
531 // because the page load can happen in parallel to this UI thread 539 // because the page load can happen in parallel to this UI thread
532 // and IO thread may access the NetworkStateNotifier. 540 // and IO thread may access the NetworkStateNotifier.
533 chromeos::CrosLibrary::Get()->GetNetworkLibrary() 541 chromeos::CrosLibrary::Get()->GetNetworkLibrary()
534 ->AddNetworkManagerObserver( 542 ->AddNetworkManagerObserver(
535 chromeos::NetworkStateNotifier::GetInstance()); 543 chromeos::NetworkStateNotifier::GetInstance());
536 } 544 }
537 #endif 545 #endif
538 546
539 // Continue with the incognito profile from here on if --incognito 547 // Continue with the incognito profile from here on if Incognito mode
540 if ((command_line.HasSwitch(switches::kIncognito) || 548 // is forced.
541 profile->GetPrefs()->GetBoolean(prefs::kIncognitoForced)) && 549 if (IncognitoIsForced(command_line, profile->GetPrefs())) {
542 profile->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) {
543 profile = profile->GetOffTheRecordProfile(); 550 profile = profile->GetOffTheRecordProfile();
544 } 551 }
545 552
546 BrowserInit::LaunchWithProfile lwp(cur_dir, command_line, this); 553 BrowserInit::LaunchWithProfile lwp(cur_dir, command_line, this);
547 std::vector<GURL> urls_to_launch = BrowserInit::GetURLsFromCommandLine( 554 std::vector<GURL> urls_to_launch = BrowserInit::GetURLsFromCommandLine(
548 command_line, cur_dir, profile); 555 command_line, cur_dir, profile);
549 bool launched = lwp.Launch(profile, urls_to_launch, process_startup); 556 bool launched = lwp.Launch(profile, urls_to_launch, process_startup);
550 in_startup = false; 557 in_startup = false;
551 558
552 if (!launched) { 559 if (!launched) {
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 return false; 1447 return false;
1441 automation->SetExpectedTabCount(expected_tabs); 1448 automation->SetExpectedTabCount(expected_tabs);
1442 1449
1443 AutomationProviderList* list = 1450 AutomationProviderList* list =
1444 g_browser_process->InitAutomationProviderList(); 1451 g_browser_process->InitAutomationProviderList();
1445 DCHECK(list); 1452 DCHECK(list);
1446 list->AddProvider(automation); 1453 list->AddProvider(automation);
1447 1454
1448 return true; 1455 return true;
1449 } 1456 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698