Chromium Code Reviews| 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> | |
| 10 | |
| 11 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | |
| 13 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 14 #include "base/string16.h" | |
| 15 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "chrome/browser/protector/setting_change.h" | |
| 16 #include "chrome/browser/ui/global_error.h" | 13 #include "chrome/browser/ui/global_error.h" |
| 17 | 14 |
| 15 class Browser; | |
| 18 class Profile; | 16 class Profile; |
| 19 | 17 |
| 18 namespace protector { | |
| 19 | |
| 20 // Global error about unwanted settings changes. | 20 // Global error about unwanted settings changes. |
| 21 class SettingsChangeGlobalError : public GlobalError { | 21 class SettingsChangeGlobalError : public GlobalError { |
| 22 public: | 22 public: |
| 23 enum ChangeType { | 23 // Interface for notifications about bubble closing. |
| 24 kSearchEngineChanged = 0, // Default search engine has been changed. | 24 class Delegate { |
|
sky
2011/10/21 21:34:11
This should be in its own header so that you don't
whywhat
2011/10/24 15:30:17
Done.
| |
| 25 kHomePageChanged, // Home page has been changed. | 25 public: |
| 26 virtual ~Delegate() {} | |
| 27 | |
| 28 // Called if user clicks "Apply change" button. | |
| 29 virtual void OnApplyChanges() = 0; | |
| 30 | |
| 31 // Called if user clicks "Discard change" button. | |
| 32 virtual void OnDiscardChanges() = 0; | |
| 33 | |
| 34 // Called if user clicked outside the bubble and timeout for its reshow | |
| 35 // has passed. | |
| 36 virtual void OnDecisionTimeout() = 0; | |
| 26 }; | 37 }; |
| 27 | 38 |
| 28 struct Change { | 39 // Creates new global error about settings changes |changes|. Takes |
| 29 ChangeType type; // Which setting has been changed. | 40 // ownership over |changes| contents. |
| 30 string16 old_setting; // Old setting value or "" if unknown. | 41 // Uses |delegate| to notify about user decision. |
| 31 string16 new_setting; // New setting value. | 42 SettingsChangeGlobalError(const SettingChangeVector& changes, |
| 32 }; | 43 Delegate* delegate); |
| 33 | |
| 34 typedef std::vector<Change> ChangesVector; | |
| 35 | |
| 36 // Creates new global error about settings changes |changes|. | |
| 37 // If user decides to apply changes, |apply_changes_cb| is called. | |
| 38 // If user decides to keep previous settings, |revert_changes_cb| is called. | |
| 39 SettingsChangeGlobalError(const ChangesVector& changes, | |
| 40 const base::Closure& apply_changes_cb, | |
| 41 const base::Closure& revert_changes_cb); | |
| 42 virtual ~SettingsChangeGlobalError(); | 44 virtual ~SettingsChangeGlobalError(); |
| 43 | 45 |
| 44 // Displays a global error bubble for the default browser profile. | 46 // Displays a global error bubble for the given browser profile. |
| 45 // Can be called from any thread. | 47 // Can be called from any thread. |
| 46 void ShowForDefaultProfile(); | 48 void ShowForProfile(Profile* profile); |
| 49 | |
| 50 // Browser that the bubble has been last time shown for. | |
| 51 Browser* browser() const { return browser_; } | |
| 52 | |
| 53 SettingChangeVector* mutable_changes() { return &changes_; } | |
| 47 | 54 |
| 48 // GlobalError implementation. | 55 // GlobalError implementation. |
| 49 virtual bool HasBadge() OVERRIDE; | 56 virtual bool HasBadge() OVERRIDE; |
| 50 virtual bool HasMenuItem() OVERRIDE; | 57 virtual bool HasMenuItem() OVERRIDE; |
| 51 virtual int MenuItemCommandID() OVERRIDE; | 58 virtual int MenuItemCommandID() OVERRIDE; |
| 52 virtual string16 MenuItemLabel() OVERRIDE; | 59 virtual string16 MenuItemLabel() OVERRIDE; |
| 53 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; | 60 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; |
| 54 virtual bool HasBubbleView() OVERRIDE; | 61 virtual bool HasBubbleView() OVERRIDE; |
| 55 virtual string16 GetBubbleViewTitle() OVERRIDE; | 62 virtual string16 GetBubbleViewTitle() OVERRIDE; |
| 56 virtual string16 GetBubbleViewMessage() OVERRIDE; | 63 virtual string16 GetBubbleViewMessage() OVERRIDE; |
| 57 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; | 64 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; |
| 58 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; | 65 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; |
| 59 virtual bool IsAcceptButtonDefault() OVERRIDE; | 66 virtual bool IsAcceptButtonDefault() OVERRIDE; |
| 60 virtual void BubbleViewDidClose() OVERRIDE; | 67 virtual void BubbleViewDidClose() OVERRIDE; |
| 61 virtual void BubbleViewAcceptButtonPressed() OVERRIDE; | 68 virtual void BubbleViewAcceptButtonPressed() OVERRIDE; |
| 62 virtual void BubbleViewCancelButtonPressed() OVERRIDE; | 69 virtual void BubbleViewCancelButtonPressed() OVERRIDE; |
| 63 | 70 |
| 64 private: | 71 private: |
| 65 ChangesVector changes_; | |
| 66 | |
| 67 base::Closure apply_changes_cb_; | |
| 68 base::Closure revert_changes_cb_; | |
| 69 | |
| 70 // Profile that we have been added to. | |
| 71 Profile* profile_; | |
| 72 | |
| 73 // True if user has dismissed the bubble by clicking on one of the buttons. | |
| 74 bool closed_by_button_; | |
| 75 | |
| 76 base::WeakPtrFactory<SettingsChangeGlobalError> weak_factory_; | |
| 77 | |
| 78 // Helper called on the UI thread to add this global error to the default | 72 // Helper called on the UI thread to add this global error to the default |
| 79 // profile (stored in |profile_|). | 73 // profile (stored in |profile_|). |
| 80 void AddToDefaultProfile(); | 74 void AddToProfile(Profile* profile); |
| 81 | 75 |
| 82 // Displays global error bubble. Must be called on the UI thread. | 76 // Displays global error bubble. Must be called on the UI thread. |
| 83 void Show(); | 77 void Show(); |
| 84 | 78 |
| 85 // Removes global error from its profile and deletes |this| later. | 79 // Removes global error from its profile and deletes |this| later. |
| 86 void RemoveFromProfile(); | 80 void RemoveFromProfile(); |
| 87 | 81 |
| 82 // List of changes to show. | |
| 83 SettingChangeVector changes_; | |
| 84 | |
| 85 // Delegate to notify about user actions. | |
| 86 Delegate* delegate_; | |
| 87 | |
| 88 // Profile that we have been added to. | |
| 89 Profile* profile_; | |
| 90 | |
| 91 // Browser that we have been shown for. | |
| 92 Browser* browser_; | |
| 93 | |
| 94 // True if user has dismissed the bubble by clicking on one of the buttons. | |
| 95 bool closed_by_button_; | |
| 96 | |
| 97 base::WeakPtrFactory<SettingsChangeGlobalError> weak_factory_; | |
| 98 | |
| 88 DISALLOW_COPY_AND_ASSIGN(SettingsChangeGlobalError); | 99 DISALLOW_COPY_AND_ASSIGN(SettingsChangeGlobalError); |
| 89 }; | 100 }; |
| 90 | 101 |
| 102 } // namespace protector | |
| 103 | |
| 91 #endif // CHROME_BROWSER_PROTECTOR_SETTINGS_CHANGE_GLOBAL_ERROR_H_ | 104 #endif // CHROME_BROWSER_PROTECTOR_SETTINGS_CHANGE_GLOBAL_ERROR_H_ |
| OLD | NEW |