| 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 SettingChange() {} | 24 // IDs of changes Protector currently tracks. |
| 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) {} |
| 25 virtual ~SettingChange() {} | 34 virtual ~SettingChange() {} |
| 26 | 35 |
| 27 // Applies initial actions to the setting if needed. Must be called before | 36 Type type() const { return type_; } |
| 28 // any other calls are made, including text getters. Returns true if | 37 |
| 29 // initialization was successful. | 38 // Returns the old setting presentation to be shown to user. |
| 30 virtual bool Init(Protector* protector) { return true; } | 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; |
| 31 | 44 |
| 32 // Persists new setting if needed. | 45 // Persists new setting if needed. |
| 33 virtual void Apply(Protector* protector) {} | 46 virtual void Accept(Protector* protector) {} |
| 34 | 47 |
| 35 // Restores old setting if needed. | 48 // Restores old setting value if needed. |
| 36 virtual void Discard(Protector* protector) {} | 49 virtual void Revert(Protector* protector) {} |
| 37 | 50 |
| 38 // Returns the wrench menu item and bubble title. | 51 // Called when user ignored the change. |
| 39 virtual string16 GetTitle() const = 0; | 52 virtual void DoDefault(Protector* protector) {} |
| 40 | |
| 41 // Returns the bubble message text. | |
| 42 virtual string16 GetMessage() const = 0; | |
| 43 | |
| 44 // Returns text for the button to apply the change with |Apply|. | |
| 45 // Returns empty string if no apply button should be shown. | |
| 46 virtual string16 GetApplyButtonText() const = 0; | |
| 47 | |
| 48 // Returns text for the button to discard the change with |Discard|. | |
| 49 virtual string16 GetDiscardButtonText() const = 0; | |
| 50 | 53 |
| 51 private: | 54 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 |
| 52 DISALLOW_COPY_AND_ASSIGN(SettingChange); | 59 DISALLOW_COPY_AND_ASSIGN(SettingChange); |
| 53 }; | 60 }; |
| 54 | 61 |
| 55 // TODO(ivankr): CompositeSettingChange that incapsulates multiple | 62 typedef std::vector<SettingChange*> SettingChangeVector; |
| 56 // SettingChange instances. | 63 typedef void (SettingChange::*SettingChangeAction)(Protector*); |
| 57 | 64 |
| 58 // Allocates and initializes SettingChange implementation for default search | 65 // Allocates and initializes SettingChange implementation for default search |
| 59 // provider setting. Both |actual| and |backup| may be NULL if corresponding | 66 // provider setting. |
| 60 // values are unknown or invalid. | |
| 61 SettingChange* CreateDefaultSearchProviderChange( | 67 SettingChange* CreateDefaultSearchProviderChange( |
| 62 const TemplateURL* actual, | 68 const TemplateURL* actual, |
| 63 const TemplateURL* backup); | 69 const TemplateURL* backup); |
| 64 | 70 |
| 65 } // namespace protector | 71 } // namespace protector |
| 66 | 72 |
| 67 #endif // CHROME_BROWSER_PROTECTOR_SETTING_CHANGE_H_ | 73 #endif // CHROME_BROWSER_PROTECTOR_SETTING_CHANGE_H_ |
| OLD | NEW |