blob: d857fa26ab1c0232309f7490844a75bf5c0796c4 [file] [log] [blame]
[email protected]202ab0502013-07-30 15:25:351// 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
dcheng4af48582016-04-19 00:29:358#include <memory>
[email protected]d1027a82014-01-27 13:22:429#include <string>
10#include <utility>
11#include <vector>
12
avib896c712015-12-26 02:10:4313#include "base/macros.h"
[email protected]d1027a82014-01-27 13:22:4214#include "base/memory/weak_ptr.h"
anand.ratn027d34b2014-09-24 07:40:1215#include "base/strings/string_split.h"
[email protected]202ab0502013-07-30 15:25:3516#include "chrome/browser/prefs/session_startup_pref.h"
[email protected]d1027a82014-01-27 13:22:4217#include "chrome/browser/profile_resetter/profile_resetter.h"
[email protected]202ab0502013-07-30 15:25:3518
[email protected]2ed8e552013-09-17 11:52:1319namespace base {
20class ListValue;
21}
battreec964982015-12-15 14:04:5822namespace reset_report {
23class ChromeResetReport;
24}
[email protected]2ed8e552013-09-17 11:52:1325
[email protected]202ab0502013-07-30 15:25:3526// ResettableSettingsSnapshot captures some settings values at constructor. It
27// can calculate the difference between two snapshots. That is, modified fields.
28class ResettableSettingsSnapshot {
29 public:
[email protected]2ed8e552013-09-17 11:52:1330 // ExtensionList is a vector of pairs. The first component is the extension
31 // id, the second is the name.
anand.ratn027d34b2014-09-24 07:40:1232 typedef base::StringPairs ExtensionList;
[email protected]202ab0502013-07-30 15:25:3533 // All types of settings handled by this class.
34 enum Field {
[email protected]e937a9702013-10-03 22:59:4335 STARTUP_MODE = 1 << 0,
36 HOMEPAGE = 1 << 1,
37 DSE_URL = 1 << 2,
38 EXTENSIONS = 1 << 3,
[email protected]d1027a82014-01-27 13:22:4239 SHORTCUTS = 1 << 4,
[email protected]f43b64e2013-07-30 17:04:4140
[email protected]d1027a82014-01-27 13:22:4241 ALL_FIELDS = STARTUP_MODE | HOMEPAGE | DSE_URL | EXTENSIONS | SHORTCUTS,
[email protected]202ab0502013-07-30 15:25:3542 };
43
[email protected]3ae13e0d2014-01-14 17:58:3644 explicit ResettableSettingsSnapshot(Profile* profile);
[email protected]202ab0502013-07-30 15:25:3545 ~ResettableSettingsSnapshot();
46
47 // Getters.
48 const std::vector<GURL>& startup_urls() const { return startup_.urls; }
49
50 SessionStartupPref::Type startup_type() const { return startup_.type; }
51
52 const std::string& homepage() const { return homepage_; }
53
54 bool homepage_is_ntp() const { return homepage_is_ntp_; }
55
[email protected]317894b2014-08-14 08:44:2756 bool show_home_button() const { return show_home_button_; }
57
[email protected]202ab0502013-07-30 15:25:3558 const std::string& dse_url() const { return dse_url_; }
59
[email protected]2ed8e552013-09-17 11:52:1360 const ExtensionList& enabled_extensions() const {
[email protected]392883a2013-08-09 14:15:4661 return enabled_extensions_;
62 }
63
[email protected]d1027a82014-01-27 13:22:4264 const std::vector<ShortcutCommand>& shortcuts() const {
65 return shortcuts_;
66 }
67
68 bool shortcuts_determined() const {
69 return shortcuts_determined_;
70 }
71
battreec964982015-12-15 14:04:5872 std::string guid() const { return guid_; }
73
[email protected]392883a2013-08-09 14:15:4674 // Substitutes |enabled_extensions_| with
75 // |enabled_extensions_|\|snapshot.enabled_extensions_|.
76 void Subtract(const ResettableSettingsSnapshot& snapshot);
[email protected]202ab0502013-07-30 15:25:3577
78 // For each member 'm' compares |this->m| with |snapshot.m| and sets the
79 // corresponding |ResetableSettingsSnapshot::Field| bit to 1 in case of
80 // difference.
81 // The return value is a bit mask of Field values signifying which members
82 // were different.
83 int FindDifferentFields(const ResettableSettingsSnapshot& snapshot) const;
84
[email protected]d1027a82014-01-27 13:22:4285 // Collects the shortcuts asynchronously and calls |callback|. If the request
86 // has been made already, noop.
87 void RequestShortcuts(const base::Closure& callback);
88
[email protected]202ab0502013-07-30 15:25:3589 private:
[email protected]d1027a82014-01-27 13:22:4290 // Fills the |shortcuts_| member and calls |callback|.
91 void SetShortcutsAndReport(
92 const base::Closure& callback,
93 const std::vector<ShortcutCommand>& shortcuts);
94
battreec964982015-12-15 14:04:5895 // Every ResettableSettingsSnapshot instance gets a randomly created GUID.
96 std::string guid_;
97
[email protected]202ab0502013-07-30 15:25:3598 // Startup pages. URLs are always stored sorted.
99 SessionStartupPref startup_;
100
101 std::string homepage_;
102 bool homepage_is_ntp_;
[email protected]317894b2014-08-14 08:44:27103 bool show_home_button_;
[email protected]202ab0502013-07-30 15:25:35104
105 // Default search engine.
106 std::string dse_url_;
107
[email protected]2ed8e552013-09-17 11:52:13108 // List of pairs [id, name] for enabled extensions. Always sorted.
109 ExtensionList enabled_extensions_;
[email protected]392883a2013-08-09 14:15:46110
[email protected]d1027a82014-01-27 13:22:42111 // Chrome shortcuts (e.g. icons on the Windows desktop, etc.) with non-empty
112 // arguments.
113 std::vector<ShortcutCommand> shortcuts_;
114
115 // |shortcuts_| were retrieved.
116 bool shortcuts_determined_;
117
118 // The flag to cancel shortcuts retrieving.
119 scoped_refptr<SharedCancellationFlag> cancellation_flag_;
120
121 base::WeakPtrFactory<ResettableSettingsSnapshot> weak_ptr_factory_;
122
[email protected]202ab0502013-07-30 15:25:35123 DISALLOW_COPY_AND_ASSIGN(ResettableSettingsSnapshot);
124};
125
battreec964982015-12-15 14:04:58126// Serializes specified |snapshot| members to a protobuf. |field_mask| is a bit
127// mask of ResettableSettingsSnapshot::Field values.
dcheng4af48582016-04-19 00:29:35128std::unique_ptr<reset_report::ChromeResetReport> SerializeSettingsReportToProto(
battreec964982015-12-15 14:04:58129 const ResettableSettingsSnapshot& snapshot,
130 int field_mask);
131
[email protected]f43b64e2013-07-30 17:04:41132// Sends |report| as a feedback. |report| is supposed to be result of
battreec964982015-12-15 14:04:58133// SerializeSettingsReportToProto().
134void SendSettingsFeedbackProto(const reset_report::ChromeResetReport& report,
135 Profile* profile);
136
[email protected]d1027a82014-01-27 13:22:42137// Returns list of key/value pairs for all available reported information
138// from the |profile| and some additional fields.
dcheng4af48582016-04-19 00:29:35139std::unique_ptr<base::ListValue> GetReadableFeedbackForSnapshot(
[email protected]d1027a82014-01-27 13:22:42140 Profile* profile,
141 const ResettableSettingsSnapshot& snapshot);
[email protected]3ae13e0d2014-01-14 17:58:36142
[email protected]202ab0502013-07-30 15:25:35143#endif // CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_