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

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

Issue 9968007: [protector] Support for collapsing multiple changes into a single one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 8 years, 8 months 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
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/protector/base_setting_change.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PROTECTOR_BASE_SETTING_CHANGE_H_ 5 #ifndef CHROME_BROWSER_PROTECTOR_BASE_SETTING_CHANGE_H_
6 #define CHROME_BROWSER_PROTECTOR_BASE_SETTING_CHANGE_H_ 6 #define CHROME_BROWSER_PROTECTOR_BASE_SETTING_CHANGE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <utility>
10 #include <vector>
11 10
12 #include "base/basictypes.h" 11 #include "base/basictypes.h"
13 #include "base/string16.h" 12 #include "base/string16.h"
14 #include "chrome/browser/tabs/pinned_tab_codec.h" 13 #include "chrome/browser/tabs/pinned_tab_codec.h"
14 #include "googleurl/src/gurl.h"
15 15
16 class Browser; 16 class Browser;
17 class Profile; 17 class Profile;
18 class TemplateURL; 18 class TemplateURL;
19 struct SessionStartupPref; 19 struct SessionStartupPref;
20 20
21 namespace protector { 21 namespace protector {
22 22
23 class CompositeSettingsChange;
24
23 // Base class for setting change tracked by Protector. 25 // Base class for setting change tracked by Protector.
24 class BaseSettingChange { 26 class BaseSettingChange {
25 public: 27 public:
28 // Pair consisting of a display name representing either new or backup setting
29 // and priority for it. Priority is used for composite changes, consisting
30 // of multiple BaseSettingChange instances - the display name with the highest
31 // priority is used.
32 typedef std::pair<size_t, string16> DisplayName;
33
34 // Default priority value.
35 static const size_t kDefaultNamePriority;
36
26 BaseSettingChange(); 37 BaseSettingChange();
27 virtual ~BaseSettingChange(); 38 virtual ~BaseSettingChange();
28 39
40 // Merges |this| with |other| and returns a CompositeSettingsChange instance.
41 // Returned instance takes ownership of |other|.
42 // Init should not be called for the returned instance.
43 // |this| may be another CompositeSettingsChange, in which case |other| is
44 // simply added to it and |this| is returned. |other| cannot be
45 // CompositeSettingsChange.
46 virtual CompositeSettingsChange* MergeWith(BaseSettingChange* other);
47
48 // Returns true if |this| is a result of merging some changes with |other|.
49 virtual bool Contains(const BaseSettingChange* other) const;
50
29 // Applies initial actions to the setting if needed. Must be called before 51 // Applies initial actions to the setting if needed. Must be called before
30 // any other calls are made, including text getters. 52 // any other calls are made, including text getters.
31 // Returns true if initialization was successful. 53 // Returns true if initialization was successful.
32 // Associates this change with |profile| instance so overrides must call the 54 // Associates this change with |profile| instance so overrides must call the
33 // base method. 55 // base method.
34 virtual bool Init(Profile* profile); 56 virtual bool Init(Profile* profile);
35 57
36 // Persists new setting if needed. |browser| is the Browser instance from 58 // Persists new setting if needed. |browser| is the Browser instance from
37 // which the user action originates. 59 // which the user action originates.
38 virtual void Apply(Browser* browser); 60 virtual void Apply(Browser* browser);
(...skipping 20 matching lines...) Expand all
59 // Returns the bubble message text. 81 // Returns the bubble message text.
60 virtual string16 GetBubbleMessage() const = 0; 82 virtual string16 GetBubbleMessage() const = 0;
61 83
62 // Returns text for the button to apply the change with |Apply|. 84 // Returns text for the button to apply the change with |Apply|.
63 // Returns empty string if no apply button should be shown. 85 // Returns empty string if no apply button should be shown.
64 virtual string16 GetApplyButtonText() const = 0; 86 virtual string16 GetApplyButtonText() const = 0;
65 87
66 // Returns text for the button to discard the change with |Discard|. 88 // Returns text for the button to discard the change with |Discard|.
67 virtual string16 GetDiscardButtonText() const = 0; 89 virtual string16 GetDiscardButtonText() const = 0;
68 90
91 // Returns the display name and priority for the new setting. If multiple
92 // BaseSettingChange instances are merged into CompositeSettingsChange
93 // instance, the display name with the highest priority will be used for the
94 // Apply button (Discard button will have a generic caption in that case).
95 // Returns an empty string in |second| if there is no specific representation
96 // for new setting value and a generic string should be used.
97 virtual DisplayName GetApplyDisplayName() const;
98
99 // Returns a URL uniquely identifying new (to be applied) settings.
100 // ProtectorService uses this URLs to decide whether to merge a change
101 // with already existing active changes. The URL may be empty.
102 virtual GURL GetNewSettingURL() const;
103
104 // Returns true if this change can be merged with other changes.
105 virtual bool CanBeMerged() const;
106
69 protected: 107 protected:
70 // Profile instance we've been associated with by an |Init| call. 108 // Profile instance we've been associated with by an |Init| call.
71 Profile* profile() { return profile_; } 109 Profile* profile() { return profile_; }
72 110
73 private: 111 private:
74 Profile* profile_; 112 Profile* profile_;
75 113
76 DISALLOW_COPY_AND_ASSIGN(BaseSettingChange); 114 DISALLOW_COPY_AND_ASSIGN(BaseSettingChange);
77 }; 115 };
78 116
117 // Display name priorities of various change types:
118 extern const size_t kDefaultSearchProviderChangeNamePriority;
119 extern const size_t kSessionStartupChangeNamePriority;
120
79 // TODO(ivankr): CompositeSettingChange that incapsulates multiple 121 // TODO(ivankr): CompositeSettingChange that incapsulates multiple
80 // BaseSettingChange instances. 122 // BaseSettingChange instances.
81 123
82 // Allocates and initializes BaseSettingChange implementation for default search 124 // Allocates and initializes BaseSettingChange implementation for default search
83 // provider setting. Reports corresponding histograms. Both |actual| and 125 // provider setting. Reports corresponding histograms. Both |actual| and
84 // |backup| may be NULL if corresponding values are unknown or invalid. 126 // |backup| may be NULL if corresponding values are unknown or invalid.
85 // |backup| will be owned by the returned |BaseSettingChange| instance. |actual| 127 // |backup| will be owned by the returned |BaseSettingChange| instance. |actual|
86 // is not owned and is safe to destroy after Protector::ShowChange has been 128 // is not owned and is safe to destroy after Protector::ShowChange has been
87 // called for the returned instance. 129 // called for the returned instance.
88 BaseSettingChange* CreateDefaultSearchProviderChange(const TemplateURL* actual, 130 BaseSettingChange* CreateDefaultSearchProviderChange(const TemplateURL* actual,
89 TemplateURL* backup); 131 TemplateURL* backup);
90 132
91 // Allocates and initializes BaseSettingChange implementation for session 133 // Allocates and initializes BaseSettingChange implementation for session
92 // startup setting, including the pinned tabs. Reports corresponding histograms. 134 // startup setting, including the pinned tabs. Reports corresponding histograms.
93 BaseSettingChange* CreateSessionStartupChange( 135 BaseSettingChange* CreateSessionStartupChange(
94 const SessionStartupPref& actual_startup_pref, 136 const SessionStartupPref& actual_startup_pref,
95 const PinnedTabCodec::Tabs& actual_pinned_tabs, 137 const PinnedTabCodec::Tabs& actual_pinned_tabs,
96 const SessionStartupPref& backup_startup_pref, 138 const SessionStartupPref& backup_startup_pref,
97 const PinnedTabCodec::Tabs& backup_pinned_tabs); 139 const PinnedTabCodec::Tabs& backup_pinned_tabs);
98 140
99 // Allocates and initializes BaseSettingChange implementation for an unknown 141 // Allocates and initializes BaseSettingChange implementation for an unknown
100 // preferences change with invalid backup. 142 // preferences change with invalid backup.
101 BaseSettingChange* CreatePrefsBackupInvalidChange(); 143 BaseSettingChange* CreatePrefsBackupInvalidChange();
102 144
103 } // namespace protector 145 } // namespace protector
104 146
105 #endif // CHROME_BROWSER_PROTECTOR_BASE_SETTING_CHANGE_H_ 147 #endif // CHROME_BROWSER_PROTECTOR_BASE_SETTING_CHANGE_H_
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/protector/base_setting_change.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698