Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / profile_resetter / resettable_settings_snapshot.h
blob04b4541eb77dbfdf4bbd836e3ba0635b9d0a684e
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_
8 #include <string>
9 #include <utility>
10 #include <vector>
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"
18 namespace base {
19 class ListValue;
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,
37 ALL_FIELDS = STARTUP_MODE | HOMEPAGE | DSE_URL | EXTENSIONS | SHORTCUTS,
40 explicit ResettableSettingsSnapshot(Profile* profile);
41 ~ResettableSettingsSnapshot();
43 // Getters.
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 {
61 return shortcuts_;
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
74 // difference.
75 // The return value is a bit mask of Field values signifying which members
76 // were different.
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);
83 private:
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.
97 std::string dse_url_;
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
103 // arguments.
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,
126 int field_mask);
128 // Sends |report| as a feedback. |report| is supposed to be result of
129 // SerializeSettingsReport().
130 void SendSettingsFeedback(const std::string& report,
131 Profile* profile,
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(
137 Profile* profile,
138 const ResettableSettingsSnapshot& snapshot);
140 #endif // CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_