Update V8 to version 4.5.11.
[chromium-blink-merge.git] / chrome / installer / util / master_preferences.h
blob2b8c914399bd71804b12b680f1cd1242a06a50db
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 // This file contains functions processing master preference file used by
6 // setup and first run.
8 #ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_
9 #define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_
11 #include <string>
12 #include <vector>
14 #include "base/command_line.h"
15 #include "base/memory/scoped_ptr.h"
17 namespace base {
18 class DictionaryValue;
19 class FilePath;
22 namespace installer {
24 #if !defined(OS_MACOSX)
25 // This is the default name for the master preferences file used to pre-set
26 // values in the user profile at first run.
27 const char kDefaultMasterPrefs[] = "master_preferences";
28 #endif
30 // The master preferences is a JSON file with the same entries as the
31 // 'Default\Preferences' file. This function parses the distribution
32 // section of the preferences file.
34 // A prototypical 'master_preferences' file looks like this:
36 // {
37 // "distribution": {
38 // "alternate_shortcut_text": false,
39 // "auto_launch_chrome": false,
40 // "chrome_shortcut_icon_index": 0,
41 // "create_all_shortcuts": true,
42 // "import_bookmarks": false,
43 // "import_bookmarks_from_file": "c:\\path",
44 // "import_history": false,
45 // "import_home_page": false,
46 // "import_search_engine": true,
47 // "ping_delay": 40,
48 // "show_welcome_page": true,
49 // "skip_first_run_ui": true,
50 // "do_not_launch_chrome": false,
51 // "make_chrome_default": false,
52 // "make_chrome_default_for_user": true,
53 // "require_eula": true,
54 // "system_level": false,
55 // "verbose_logging": true
56 // },
57 // "browser": {
58 // "show_home_button": true
59 // },
60 // "bookmark_bar": {
61 // "show_on_all_tabs": true
62 // },
63 // "first_run_tabs": [
64 // "http://gmail.com",
65 // "https://igoogle.com"
66 // ],
67 // "homepage": "http://example.org",
68 // "homepage_is_newtabpage": false
69 // }
71 // A reserved "distribution" entry in the file is used to group related
72 // installation properties. This entry will be ignored at other times.
73 // This function parses the 'distribution' entry and returns a combination
74 // of MasterPrefResult.
76 class MasterPreferences {
77 public:
78 // Construct a master preferences from the current process' current command
79 // line. Equivalent to calling
80 // MasterPreferences(*CommandLine::ForCurrentProcess()).
81 MasterPreferences();
83 // Parses the command line and optionally reads the master preferences file
84 // to get distribution related install options (if the "installerdata" switch
85 // is present in the command line.
86 // The options from the preference file and command line are merged, with the
87 // ones from the command line taking precedence in case of a conflict.
88 explicit MasterPreferences(const base::CommandLine& cmd_line);
90 // Parses a specific preferences file and does not merge any command line
91 // switches with the distribution dictionary.
92 explicit MasterPreferences(const base::FilePath& prefs_path);
94 // Parses a preferences directly from |prefs| and does not merge any command
95 // line switches with the distribution dictionary.
96 explicit MasterPreferences(const std::string& prefs);
98 ~MasterPreferences();
100 // Each of the Get methods below returns true if the named value was found in
101 // the distribution dictionary and its value assigned to the 'value'
102 // parameter. If the value wasn't found, the return value is false.
103 bool GetBool(const std::string& name, bool* value) const;
104 bool GetInt(const std::string& name, int* value) const;
105 bool GetString(const std::string& name, std::string* value) const;
107 // As part of the master preferences an optional section indicates the tabs
108 // to open during first run. An example is the following:
110 // {
111 // "first_run_tabs": [
112 // "http://google.com/f1",
113 // "https://google.com/f2"
114 // ]
115 // }
117 // Note that the entries are usually urls but they don't have to be.
119 // An empty vector is returned if the first_run_tabs preference is absent.
120 std::vector<std::string> GetFirstRunTabs() const;
122 // The master preferences can also contain a regular extensions
123 // preference block. If so, the extensions referenced there will be
124 // installed during the first run experience.
125 // An extension can go in the master prefs needs just the basic
126 // elements such as:
127 // 1- An extension entry under settings, assigned by the gallery
128 // 2- The "location" : 1 entry
129 // 3- A minimal "manifest" block with key, name, permissions, update url
130 // and version. The version needs to be lower than the version of
131 // the extension that is hosted in the gallery.
132 // 4- The "path" entry with the version as last component
133 // 5- The "state" : 1 entry
135 // The following is an example of a master pref file that installs
136 // Google XYZ:
138 // {
139 // "extensions": {
140 // "settings": {
141 // "ppflmjolhbonpkbkooiamcnenbmbjcbb": {
142 // "location": 1,
143 // "manifest": {
144 // "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4<rest of key ommited>",
145 // "name": "Google XYZ (Installing...)",
146 // "permissions": [ "tabs", "http://xyz.google.com/" ],
147 // "update_url": "http://fixme.com/fixme/fixme/crx",
148 // "version": "0.0"
149 // },
150 // "path": "ppflmjolhbonpkbkooiamcnenbmbjcbb\\0.0",
151 // "state": 1
152 // }
153 // }
154 // }
155 // }
157 bool GetExtensionsBlock(base::DictionaryValue** extensions) const;
159 // Returns the compressed variations seed entry from the master prefs.
160 std::string GetCompressedVariationsSeed() const;
162 // Returns the variations seed entry from the master prefs.
163 std::string GetVariationsSeed() const;
165 // Returns the variations seed signature entry from the master prefs.
166 std::string GetVariationsSeedSignature() const;
168 // Returns true iff the master preferences were successfully read from a file.
169 bool read_from_file() const {
170 return preferences_read_from_file_;
173 bool install_chrome() const {
174 return chrome_;
177 bool is_multi_install() const {
178 return multi_install_;
181 // Returns a reference to this MasterPreferences' root dictionary of values.
182 const base::DictionaryValue& master_dictionary() const {
183 return *master_dictionary_.get();
186 // Returns a static preference object that has been initialized with the
187 // CommandLine object for the current process.
188 // NOTE: Must not be called before CommandLine::Init() is called!
189 // OTHER NOTE: Not thread safe.
190 static const MasterPreferences& ForCurrentProcess();
192 protected:
193 void InitializeFromCommandLine(const base::CommandLine& cmd_line);
195 // Initializes the instance from a given JSON string, returning true if the
196 // string was successfully parsed.
197 bool InitializeFromString(const std::string& json_data);
199 void InitializeProductFlags();
201 // Enforces legacy preferences that should no longer be used, but could be
202 // found in older master_preferences files.
203 void EnforceLegacyPreferences();
205 // Removes the specified string pref from the master preferences and returns
206 // its value. Should be used for master prefs that shouldn't be automatically
207 // copied over to profile preferences.
208 std::string ExtractPrefString(const std::string& name) const;
210 scoped_ptr<base::DictionaryValue> master_dictionary_;
211 base::DictionaryValue* distribution_;
212 bool preferences_read_from_file_;
213 bool chrome_;
214 bool multi_install_;
216 private:
217 DISALLOW_COPY_AND_ASSIGN(MasterPreferences);
220 } // namespace installer
222 #endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_