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