Reset profile: reset cookies and site data.
[chromium-blink-merge.git] / chrome / browser / profile_resetter / profile_resetter.h
blob492d6f6d04971da476d0d5b0a0ca6c7a388aa061
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_
6 #define CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "chrome/browser/browsing_data/browsing_data_remover.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
15 class Profile;
16 class TemplateURLService;
18 // This class allows resetting certain aspects of a profile to default values.
19 // It is used in case the profile has been damaged due to malware or bad user
20 // settings.
21 class ProfileResetter : public base::NonThreadSafe,
22 public content::NotificationObserver,
23 public BrowsingDataRemover::Observer {
24 public:
25 // Flags indicating what aspects of a profile shall be reset.
26 enum Resettable {
27 DEFAULT_SEARCH_ENGINE = 1 << 0,
28 HOMEPAGE = 1 << 1,
29 CONTENT_SETTINGS = 1 << 2,
30 COOKIES_AND_SITE_DATA = 1 << 3,
31 EXTENSIONS = 1 << 4,
32 STARTUP_PAGES = 1 << 5,
33 PINNED_TABS = 1 << 6,
34 // Update ALL if you add new values and check whether the type of
35 // ResettableFlags needs to be enlarged.
36 ALL = DEFAULT_SEARCH_ENGINE | HOMEPAGE | CONTENT_SETTINGS |
37 COOKIES_AND_SITE_DATA | EXTENSIONS | STARTUP_PAGES | PINNED_TABS
40 // Bit vector for Resettable enum.
41 typedef uint32 ResettableFlags;
43 COMPILE_ASSERT(sizeof(ResettableFlags) == sizeof(Resettable),
44 type_ResettableFlags_doesnt_match_Resettable);
46 explicit ProfileResetter(Profile* profile);
47 virtual ~ProfileResetter();
49 // Resets |resettable_flags| and calls |callback| on the UI thread on
50 // completion. If |resettable_flags| contains EXTENSIONS, these are handled
51 // according to |extension_handling|.
52 void Reset(ResettableFlags resettable_flags,
53 const base::Closure& callback);
55 bool IsActive() const;
57 private:
58 // Marks |resettable| as done and triggers |callback_| if all pending jobs
59 // have completed.
60 void MarkAsDone(Resettable resettable);
62 void ResetDefaultSearchEngine();
63 void ResetHomepage();
64 void ResetContentSettings();
65 void ResetCookiesAndSiteData();
66 void ResetExtensions();
67 void ResetStartupPages();
68 void ResetPinnedTabs();
70 // content::NotificationObserver:
71 virtual void Observe(int type,
72 const content::NotificationSource& source,
73 const content::NotificationDetails& details) OVERRIDE;
75 // BrowsingDataRemover::Observer:
76 virtual void OnBrowsingDataRemoverDone() OVERRIDE;
78 Profile* profile_;
79 TemplateURLService* template_url_service_;
81 // Flags of a Resetable indicating which reset operations we are still waiting
82 // for.
83 ResettableFlags pending_reset_flags_;
85 // Called on UI thread when reset has been completed.
86 base::Closure callback_;
88 content::NotificationRegistrar registrar_;
90 // If non-null it means removal is in progress. BrowsingDataRemover takes care
91 // of deleting itself when done.
92 BrowsingDataRemover* cookies_remover_;
94 DISALLOW_COPY_AND_ASSIGN(ProfileResetter);
97 #endif // CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_