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