| 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_SETTINGS_CHANGE_GLOBAL_ERROR_H_ | 5 #ifndef CHROME_BROWSER_PROTECTOR_SETTINGS_CHANGE_GLOBAL_ERROR_H_ |
| 6 #define CHROME_BROWSER_PROTECTOR_SETTINGS_CHANGE_GLOBAL_ERROR_H_ | 6 #define CHROME_BROWSER_PROTECTOR_SETTINGS_CHANGE_GLOBAL_ERROR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "chrome/browser/protector/protector.h" |
| 16 #include "chrome/browser/ui/global_error.h" | 17 #include "chrome/browser/ui/global_error.h" |
| 17 | 18 |
| 19 class Browser; |
| 18 class Profile; | 20 class Profile; |
| 19 | 21 |
| 22 namespace protector { |
| 23 |
| 20 // Global error about unwanted settings changes. | 24 // Global error about unwanted settings changes. |
| 21 class SettingsChangeGlobalError : public GlobalError { | 25 class SettingsChangeGlobalError : public GlobalError { |
| 22 public: | 26 public: |
| 23 enum ChangeType { | |
| 24 kSearchEngineChanged = 0, // Default search engine has been changed. | |
| 25 kHomePageChanged, // Home page has been changed. | |
| 26 }; | |
| 27 | |
| 28 struct Change { | |
| 29 ChangeType type; // Which setting has been changed. | |
| 30 string16 old_setting; // Old setting value or "" if unknown. | |
| 31 string16 new_setting; // New setting value. | |
| 32 }; | |
| 33 | |
| 34 typedef std::vector<Change> ChangesVector; | |
| 35 | |
| 36 // Creates new global error about settings changes |changes|. | 27 // Creates new global error about settings changes |changes|. |
| 37 // If user decides to apply changes, |apply_changes_cb| is called. | 28 // If user decides to apply changes, |apply_changes_cb| is called. |
| 38 // If user decides to keep previous settings, |revert_changes_cb| is called. | 29 // If user decides to keep previous settings, |revert_changes_cb| is called. |
| 39 SettingsChangeGlobalError(const ChangesVector& changes, | 30 SettingsChangeGlobalError(const ChangesVector& changes, |
| 40 const base::Closure& apply_changes_cb, | 31 const base::Closure& apply_changes_cb, |
| 41 const base::Closure& revert_changes_cb); | 32 const base::Closure& revert_changes_cb); |
| 42 virtual ~SettingsChangeGlobalError(); | 33 virtual ~SettingsChangeGlobalError(); |
| 43 | 34 |
| 44 // Displays a global error bubble for the default browser profile. | 35 // Displays a global error bubble for the default browser profile. |
| 45 // Can be called from any thread. | 36 // Can be called from any thread. |
| 46 void ShowForDefaultProfile(); | 37 void ShowForDefaultProfile(); |
| 47 | 38 |
| 39 Profile* profile() const { return profile_; } |
| 40 Browser* browser() const { return browser_; } |
| 41 |
| 48 // GlobalError implementation. | 42 // GlobalError implementation. |
| 49 virtual bool HasBadge() OVERRIDE; | 43 virtual bool HasBadge() OVERRIDE; |
| 50 virtual bool HasMenuItem() OVERRIDE; | 44 virtual bool HasMenuItem() OVERRIDE; |
| 51 virtual int MenuItemCommandID() OVERRIDE; | 45 virtual int MenuItemCommandID() OVERRIDE; |
| 52 virtual string16 MenuItemLabel() OVERRIDE; | 46 virtual string16 MenuItemLabel() OVERRIDE; |
| 53 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; | 47 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; |
| 54 virtual bool HasBubbleView() OVERRIDE; | 48 virtual bool HasBubbleView() OVERRIDE; |
| 55 virtual string16 GetBubbleViewTitle() OVERRIDE; | 49 virtual string16 GetBubbleViewTitle() OVERRIDE; |
| 56 virtual string16 GetBubbleViewMessage() OVERRIDE; | 50 virtual string16 GetBubbleViewMessage() OVERRIDE; |
| 57 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; | 51 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; |
| 58 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; | 52 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; |
| 59 virtual bool IsAcceptButtonDefault() OVERRIDE; | 53 virtual bool IsAcceptButtonDefault() OVERRIDE; |
| 60 virtual void BubbleViewDidClose() OVERRIDE; | 54 virtual void BubbleViewDidClose() OVERRIDE; |
| 61 virtual void BubbleViewAcceptButtonPressed() OVERRIDE; | 55 virtual void BubbleViewAcceptButtonPressed() OVERRIDE; |
| 62 virtual void BubbleViewCancelButtonPressed() OVERRIDE; | 56 virtual void BubbleViewCancelButtonPressed() OVERRIDE; |
| 63 | 57 |
| 64 private: | 58 private: |
| 65 ChangesVector changes_; | 59 Protector::ChangesVector changes_; |
| 66 | 60 |
| 67 base::Closure apply_changes_cb_; | 61 base::Closure apply_changes_cb_; |
| 68 base::Closure revert_changes_cb_; | 62 base::Closure revert_changes_cb_; |
| 69 | 63 |
| 70 // Profile that we have been added to. | 64 // Profile that we have been added to. |
| 71 Profile* profile_; | 65 Profile* profile_; |
| 72 | 66 |
| 67 // Browser that we have been shown for. |
| 68 Browser* browser_; |
| 69 |
| 73 // True if user has dismissed the bubble by clicking on one of the buttons. | 70 // True if user has dismissed the bubble by clicking on one of the buttons. |
| 74 bool closed_by_button_; | 71 bool closed_by_button_; |
| 75 | 72 |
| 76 base::WeakPtrFactory<SettingsChangeGlobalError> weak_factory_; | 73 base::WeakPtrFactory<SettingsChangeGlobalError> weak_factory_; |
| 77 | 74 |
| 78 // Helper called on the UI thread to add this global error to the default | 75 // Helper called on the UI thread to add this global error to the default |
| 79 // profile (stored in |profile_|). | 76 // profile (stored in |profile_|). |
| 80 void AddToDefaultProfile(); | 77 void AddToDefaultProfile(); |
| 81 | 78 |
| 82 // Displays global error bubble. Must be called on the UI thread. | 79 // Displays global error bubble. Must be called on the UI thread. |
| 83 void Show(); | 80 void Show(); |
| 84 | 81 |
| 85 // Removes global error from its profile and deletes |this| later. | 82 // Removes global error from its profile and deletes |this| later. |
| 86 void RemoveFromProfile(); | 83 void RemoveFromProfile(); |
| 87 | 84 |
| 88 DISALLOW_COPY_AND_ASSIGN(SettingsChangeGlobalError); | 85 DISALLOW_COPY_AND_ASSIGN(SettingsChangeGlobalError); |
| 89 }; | 86 }; |
| 90 | 87 |
| 88 } // namespace protector |
| 89 |
| 91 #endif // CHROME_BROWSER_PROTECTOR_SETTINGS_CHANGE_GLOBAL_ERROR_H_ | 90 #endif // CHROME_BROWSER_PROTECTOR_SETTINGS_CHANGE_GLOBAL_ERROR_H_ |
| OLD | NEW |