| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_PROFILE_RESETTER_PROFILE_RESETTER_H_ | 5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_ |
| 6 #define CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_ | 6 #define CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/threading/non_thread_safe.h" | 10 #include "base/threading/non_thread_safe.h" |
| 11 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
| 12 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
| 13 | 13 |
| 14 class Profile; | 14 class Profile; |
| 15 class TemplateURLService; | 15 class TemplateURLService; |
| 16 | 16 |
| 17 // This class allows resetting certain aspects of a profile to default values. | 17 // This class allows resetting certain aspects of a profile to default values. |
| 18 // It is used in case the profile has been damaged due to malware or bad user | 18 // It is used in case the profile has been damaged due to malware or bad user |
| 19 // settings. | 19 // settings. |
| 20 class ProfileResetter : public base::NonThreadSafe, | 20 class ProfileResetter : public base::NonThreadSafe, |
| 21 public content::NotificationObserver { | 21 public content::NotificationObserver { |
| 22 public: | 22 public: |
| 23 // Flags indicating what aspects of a profile shall be reset. | 23 // Flags indicating what aspects of a profile shall be reset. |
| 24 enum Resettable { | 24 enum Resettable { |
| 25 DEFAULT_SEARCH_ENGINE = 1 << 0, | 25 DEFAULT_SEARCH_ENGINE = 1 << 0, |
| 26 HOMEPAGE = 1 << 1, | 26 HOMEPAGE = 1 << 1, |
| 27 CONTENT_SETTINGS = 1 << 2, | 27 CONTENT_SETTINGS = 1 << 2, |
| 28 COOKIES_AND_SITE_DATA = 1 << 3, | 28 COOKIES_AND_SITE_DATA = 1 << 3, |
| 29 EXTENSIONS = 1 << 4, | 29 EXTENSIONS = 1 << 4, |
| 30 STARTUP_PAGE = 1 << 5, | 30 STARTUP_PAGES = 1 << 5, |
| 31 PINNED_TABS = 1 << 6, |
| 31 // Update ALL if you add new values and check whether the type of | 32 // Update ALL if you add new values and check whether the type of |
| 32 // ResettableFlags needs to be enlarged. | 33 // ResettableFlags needs to be enlarged. |
| 33 ALL = DEFAULT_SEARCH_ENGINE | HOMEPAGE | CONTENT_SETTINGS | | 34 ALL = DEFAULT_SEARCH_ENGINE | HOMEPAGE | CONTENT_SETTINGS | |
| 34 COOKIES_AND_SITE_DATA | EXTENSIONS | STARTUP_PAGE | 35 COOKIES_AND_SITE_DATA | EXTENSIONS | STARTUP_PAGES | PINNED_TABS |
| 35 }; | |
| 36 | |
| 37 // How to handle extensions that shall be reset. | |
| 38 enum ExtensionHandling { | |
| 39 DISABLE_EXTENSIONS, | |
| 40 UNINSTALL_EXTENSIONS | |
| 41 }; | 36 }; |
| 42 | 37 |
| 43 // Bit vector for Resettable enum. | 38 // Bit vector for Resettable enum. |
| 44 typedef uint32 ResettableFlags; | 39 typedef uint32 ResettableFlags; |
| 45 | 40 |
| 46 COMPILE_ASSERT(sizeof(ResettableFlags) == sizeof(Resettable), | 41 COMPILE_ASSERT(sizeof(ResettableFlags) == sizeof(Resettable), |
| 47 type_ResettableFlags_doesnt_match_Resettable); | 42 type_ResettableFlags_doesnt_match_Resettable); |
| 48 | 43 |
| 49 explicit ProfileResetter(Profile* profile); | 44 explicit ProfileResetter(Profile* profile); |
| 50 virtual ~ProfileResetter(); | 45 virtual ~ProfileResetter(); |
| 51 | 46 |
| 52 // Resets |resettable_flags| and calls |callback| on the UI thread on | 47 // Resets |resettable_flags| and calls |callback| on the UI thread on |
| 53 // completion. If |resettable_flags| contains EXTENSIONS, these are handled | 48 // completion. If |resettable_flags| contains EXTENSIONS, these are handled |
| 54 // according to |extension_handling|. | 49 // according to |extension_handling|. |
| 55 void Reset(ResettableFlags resettable_flags, | 50 void Reset(ResettableFlags resettable_flags, |
| 56 ExtensionHandling extension_handling, | |
| 57 const base::Closure& callback); | 51 const base::Closure& callback); |
| 58 | 52 |
| 59 bool IsActive() const; | 53 bool IsActive() const; |
| 60 | 54 |
| 61 private: | 55 private: |
| 62 // Marks |resettable| as done and triggers |callback_| if all pending jobs | 56 // Marks |resettable| as done and triggers |callback_| if all pending jobs |
| 63 // have completed. | 57 // have completed. |
| 64 void MarkAsDone(Resettable resettable); | 58 void MarkAsDone(Resettable resettable); |
| 65 | 59 |
| 66 void ResetDefaultSearchEngine(); | 60 void ResetDefaultSearchEngine(); |
| 67 void ResetHomepage(); | 61 void ResetHomepage(); |
| 68 void ResetContentSettings(); | 62 void ResetContentSettings(); |
| 69 void ResetCookiesAndSiteData(); | 63 void ResetCookiesAndSiteData(); |
| 70 void ResetExtensions(ExtensionHandling extension_handling); | 64 void ResetExtensions(); |
| 71 void ResetStartPage(); | 65 void ResetStartupPages(); |
| 66 void ResetPinnedTabs(); |
| 72 | 67 |
| 73 // content::NotificationObserver: | 68 // content::NotificationObserver: |
| 74 virtual void Observe(int type, | 69 virtual void Observe(int type, |
| 75 const content::NotificationSource& source, | 70 const content::NotificationSource& source, |
| 76 const content::NotificationDetails& details) OVERRIDE; | 71 const content::NotificationDetails& details) OVERRIDE; |
| 77 | 72 |
| 78 Profile* profile_; | 73 Profile* profile_; |
| 79 TemplateURLService* template_url_service_; | 74 TemplateURLService* template_url_service_; |
| 80 | 75 |
| 81 // Flags of a Resetable indicating which reset operations we are still waiting | 76 // Flags of a Resetable indicating which reset operations we are still waiting |
| 82 // for. | 77 // for. |
| 83 ResettableFlags pending_reset_flags_; | 78 ResettableFlags pending_reset_flags_; |
| 84 | 79 |
| 85 // Called on UI thread when reset has been completed. | 80 // Called on UI thread when reset has been completed. |
| 86 base::Closure callback_; | 81 base::Closure callback_; |
| 87 | 82 |
| 88 content::NotificationRegistrar registrar_; | 83 content::NotificationRegistrar registrar_; |
| 89 | 84 |
| 90 DISALLOW_COPY_AND_ASSIGN(ProfileResetter); | 85 DISALLOW_COPY_AND_ASSIGN(ProfileResetter); |
| 91 }; | 86 }; |
| 92 | 87 |
| 93 #endif // CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_ | 88 #endif // CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_ |
| OLD | NEW |