Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: chrome/browser/protector/base_setting_change.h

Issue 11493003: Remove the protector service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix implicit ExtensionSystem -> TemplateURLService dependency Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_PROTECTOR_BASE_SETTING_CHANGE_H_
6 #define CHROME_BROWSER_PROTECTOR_BASE_SETTING_CHANGE_H_
7
8 #include <utility>
9
10 #include "base/basictypes.h"
11 #include "base/string16.h"
12 #include "chrome/browser/ui/startup/startup_tab.h"
13 #include "googleurl/src/gurl.h"
14
15 class Browser;
16 class Profile;
17 class TemplateURL;
18 struct SessionStartupPref;
19
20 namespace protector {
21
22 class CompositeSettingsChange;
23
24 // Base class for setting change tracked by Protector.
25 class BaseSettingChange {
26 public:
27 // Pair consisting of a display name representing either new or backup setting
28 // and priority for it. Priority is used for composite changes, consisting
29 // of multiple BaseSettingChange instances - the display name with the highest
30 // priority is used.
31 typedef std::pair<size_t, string16> DisplayName;
32
33 // Default priority value.
34 static const size_t kDefaultNamePriority;
35
36 BaseSettingChange();
37 virtual ~BaseSettingChange();
38
39 // Merges |this| with |other| and returns a CompositeSettingsChange instance.
40 // Returned instance takes ownership of |other|.
41 // Init should not be called for the returned instance.
42 // |this| may be another CompositeSettingsChange, in which case |other| is
43 // simply added to it and |this| is returned. |other| cannot be
44 // CompositeSettingsChange.
45 virtual CompositeSettingsChange* MergeWith(BaseSettingChange* other);
46
47 // Returns true if |this| is a result of merging some changes with |other|.
48 virtual bool Contains(const BaseSettingChange* other) const;
49
50 // Applies initial actions to the setting if needed. Must be called before
51 // any other calls are made, including text getters.
52 // Returns true if initialization was successful.
53 // Associates this change with |profile| instance so overrides must call the
54 // base method.
55 virtual bool Init(Profile* profile);
56
57 // Called instead of Init when ProtectorService is disabled. No other members
58 // are called in that case.
59 virtual void InitWhenDisabled(Profile* profile);
60
61 // Persists new setting if needed. |browser| is the Browser instance from
62 // which the user action originates.
63 virtual void Apply(Browser* browser);
64
65 // Restores old setting if needed. |browser| is the Browser instance from
66 // which the user action originates.
67 virtual void Discard(Browser* browser);
68
69 // Indicates that user has ignored this change and timeout has passed.
70 virtual void Timeout();
71
72 // Returns the resource ID of the badge icon.
73 virtual int GetBadgeIconID() const = 0;
74
75 // Returns the resource ID for the menu item icon.
76 virtual int GetMenuItemIconID() const = 0;
77
78 // Returns the resource ID for bubble view icon.
79 virtual int GetBubbleIconID() const = 0;
80
81 // Returns the wrench menu item and bubble title.
82 virtual string16 GetBubbleTitle() const = 0;
83
84 // Returns the bubble message text.
85 virtual string16 GetBubbleMessage() const = 0;
86
87 // Returns text for the button to apply the change with |Apply|.
88 // Returns empty string if no apply button should be shown.
89 virtual string16 GetApplyButtonText() const = 0;
90
91 // Returns text for the button to discard the change with |Discard|.
92 virtual string16 GetDiscardButtonText() const = 0;
93
94 // Returns the display name and priority for the new setting. If multiple
95 // BaseSettingChange instances are merged into CompositeSettingsChange
96 // instance, the display name with the highest priority will be used for the
97 // Apply button (Discard button will have a generic caption in that case).
98 // Returns an empty string in |second| if there is no specific representation
99 // for new setting value and a generic string should be used.
100 virtual DisplayName GetApplyDisplayName() const;
101
102 // Returns a URL uniquely identifying new (to be applied) settings.
103 // ProtectorService uses this URLs to decide whether to merge a change
104 // with already existing active changes. The URL may be empty.
105 virtual GURL GetNewSettingURL() const;
106
107 // Returns true if this change can be merged with other changes.
108 virtual bool CanBeMerged() const;
109
110 // Returns |false| if this change is not user-visible. It won't be presented
111 // to user on it's own then, but may be merged with other changes and applied
112 // or discarded.
113 virtual bool IsUserVisible() const;
114
115 protected:
116 // Profile instance we've been associated with by an |Init| call.
117 Profile* profile() { return profile_; }
118
119 private:
120 Profile* profile_;
121
122 DISALLOW_COPY_AND_ASSIGN(BaseSettingChange);
123 };
124
125 // Display name priorities of various change types:
126 extern const size_t kDefaultSearchProviderChangeNamePriority;
127 extern const size_t kSessionStartupChangeNamePriority;
128 extern const size_t kHomepageChangeNamePriority;
129
130 // TODO(ivankr): CompositeSettingChange that incapsulates multiple
131 // BaseSettingChange instances.
132
133 // Allocates and initializes BaseSettingChange implementation for default search
134 // provider setting. Reports corresponding histograms. Both |actual| and
135 // |backup| may be NULL if corresponding values are unknown or invalid.
136 // |backup| will be owned by the returned |BaseSettingChange| instance. |actual|
137 // is not owned and is safe to destroy after Protector::ShowChange has been
138 // called for the returned instance.
139 BaseSettingChange* CreateDefaultSearchProviderChange(TemplateURL* actual,
140 TemplateURL* backup);
141
142 // Allocates and initializes BaseSettingChange implementation for session
143 // startup setting, including the pinned tabs. Reports corresponding histograms.
144 BaseSettingChange* CreateSessionStartupChange(
145 const SessionStartupPref& actual_startup_pref,
146 const StartupTabs& actual_pinned_tabs,
147 const SessionStartupPref& backup_startup_pref,
148 const StartupTabs& backup_pinned_tabs);
149
150 BaseSettingChange* CreateHomepageChange(
151 const std::string& actual_homepage,
152 bool actual_homepage_is_ntp,
153 bool actual_show_homepage,
154 const std::string& backup_homepage,
155 bool backup_homepage_is_ntp,
156 bool backup_show_homepage);
157
158 // Allocates and initializes BaseSettingChange implementation for an unknown
159 // preferences change with invalid backup.
160 BaseSettingChange* CreatePrefsBackupInvalidChange();
161
162 } // namespace protector
163
164 #endif // CHROME_BROWSER_PROTECTOR_BASE_SETTING_CHANGE_H_
OLDNEW
« no previous file with comments | « chrome/browser/protector/base_prefs_change.cc ('k') | chrome/browser/protector/base_setting_change.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698