OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SETTING_CHANGE_H_ | 5 #ifndef CHROME_BROWSER_PROTECTOR_SETTING_CHANGE_H_ |
6 #define CHROME_BROWSER_PROTECTOR_SETTING_CHANGE_H_ | 6 #define CHROME_BROWSER_PROTECTOR_SETTING_CHANGE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 | 14 |
15 class TemplateURL; | 15 class TemplateURL; |
16 | 16 |
17 namespace protector { | 17 namespace protector { |
18 | 18 |
19 class Protector; | 19 class Protector; |
20 | 20 |
21 // Base class for setting change tracked by Protector. | 21 // Base class for setting change tracked by Protector. |
22 class SettingChange { | 22 class SettingChange { |
23 public: | 23 public: |
24 // IDs of changes Protector currently tracks. | 24 SettingChange() {} |
25 enum Type { | |
26 // Default search engine has been changed. | |
27 kSearchEngineChanged, | |
28 | |
29 // Home page has been changed. | |
30 kHomePageChanged, | |
31 }; | |
32 | |
33 explicit SettingChange(Type type) : type_(type) {} | |
34 virtual ~SettingChange() {} | 25 virtual ~SettingChange() {} |
35 | 26 |
36 Type type() const { return type_; } | 27 // Applies initial actions to the setting if needed. Must be called before |
37 | 28 // any other calls are made, including text getters. |
38 // Returns the old setting presentation to be shown to user. | 29 virtual void Init(Protector* protector) {} |
39 // Returns empty string if the old setting is unavailable. | |
40 virtual string16 GetOldSetting() const = 0; | |
41 | |
42 // Returns the new setting presentation to be shown to user. | |
43 virtual string16 GetNewSetting() const = 0; | |
44 | 30 |
45 // Persists new setting if needed. | 31 // Persists new setting if needed. |
46 virtual void Accept(Protector* protector) {} | 32 virtual void Apply(Protector* protector) {} |
47 | 33 |
48 // Restores old setting value if needed. | 34 // Restores old setting if needed. |
49 virtual void Revert(Protector* protector) {} | 35 virtual void Discard(Protector* protector) {} |
50 | 36 |
51 // Called when user ignored the change. | 37 // Returns the wrench menu item and bubble title. |
52 virtual void DoDefault(Protector* protector) {} | 38 virtual string16 GetTitle() const = 0; |
| 39 |
| 40 // Returns the bubble message text. |
| 41 virtual string16 GetMessage() const = 0; |
| 42 |
| 43 // Returns text for the button to apply the change with |Apply|. |
| 44 // Returns empty string if no apply button should be shown. |
| 45 virtual string16 GetApplyButtonText() const = 0; |
| 46 |
| 47 // Returns text for the button to discard the change with |Discard|. |
| 48 virtual string16 GetDiscardButtonText() const = 0; |
53 | 49 |
54 private: | 50 private: |
55 // Type of the change. Used for strings lookup by UI. | |
56 // TODO(avayvod): Refactor string selection logic via polymorphism. | |
57 Type type_; | |
58 | |
59 DISALLOW_COPY_AND_ASSIGN(SettingChange); | 51 DISALLOW_COPY_AND_ASSIGN(SettingChange); |
60 }; | 52 }; |
61 | 53 |
62 typedef std::vector<SettingChange*> SettingChangeVector; | 54 // TODO(ivankr): CompositeSettingChange that incapsulates multiple |
63 typedef void (SettingChange::*SettingChangeAction)(Protector*); | 55 // SettingChange instances. |
64 | 56 |
65 // Allocates and initializes SettingChange implementation for default search | 57 // Allocates and initializes SettingChange implementation for default search |
66 // provider setting. | 58 // provider setting. Both |actual| and |backup| may be NULL if corresponding |
| 59 // values are unknown or invalid. |
67 SettingChange* CreateDefaultSearchProviderChange( | 60 SettingChange* CreateDefaultSearchProviderChange( |
68 const TemplateURL* actual, | 61 const TemplateURL* actual, |
69 const TemplateURL* backup); | 62 const TemplateURL* backup); |
70 | 63 |
71 } // namespace protector | 64 } // namespace protector |
72 | 65 |
73 #endif // CHROME_BROWSER_PROTECTOR_SETTING_CHANGE_H_ | 66 #endif // CHROME_BROWSER_PROTECTOR_SETTING_CHANGE_H_ |
OLD | NEW |