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