[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 1 | // Copyright (c) 2013 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_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ |
| 6 | #define CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ |
| 7 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 8 | #include <memory> |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <utility> |
| 11 | #include <vector> |
| 12 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 14 | #include "base/memory/weak_ptr.h" |
anand.ratn | 027d34b | 2014-09-24 07:40:12 | [diff] [blame] | 15 | #include "base/strings/string_split.h" |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 16 | #include "chrome/browser/prefs/session_startup_pref.h" |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 17 | #include "chrome/browser/profile_resetter/profile_resetter.h" |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 18 | |
[email protected] | 2ed8e55 | 2013-09-17 11:52:13 | [diff] [blame] | 19 | namespace base { |
| 20 | class ListValue; |
| 21 | } |
battre | ec96498 | 2015-12-15 14:04:58 | [diff] [blame] | 22 | namespace reset_report { |
| 23 | class ChromeResetReport; |
| 24 | } |
[email protected] | 2ed8e55 | 2013-09-17 11:52:13 | [diff] [blame] | 25 | |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 26 | // ResettableSettingsSnapshot captures some settings values at constructor. It |
| 27 | // can calculate the difference between two snapshots. That is, modified fields. |
| 28 | class ResettableSettingsSnapshot { |
| 29 | public: |
[email protected] | 2ed8e55 | 2013-09-17 11:52:13 | [diff] [blame] | 30 | // ExtensionList is a vector of pairs. The first component is the extension |
| 31 | // id, the second is the name. |
anand.ratn | 027d34b | 2014-09-24 07:40:12 | [diff] [blame] | 32 | typedef base::StringPairs ExtensionList; |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 33 | // All types of settings handled by this class. |
| 34 | enum Field { |
[email protected] | e937a970 | 2013-10-03 22:59:43 | [diff] [blame] | 35 | STARTUP_MODE = 1 << 0, |
| 36 | HOMEPAGE = 1 << 1, |
| 37 | DSE_URL = 1 << 2, |
| 38 | EXTENSIONS = 1 << 3, |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 39 | SHORTCUTS = 1 << 4, |
[email protected] | f43b64e | 2013-07-30 17:04:41 | [diff] [blame] | 40 | |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 41 | ALL_FIELDS = STARTUP_MODE | HOMEPAGE | DSE_URL | EXTENSIONS | SHORTCUTS, |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 42 | }; |
| 43 | |
[email protected] | 3ae13e0d | 2014-01-14 17:58:36 | [diff] [blame] | 44 | explicit ResettableSettingsSnapshot(Profile* profile); |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 45 | ~ResettableSettingsSnapshot(); |
| 46 | |
| 47 | // Getters. |
| 48 | const std::vector<GURL>& startup_urls() const { return startup_.urls; } |
| 49 | |
| 50 | SessionStartupPref::Type startup_type() const { return startup_.type; } |
| 51 | |
| 52 | const std::string& homepage() const { return homepage_; } |
| 53 | |
| 54 | bool homepage_is_ntp() const { return homepage_is_ntp_; } |
| 55 | |
[email protected] | 317894b | 2014-08-14 08:44:27 | [diff] [blame] | 56 | bool show_home_button() const { return show_home_button_; } |
| 57 | |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 58 | const std::string& dse_url() const { return dse_url_; } |
| 59 | |
[email protected] | 2ed8e55 | 2013-09-17 11:52:13 | [diff] [blame] | 60 | const ExtensionList& enabled_extensions() const { |
[email protected] | 392883a | 2013-08-09 14:15:46 | [diff] [blame] | 61 | return enabled_extensions_; |
| 62 | } |
| 63 | |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 64 | const std::vector<ShortcutCommand>& shortcuts() const { |
| 65 | return shortcuts_; |
| 66 | } |
| 67 | |
| 68 | bool shortcuts_determined() const { |
| 69 | return shortcuts_determined_; |
| 70 | } |
| 71 | |
battre | ec96498 | 2015-12-15 14:04:58 | [diff] [blame] | 72 | std::string guid() const { return guid_; } |
| 73 | |
[email protected] | 392883a | 2013-08-09 14:15:46 | [diff] [blame] | 74 | // Substitutes |enabled_extensions_| with |
| 75 | // |enabled_extensions_|\|snapshot.enabled_extensions_|. |
| 76 | void Subtract(const ResettableSettingsSnapshot& snapshot); |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 77 | |
| 78 | // For each member 'm' compares |this->m| with |snapshot.m| and sets the |
| 79 | // corresponding |ResetableSettingsSnapshot::Field| bit to 1 in case of |
| 80 | // difference. |
| 81 | // The return value is a bit mask of Field values signifying which members |
| 82 | // were different. |
| 83 | int FindDifferentFields(const ResettableSettingsSnapshot& snapshot) const; |
| 84 | |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 85 | // Collects the shortcuts asynchronously and calls |callback|. If the request |
| 86 | // has been made already, noop. |
| 87 | void RequestShortcuts(const base::Closure& callback); |
| 88 | |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 89 | private: |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 90 | // Fills the |shortcuts_| member and calls |callback|. |
| 91 | void SetShortcutsAndReport( |
| 92 | const base::Closure& callback, |
| 93 | const std::vector<ShortcutCommand>& shortcuts); |
| 94 | |
battre | ec96498 | 2015-12-15 14:04:58 | [diff] [blame] | 95 | // Every ResettableSettingsSnapshot instance gets a randomly created GUID. |
| 96 | std::string guid_; |
| 97 | |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 98 | // Startup pages. URLs are always stored sorted. |
| 99 | SessionStartupPref startup_; |
| 100 | |
| 101 | std::string homepage_; |
| 102 | bool homepage_is_ntp_; |
[email protected] | 317894b | 2014-08-14 08:44:27 | [diff] [blame] | 103 | bool show_home_button_; |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 104 | |
| 105 | // Default search engine. |
| 106 | std::string dse_url_; |
| 107 | |
[email protected] | 2ed8e55 | 2013-09-17 11:52:13 | [diff] [blame] | 108 | // List of pairs [id, name] for enabled extensions. Always sorted. |
| 109 | ExtensionList enabled_extensions_; |
[email protected] | 392883a | 2013-08-09 14:15:46 | [diff] [blame] | 110 | |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 111 | // Chrome shortcuts (e.g. icons on the Windows desktop, etc.) with non-empty |
| 112 | // arguments. |
| 113 | std::vector<ShortcutCommand> shortcuts_; |
| 114 | |
| 115 | // |shortcuts_| were retrieved. |
| 116 | bool shortcuts_determined_; |
| 117 | |
| 118 | // The flag to cancel shortcuts retrieving. |
| 119 | scoped_refptr<SharedCancellationFlag> cancellation_flag_; |
| 120 | |
| 121 | base::WeakPtrFactory<ResettableSettingsSnapshot> weak_ptr_factory_; |
| 122 | |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 123 | DISALLOW_COPY_AND_ASSIGN(ResettableSettingsSnapshot); |
| 124 | }; |
| 125 | |
battre | ec96498 | 2015-12-15 14:04:58 | [diff] [blame] | 126 | // Serializes specified |snapshot| members to a protobuf. |field_mask| is a bit |
| 127 | // mask of ResettableSettingsSnapshot::Field values. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 128 | std::unique_ptr<reset_report::ChromeResetReport> SerializeSettingsReportToProto( |
battre | ec96498 | 2015-12-15 14:04:58 | [diff] [blame] | 129 | const ResettableSettingsSnapshot& snapshot, |
| 130 | int field_mask); |
| 131 | |
[email protected] | f43b64e | 2013-07-30 17:04:41 | [diff] [blame] | 132 | // Sends |report| as a feedback. |report| is supposed to be result of |
battre | ec96498 | 2015-12-15 14:04:58 | [diff] [blame] | 133 | // SerializeSettingsReportToProto(). |
| 134 | void SendSettingsFeedbackProto(const reset_report::ChromeResetReport& report, |
| 135 | Profile* profile); |
| 136 | |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 137 | // Returns list of key/value pairs for all available reported information |
| 138 | // from the |profile| and some additional fields. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 139 | std::unique_ptr<base::ListValue> GetReadableFeedbackForSnapshot( |
[email protected] | d1027a8 | 2014-01-27 13:22:42 | [diff] [blame] | 140 | Profile* profile, |
| 141 | const ResettableSettingsSnapshot& snapshot); |
[email protected] | 3ae13e0d | 2014-01-14 17:58:36 | [diff] [blame] | 142 | |
[email protected] | 202ab050 | 2013-07-30 15:25:35 | [diff] [blame] | 143 | #endif // CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ |