| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ | 5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ |
| 6 #define CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ | 6 #define CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "chrome/browser/prefs/session_startup_pref.h" | 9 #include "chrome/browser/prefs/session_startup_pref.h" |
| 10 | 10 |
| 11 namespace base { |
| 12 class ListValue; |
| 13 } |
| 14 |
| 11 // ResettableSettingsSnapshot captures some settings values at constructor. It | 15 // ResettableSettingsSnapshot captures some settings values at constructor. It |
| 12 // can calculate the difference between two snapshots. That is, modified fields. | 16 // can calculate the difference between two snapshots. That is, modified fields. |
| 13 class ResettableSettingsSnapshot { | 17 class ResettableSettingsSnapshot { |
| 14 public: | 18 public: |
| 19 // ExtensionList is a vector of pairs. The first component is the extension |
| 20 // id, the second is the name. |
| 21 typedef std::vector<std::pair<std::string, std::string> > ExtensionList; |
| 15 // All types of settings handled by this class. | 22 // All types of settings handled by this class. |
| 16 enum Field { | 23 enum Field { |
| 17 STARTUP_URLS = 1 << 0, | 24 STARTUP_URLS = 1 << 0, |
| 18 STARTUP_TYPE = 1 << 1, | 25 STARTUP_TYPE = 1 << 1, |
| 19 HOMEPAGE = 1 << 2, | 26 HOMEPAGE = 1 << 2, |
| 20 HOMEPAGE_IS_NTP = 1 << 3, | 27 HOMEPAGE_IS_NTP = 1 << 3, |
| 21 DSE_URL = 1 << 4, | 28 DSE_URL = 1 << 4, |
| 22 EXTENSIONS = 1 << 5, | 29 EXTENSIONS = 1 << 5, |
| 23 | 30 |
| 24 ALL_FIELDS = STARTUP_URLS | STARTUP_TYPE | HOMEPAGE | | 31 ALL_FIELDS = STARTUP_URLS | STARTUP_TYPE | HOMEPAGE | |
| 25 HOMEPAGE_IS_NTP | DSE_URL | EXTENSIONS, | 32 HOMEPAGE_IS_NTP | DSE_URL | EXTENSIONS, |
| 26 }; | 33 }; |
| 27 | 34 |
| 28 explicit ResettableSettingsSnapshot(Profile* profile); | 35 explicit ResettableSettingsSnapshot(Profile* profile); |
| 29 ~ResettableSettingsSnapshot(); | 36 ~ResettableSettingsSnapshot(); |
| 30 | 37 |
| 31 // Getters. | 38 // Getters. |
| 32 const std::vector<GURL>& startup_urls() const { return startup_.urls; } | 39 const std::vector<GURL>& startup_urls() const { return startup_.urls; } |
| 33 | 40 |
| 34 SessionStartupPref::Type startup_type() const { return startup_.type; } | 41 SessionStartupPref::Type startup_type() const { return startup_.type; } |
| 35 | 42 |
| 36 const std::string& homepage() const { return homepage_; } | 43 const std::string& homepage() const { return homepage_; } |
| 37 | 44 |
| 38 bool homepage_is_ntp() const { return homepage_is_ntp_; } | 45 bool homepage_is_ntp() const { return homepage_is_ntp_; } |
| 39 | 46 |
| 40 const std::string& dse_url() const { return dse_url_; } | 47 const std::string& dse_url() const { return dse_url_; } |
| 41 | 48 |
| 42 const std::vector<std::string>& enabled_extensions() const { | 49 const ExtensionList& enabled_extensions() const { |
| 43 return enabled_extensions_; | 50 return enabled_extensions_; |
| 44 } | 51 } |
| 45 | 52 |
| 46 // Substitutes |startup_.urls| with |startup_.urls|\|snapshot.startup_.urls|. | 53 // Substitutes |startup_.urls| with |startup_.urls|\|snapshot.startup_.urls|. |
| 47 // Substitutes |enabled_extensions_| with | 54 // Substitutes |enabled_extensions_| with |
| 48 // |enabled_extensions_|\|snapshot.enabled_extensions_|. | 55 // |enabled_extensions_|\|snapshot.enabled_extensions_|. |
| 49 void Subtract(const ResettableSettingsSnapshot& snapshot); | 56 void Subtract(const ResettableSettingsSnapshot& snapshot); |
| 50 | 57 |
| 51 // For each member 'm' compares |this->m| with |snapshot.m| and sets the | 58 // For each member 'm' compares |this->m| with |snapshot.m| and sets the |
| 52 // corresponding |ResetableSettingsSnapshot::Field| bit to 1 in case of | 59 // corresponding |ResetableSettingsSnapshot::Field| bit to 1 in case of |
| 53 // difference. | 60 // difference. |
| 54 // The return value is a bit mask of Field values signifying which members | 61 // The return value is a bit mask of Field values signifying which members |
| 55 // were different. | 62 // were different. |
| 56 int FindDifferentFields(const ResettableSettingsSnapshot& snapshot) const; | 63 int FindDifferentFields(const ResettableSettingsSnapshot& snapshot) const; |
| 57 | 64 |
| 58 private: | 65 private: |
| 59 // Startup pages. URLs are always stored sorted. | 66 // Startup pages. URLs are always stored sorted. |
| 60 SessionStartupPref startup_; | 67 SessionStartupPref startup_; |
| 61 | 68 |
| 62 std::string homepage_; | 69 std::string homepage_; |
| 63 bool homepage_is_ntp_; | 70 bool homepage_is_ntp_; |
| 64 | 71 |
| 65 // Default search engine. | 72 // Default search engine. |
| 66 std::string dse_url_; | 73 std::string dse_url_; |
| 67 | 74 |
| 68 // Enabled extension ids. Always sorted. | 75 // List of pairs [id, name] for enabled extensions. Always sorted. |
| 69 std::vector<std::string> enabled_extensions_; | 76 ExtensionList enabled_extensions_; |
| 70 | 77 |
| 71 DISALLOW_COPY_AND_ASSIGN(ResettableSettingsSnapshot); | 78 DISALLOW_COPY_AND_ASSIGN(ResettableSettingsSnapshot); |
| 72 }; | 79 }; |
| 73 | 80 |
| 74 // Serializes specified |snapshot| members to JSON format. |field_mask| is a bit | 81 // Serializes specified |snapshot| members to JSON format. |field_mask| is a bit |
| 75 // mask of ResettableSettingsSnapshot::Field values. | 82 // mask of ResettableSettingsSnapshot::Field values. |
| 76 std::string SerializeSettingsReport(const ResettableSettingsSnapshot& snapshot, | 83 std::string SerializeSettingsReport(const ResettableSettingsSnapshot& snapshot, |
| 77 int field_mask); | 84 int field_mask); |
| 78 | 85 |
| 79 // Sends |report| as a feedback. |report| is supposed to be result of | 86 // Sends |report| as a feedback. |report| is supposed to be result of |
| 80 // SerializeSettingsReport(). | 87 // SerializeSettingsReport(). |
| 81 void SendSettingsFeedback(const std::string& report, Profile* profile); | 88 void SendSettingsFeedback(const std::string& report, Profile* profile); |
| 82 | 89 |
| 90 // Returns list of key/value pairs for all reported information from the |
| 91 // |profile| and some additional fields. |
| 92 base::ListValue* GetReadableFeedback(Profile* profile); |
| 93 |
| 83 #endif // CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ | 94 #endif // CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ |
| OLD | NEW |