OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This file contains functions processing master preference file used by | 5 // This file contains functions processing master preference file used by |
6 // setup and first run. | 6 // setup and first run. |
7 | 7 |
8 #ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ | 8 #ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ |
9 #define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ | 9 #define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/scoped_ptr.h" |
15 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
16 #include "chrome/installer/util/master_preferences_constants.h" | |
17 | 17 |
18 class DictionaryValue; | 18 class DictionaryValue; |
19 class FilePath; | 19 class FilePath; |
20 | 20 |
21 namespace installer_util { | 21 namespace installer_util { |
22 | 22 |
23 // This is the default name for the master preferences file used to pre-set | 23 // This is the default name for the master preferences file used to pre-set |
24 // values in the user profile at first run. | 24 // values in the user profile at first run. |
25 const char kDefaultMasterPrefs[] = "master_preferences"; | 25 const char kDefaultMasterPrefs[] = "master_preferences"; |
26 | 26 |
27 // Parse command line and read master preferences, if present, to get | |
28 // distribution related install options. Merge them if any command line | |
29 // options present (command line value takes precedence). | |
30 DictionaryValue* GetInstallPreferences(const CommandLine& cmd_line); | |
31 | |
32 // Gets the value of given boolean preference |name| from |prefs| dictionary | |
33 // which is assumed to contain a dictionary named "distribution". Returns | |
34 // true if the value is read successfully, otherwise false. | |
35 bool GetDistroBooleanPreference(const DictionaryValue* prefs, | |
36 const std::string& name, | |
37 bool* value); | |
38 | |
39 // This function gets value of a string preference from master | |
40 // preferences. Returns true if the value is read successfully, otherwise false. | |
41 bool GetDistroStringPreference(const DictionaryValue* prefs, | |
42 const std::string& name, | |
43 std::string* value); | |
44 | |
45 // This function gets value of an integer preference from master | |
46 // preferences. Returns true if the value is read successfully, otherwise false. | |
47 bool GetDistroIntegerPreference(const DictionaryValue* prefs, | |
48 const std::string& name, | |
49 int* value); | |
50 | |
51 // The master preferences is a JSON file with the same entries as the | 27 // The master preferences is a JSON file with the same entries as the |
52 // 'Default\Preferences' file. This function parses the distribution | 28 // 'Default\Preferences' file. This function parses the distribution |
53 // section of the preferences file. | 29 // section of the preferences file. |
54 // | 30 // |
55 // A prototypical 'master_preferences' file looks like this: | 31 // A prototypical 'master_preferences' file looks like this: |
56 // | 32 // |
57 // { | 33 // { |
58 // "distribution": { | 34 // "distribution": { |
59 // "alternate_shortcut_text": false, | 35 // "alternate_shortcut_text": false, |
60 // "oem_bubble": false, | 36 // "oem_bubble": false, |
(...skipping 25 matching lines...) Expand all Loading... |
86 // "https://igoogle.com" | 62 // "https://igoogle.com" |
87 // ], | 63 // ], |
88 // "homepage": "http://example.org", | 64 // "homepage": "http://example.org", |
89 // "homepage_is_newtabpage": false | 65 // "homepage_is_newtabpage": false |
90 // } | 66 // } |
91 // | 67 // |
92 // A reserved "distribution" entry in the file is used to group related | 68 // A reserved "distribution" entry in the file is used to group related |
93 // installation properties. This entry will be ignored at other times. | 69 // installation properties. This entry will be ignored at other times. |
94 // This function parses the 'distribution' entry and returns a combination | 70 // This function parses the 'distribution' entry and returns a combination |
95 // of MasterPrefResult. | 71 // of MasterPrefResult. |
96 DictionaryValue* ParseDistributionPreferences( | 72 class MasterPreferences { |
97 const FilePath& master_prefs_path); | 73 public: |
| 74 // Parses the command line and optionally reads the master preferences file |
| 75 // to get distribution related install options (if the "installerdata" switch |
| 76 // is present in the command line. |
| 77 // The options from the preference file and command line are merged, with the |
| 78 // ones from the command line taking precedence in case of a conflict. |
| 79 explicit MasterPreferences(const CommandLine& cmd_line); |
98 | 80 |
99 // As part of the master preferences an optional section indicates the tabs | 81 // Parses a specific preferences file and does not merge any command line |
100 // to open during first run. An example is the following: | 82 // switches with the distribution dictionary. |
101 // | 83 explicit MasterPreferences(const FilePath& prefs_path); |
102 // { | |
103 // "first_run_tabs": [ | |
104 // "http://google.com/f1", | |
105 // "https://google.com/f2" | |
106 // ] | |
107 // } | |
108 // | |
109 // Note that the entries are usually urls but they don't have to. | |
110 // | |
111 // This function retuns the list as a vector of GURLs. If the master | |
112 // preferences file does not contain such list the vector is empty. | |
113 std::vector<GURL> GetFirstRunTabs(const DictionaryValue* prefs); | |
114 | 84 |
115 // Sets the value of given boolean preference |name| in "distribution" | 85 ~MasterPreferences(); |
116 // dictionary inside |prefs| dictionary. | |
117 bool SetDistroBooleanPreference(DictionaryValue* prefs, | |
118 const std::string& name, | |
119 bool value); | |
120 | 86 |
121 // The master preferences can also contain a regular extensions | 87 // Each of the Get methods below returns true if the named value was found in |
122 // preference block. If so, the extensions referenced there will be | 88 // the distribution dictionary and its value assigned to the 'value' |
123 // installed during the first run experience. | 89 // parameter. If the value wasn't found, the return value is false. |
124 // An extension can go in the master prefs needs just the basic | 90 bool GetBool(const std::string& name, bool* value) const; |
125 // elements such as: | 91 bool GetInt(const std::string& name, int* value) const; |
126 // 1- An extension entry under settings, assigned by the gallery | 92 bool GetString(const std::string& name, std::string* value) const; |
127 // 2- The "location" : 1 entry | 93 |
128 // 3- A minimal "manifest" block with key, name, permissions, update url | 94 // As part of the master preferences an optional section indicates the tabs |
129 // and version. The version needs to be lower than the version of | 95 // to open during first run. An example is the following: |
130 // the extension that is hosted in the gallery. | 96 // |
131 // 4- The "path" entry with the version as last component | 97 // { |
132 // 5- The "state" : 1 entry | 98 // "first_run_tabs": [ |
133 // | 99 // "http://google.com/f1", |
134 // The following is an example of a master pref file that installs | 100 // "https://google.com/f2" |
135 // Google XYZ: | 101 // ] |
136 // | 102 // } |
137 // { | 103 // |
138 // "extensions": { | 104 // Note that the entries are usually urls but they don't have to be. |
139 // "settings": { | 105 // |
140 // "ppflmjolhbonpkbkooiamcnenbmbjcbb": { | 106 // This function returns the list as a vector of GURLs. If the master |
141 // "location": 1, | 107 // preferences file does not contain such a list the vector is empty. |
142 // "manifest": { | 108 std::vector<GURL> GetFirstRunTabs() const; |
143 // "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4<rest of key ommited>", | 109 |
144 // "name": "Google XYZ (Installing...)", | 110 // The master preferences can also contain a regular extensions |
145 // "permissions": [ "tabs", "http://xyz.google.com/" ], | 111 // preference block. If so, the extensions referenced there will be |
146 // "update_url": "http://fixme.com/fixme/fixme/crx", | 112 // installed during the first run experience. |
147 // "version": "0.0" | 113 // An extension can go in the master prefs needs just the basic |
148 // }, | 114 // elements such as: |
149 // "path": "ppflmjolhbonpkbkooiamcnenbmbjcbb\\0.0", | 115 // 1- An extension entry under settings, assigned by the gallery |
150 // "state": 1 | 116 // 2- The "location" : 1 entry |
151 // } | 117 // 3- A minimal "manifest" block with key, name, permissions, update url |
152 // } | 118 // and version. The version needs to be lower than the version of |
153 // } | 119 // the extension that is hosted in the gallery. |
154 // } | 120 // 4- The "path" entry with the version as last component |
155 // | 121 // 5- The "state" : 1 entry |
156 bool HasExtensionsBlock(const DictionaryValue* prefs, | 122 // |
157 DictionaryValue** extensions); | 123 // The following is an example of a master pref file that installs |
| 124 // Google XYZ: |
| 125 // |
| 126 // { |
| 127 // "extensions": { |
| 128 // "settings": { |
| 129 // "ppflmjolhbonpkbkooiamcnenbmbjcbb": { |
| 130 // "location": 1, |
| 131 // "manifest": { |
| 132 // "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4<rest of key ommited>", |
| 133 // "name": "Google XYZ (Installing...)", |
| 134 // "permissions": [ "tabs", "http://xyz.google.com/" ], |
| 135 // "update_url": "http://fixme.com/fixme/fixme/crx", |
| 136 // "version": "0.0" |
| 137 // }, |
| 138 // "path": "ppflmjolhbonpkbkooiamcnenbmbjcbb\\0.0", |
| 139 // "state": 1 |
| 140 // } |
| 141 // } |
| 142 // } |
| 143 // } |
| 144 // |
| 145 bool GetExtensionsBlock(DictionaryValue** extensions) const; |
| 146 |
| 147 // Returns true iff the master preferences were successfully read from a file. |
| 148 bool read_from_file() const { |
| 149 return preferences_read_from_file_; |
| 150 } |
| 151 |
| 152 protected: |
| 153 scoped_ptr<DictionaryValue> master_dictionary_; |
| 154 DictionaryValue* distribution_; |
| 155 bool preferences_read_from_file_; |
| 156 |
| 157 private: |
| 158 DISALLOW_COPY_AND_ASSIGN(MasterPreferences); |
| 159 }; |
158 | 160 |
159 } // namespace installer_util | 161 } // namespace installer_util |
160 | 162 |
161 #endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ | 163 #endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ |
OLD | NEW |