• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_PREFS_SESSION_STARTUP_PREF_H__
6 #define CHROME_BROWSER_PREFS_SESSION_STARTUP_PREF_H__
7 
8 #include <vector>
9 
10 #include "url/gurl.h"
11 
12 class PrefService;
13 class Profile;
14 
15 namespace user_prefs {
16 class PrefRegistrySyncable;
17 }
18 
19 // StartupPref specifies what should happen at startup for a specified profile.
20 // StartupPref is stored in the preferences for a particular profile.
21 struct SessionStartupPref {
22   enum Type {
23     // Indicates the user wants to open the New Tab page.
24     DEFAULT,
25 
26     // Deprecated. See comment in session_startup_pref.cc
27     HOMEPAGE,
28 
29     // Indicates the user wants to restore the last session.
30     LAST,
31 
32     // Indicates the user wants to restore a specific set of URLs. The URLs
33     // are contained in urls.
34     URLS,
35 
36     // Number of values in this enum.
37     TYPE_COUNT
38   };
39 
40   // For historical reasons the enum and value registered in the prefs don't
41   // line up. These are the values registered in prefs.
42   // The values are also recorded in Settings.StartupPageLoadSettings histogram,
43   // so make sure to update histograms.xml if you change these.
44   static const int kPrefValueHomePage = 0;  // Deprecated
45   static const int kPrefValueLast = 1;
46   static const int kPrefValueURLs = 4;
47   static const int kPrefValueNewTab = 5;
48   static const int kPrefValueMax = 6;
49 
50   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
51 
52   // Returns the default value for |type|.
53   static Type GetDefaultStartupType();
54 
55   // What should happen on startup for the specified profile.
56   static void SetStartupPref(Profile* profile, const SessionStartupPref& pref);
57   static void SetStartupPref(PrefService* prefs,
58                              const SessionStartupPref& pref);
59   static SessionStartupPref GetStartupPref(Profile* profile);
60   static SessionStartupPref GetStartupPref(PrefService* prefs);
61 
62   // If the user had the "restore on startup" property set to the deprecated
63   // "Open the home page" value, this migrates them to a value that will have
64   // the same effect.
65   static void MigrateIfNecessary(PrefService* prefs);
66 
67   // The default startup pref for Mac used to be LAST, now it's DEFAULT. This
68   // migrates old users by writing out the preference explicitly.
69   static void MigrateMacDefaultPrefIfNecessary(PrefService* prefs);
70 
71   // Whether the startup type and URLs are managed via policy.
72   static bool TypeIsManaged(PrefService* prefs);
73   static bool URLsAreManaged(PrefService* prefs);
74 
75   // Whether the startup type has not been overridden from its default.
76   static bool TypeIsDefault(PrefService* prefs);
77 
78   // Converts an integer pref value to a SessionStartupPref::Type.
79   static SessionStartupPref::Type PrefValueToType(int pref_value);
80 
81   explicit SessionStartupPref(Type type);
82 
83   ~SessionStartupPref();
84 
85   // What to do on startup.
86   Type type;
87 
88   // The URLs to restore. Only used if type == URLS.
89   std::vector<GURL> urls;
90 };
91 
92 #endif  // CHROME_BROWSER_PREFS_SESSION_STARTUP_PREF_H__
93