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