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.
5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_
6 #define CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_
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"
22 // ResettableSettingsSnapshot captures some settings values at constructor. It
23 // can calculate the difference between two snapshots. That is, modified fields.
24 class ResettableSettingsSnapshot
{
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.
31 STARTUP_MODE
= 1 << 0,
37 ALL_FIELDS
= STARTUP_MODE
| HOMEPAGE
| DSE_URL
| EXTENSIONS
| SHORTCUTS
,
40 explicit ResettableSettingsSnapshot(Profile
* profile
);
41 ~ResettableSettingsSnapshot();
44 const std::vector
<GURL
>& startup_urls() const { return startup_
.urls
; }
46 SessionStartupPref::Type
startup_type() const { return startup_
.type
; }
48 const std::string
& homepage() const { return homepage_
; }
50 bool homepage_is_ntp() const { return homepage_is_ntp_
; }
52 bool show_home_button() const { return show_home_button_
; }
54 const std::string
& dse_url() const { return dse_url_
; }
56 const ExtensionList
& enabled_extensions() const {
57 return enabled_extensions_
;
60 const std::vector
<ShortcutCommand
>& shortcuts() const {
64 bool shortcuts_determined() const {
65 return shortcuts_determined_
;
68 // Substitutes |enabled_extensions_| with
69 // |enabled_extensions_|\|snapshot.enabled_extensions_|.
70 void Subtract(const ResettableSettingsSnapshot
& snapshot
);
72 // For each member 'm' compares |this->m| with |snapshot.m| and sets the
73 // corresponding |ResetableSettingsSnapshot::Field| bit to 1 in case of
75 // The return value is a bit mask of Field values signifying which members
77 int FindDifferentFields(const ResettableSettingsSnapshot
& snapshot
) const;
79 // Collects the shortcuts asynchronously and calls |callback|. If the request
80 // has been made already, noop.
81 void RequestShortcuts(const base::Closure
& callback
);
84 // Fills the |shortcuts_| member and calls |callback|.
85 void SetShortcutsAndReport(
86 const base::Closure
& callback
,
87 const std::vector
<ShortcutCommand
>& shortcuts
);
89 // Startup pages. URLs are always stored sorted.
90 SessionStartupPref startup_
;
92 std::string homepage_
;
93 bool homepage_is_ntp_
;
94 bool show_home_button_
;
96 // Default search engine.
99 // List of pairs [id, name] for enabled extensions. Always sorted.
100 ExtensionList enabled_extensions_
;
102 // Chrome shortcuts (e.g. icons on the Windows desktop, etc.) with non-empty
104 std::vector
<ShortcutCommand
> shortcuts_
;
106 // |shortcuts_| were retrieved.
107 bool shortcuts_determined_
;
109 // The flag to cancel shortcuts retrieving.
110 scoped_refptr
<SharedCancellationFlag
> cancellation_flag_
;
112 base::WeakPtrFactory
<ResettableSettingsSnapshot
> weak_ptr_factory_
;
114 DISALLOW_COPY_AND_ASSIGN(ResettableSettingsSnapshot
);
117 // The caller of ResettableSettingsSnapshot.
118 enum SnapshotCaller
{
119 PROFILE_RESET_WEBUI
= 0,
120 PROFILE_RESET_PROMPT
,
123 // Serializes specified |snapshot| members to JSON format. |field_mask| is a bit
124 // mask of ResettableSettingsSnapshot::Field values.
125 std::string
SerializeSettingsReport(const ResettableSettingsSnapshot
& snapshot
,
128 // Sends |report| as a feedback. |report| is supposed to be result of
129 // SerializeSettingsReport().
130 void SendSettingsFeedback(const std::string
& report
,
132 SnapshotCaller caller
);
134 // Returns list of key/value pairs for all available reported information
135 // from the |profile| and some additional fields.
136 scoped_ptr
<base::ListValue
> GetReadableFeedbackForSnapshot(
138 const ResettableSettingsSnapshot
& snapshot
);
140 #endif // CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_