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 "base/strings/string_split.h"
16 #include "chrome/browser/prefs/session_startup_pref.h"
17 #include "chrome/browser/profile_resetter/profile_resetter.h"
23 // ResettableSettingsSnapshot captures some settings values at constructor. It
24 // can calculate the difference between two snapshots. That is, modified fields.
25 class ResettableSettingsSnapshot
{
27 // ExtensionList is a vector of pairs. The first component is the extension
28 // id, the second is the name.
29 typedef base::StringPairs ExtensionList
;
30 // All types of settings handled by this class.
32 STARTUP_MODE
= 1 << 0,
38 ALL_FIELDS
= STARTUP_MODE
| HOMEPAGE
| DSE_URL
| EXTENSIONS
| SHORTCUTS
,
41 explicit ResettableSettingsSnapshot(Profile
* profile
);
42 ~ResettableSettingsSnapshot();
45 const std::vector
<GURL
>& startup_urls() const { return startup_
.urls
; }
47 SessionStartupPref::Type
startup_type() const { return startup_
.type
; }
49 const std::string
& homepage() const { return homepage_
; }
51 bool homepage_is_ntp() const { return homepage_is_ntp_
; }
53 bool show_home_button() const { return show_home_button_
; }
55 const std::string
& dse_url() const { return dse_url_
; }
57 const ExtensionList
& enabled_extensions() const {
58 return enabled_extensions_
;
61 const std::vector
<ShortcutCommand
>& shortcuts() const {
65 bool shortcuts_determined() const {
66 return shortcuts_determined_
;
69 // Substitutes |enabled_extensions_| with
70 // |enabled_extensions_|\|snapshot.enabled_extensions_|.
71 void Subtract(const ResettableSettingsSnapshot
& snapshot
);
73 // For each member 'm' compares |this->m| with |snapshot.m| and sets the
74 // corresponding |ResetableSettingsSnapshot::Field| bit to 1 in case of
76 // The return value is a bit mask of Field values signifying which members
78 int FindDifferentFields(const ResettableSettingsSnapshot
& snapshot
) const;
80 // Collects the shortcuts asynchronously and calls |callback|. If the request
81 // has been made already, noop.
82 void RequestShortcuts(const base::Closure
& callback
);
85 // Fills the |shortcuts_| member and calls |callback|.
86 void SetShortcutsAndReport(
87 const base::Closure
& callback
,
88 const std::vector
<ShortcutCommand
>& shortcuts
);
90 // Startup pages. URLs are always stored sorted.
91 SessionStartupPref startup_
;
93 std::string homepage_
;
94 bool homepage_is_ntp_
;
95 bool show_home_button_
;
97 // Default search engine.
100 // List of pairs [id, name] for enabled extensions. Always sorted.
101 ExtensionList enabled_extensions_
;
103 // Chrome shortcuts (e.g. icons on the Windows desktop, etc.) with non-empty
105 std::vector
<ShortcutCommand
> shortcuts_
;
107 // |shortcuts_| were retrieved.
108 bool shortcuts_determined_
;
110 // The flag to cancel shortcuts retrieving.
111 scoped_refptr
<SharedCancellationFlag
> cancellation_flag_
;
113 base::WeakPtrFactory
<ResettableSettingsSnapshot
> weak_ptr_factory_
;
115 DISALLOW_COPY_AND_ASSIGN(ResettableSettingsSnapshot
);
118 // The caller of ResettableSettingsSnapshot.
119 enum SnapshotCaller
{
120 PROFILE_RESET_WEBUI
= 0,
121 PROFILE_RESET_PROMPT
,
124 // Serializes specified |snapshot| members to JSON format. |field_mask| is a bit
125 // mask of ResettableSettingsSnapshot::Field values.
126 std::string
SerializeSettingsReport(const ResettableSettingsSnapshot
& snapshot
,
129 // Sends |report| as a feedback. |report| is supposed to be result of
130 // SerializeSettingsReport().
131 void SendSettingsFeedback(const std::string
& report
,
133 SnapshotCaller caller
);
135 // Returns list of key/value pairs for all available reported information
136 // from the |profile| and some additional fields.
137 scoped_ptr
<base::ListValue
> GetReadableFeedbackForSnapshot(
139 const ResettableSettingsSnapshot
& snapshot
);
141 #endif // CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_