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 "chrome/browser/profile_resetter/brandcoded_default_settings.h"
13 #include "chrome/browser/search_engines/template_url_service.h"
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
20 class ProfileResetter
: public base::NonThreadSafe
,
21 public BrowsingDataRemover::Observer
{
23 // Flags indicating what aspects of a profile shall be reset.
25 DEFAULT_SEARCH_ENGINE
= 1 << 0,
27 CONTENT_SETTINGS
= 1 << 2,
28 COOKIES_AND_SITE_DATA
= 1 << 3,
30 STARTUP_PAGES
= 1 << 5,
32 // Update ALL if you add new values and check whether the type of
33 // ResettableFlags needs to be enlarged.
34 ALL
= DEFAULT_SEARCH_ENGINE
| HOMEPAGE
| CONTENT_SETTINGS
|
35 COOKIES_AND_SITE_DATA
| EXTENSIONS
| STARTUP_PAGES
| PINNED_TABS
38 // Bit vector for Resettable enum.
39 typedef uint32 ResettableFlags
;
41 COMPILE_ASSERT(sizeof(ResettableFlags
) == sizeof(Resettable
),
42 type_ResettableFlags_doesnt_match_Resettable
);
44 explicit ProfileResetter(Profile
* profile
);
45 virtual ~ProfileResetter();
47 // Resets |resettable_flags| and calls |callback| on the UI thread on
48 // completion. |default_settings| allows the caller to specify some default
49 // settings. |default_settings| shouldn't be NULL.
50 void Reset(ResettableFlags resettable_flags
,
51 scoped_ptr
<BrandcodedDefaultSettings
> master_settings
,
52 const base::Closure
& callback
);
54 bool IsActive() const;
57 // Marks |resettable| as done and triggers |callback_| if all pending jobs
59 void MarkAsDone(Resettable resettable
);
61 void ResetDefaultSearchEngine();
63 void ResetContentSettings();
64 void ResetCookiesAndSiteData();
65 void ResetExtensions();
66 void ResetStartupPages();
67 void ResetPinnedTabs();
69 // BrowsingDataRemover::Observer:
70 virtual void OnBrowsingDataRemoverDone() OVERRIDE
;
72 // Callback for when TemplateURLService has loaded.
73 void OnTemplateURLServiceLoaded();
75 Profile
* const profile_
;
76 scoped_ptr
<BrandcodedDefaultSettings
> master_settings_
;
77 TemplateURLService
* template_url_service_
;
79 // Flags of a Resetable indicating which reset operations we are still waiting
81 ResettableFlags pending_reset_flags_
;
83 // Called on UI thread when reset has been completed.
84 base::Closure callback_
;
86 // If non-null it means removal is in progress. BrowsingDataRemover takes care
87 // of deleting itself when done.
88 BrowsingDataRemover
* cookies_remover_
;
90 scoped_ptr
<TemplateURLService::Subscription
> template_url_service_sub_
;
92 DISALLOW_COPY_AND_ASSIGN(ProfileResetter
);
95 #endif // CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_