1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_
#define CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Profile;
class TemplateURLService;
// This class allows resetting certain aspects of a profile to default values.
// It is used in case the profile has been damaged due to malware or bad user
// settings.
class ProfileResetter : public base::NonThreadSafe,
public content::NotificationObserver,
public BrowsingDataRemover::Observer {
public:
// Flags indicating what aspects of a profile shall be reset.
enum Resettable {
DEFAULT_SEARCH_ENGINE = 1 << 0,
HOMEPAGE = 1 << 1,
CONTENT_SETTINGS = 1 << 2,
COOKIES_AND_SITE_DATA = 1 << 3,
EXTENSIONS = 1 << 4,
STARTUP_PAGES = 1 << 5,
PINNED_TABS = 1 << 6,
// Update ALL if you add new values and check whether the type of
// ResettableFlags needs to be enlarged.
ALL = DEFAULT_SEARCH_ENGINE | HOMEPAGE | CONTENT_SETTINGS |
COOKIES_AND_SITE_DATA | EXTENSIONS | STARTUP_PAGES | PINNED_TABS
};
// Bit vector for Resettable enum.
typedef uint32 ResettableFlags;
COMPILE_ASSERT(sizeof(ResettableFlags) == sizeof(Resettable),
type_ResettableFlags_doesnt_match_Resettable);
explicit ProfileResetter(Profile* profile);
virtual ~ProfileResetter();
// Resets |resettable_flags| and calls |callback| on the UI thread on
// completion. |default_settings| allows the caller to specify some default
// settings. |default_settings| shouldn't be NULL.
void Reset(ResettableFlags resettable_flags,
scoped_ptr<BrandcodedDefaultSettings> master_settings,
const base::Closure& callback);
bool IsActive() const;
private:
// Marks |resettable| as done and triggers |callback_| if all pending jobs
// have completed.
void MarkAsDone(Resettable resettable);
void ResetDefaultSearchEngine();
void ResetHomepage();
void ResetContentSettings();
void ResetCookiesAndSiteData();
void ResetExtensions();
void ResetStartupPages();
void ResetPinnedTabs();
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// BrowsingDataRemover::Observer:
virtual void OnBrowsingDataRemoverDone() OVERRIDE;
Profile* const profile_;
scoped_ptr<BrandcodedDefaultSettings> master_settings_;
TemplateURLService* template_url_service_;
// Flags of a Resetable indicating which reset operations we are still waiting
// for.
ResettableFlags pending_reset_flags_;
// Called on UI thread when reset has been completed.
base::Closure callback_;
content::NotificationRegistrar registrar_;
// If non-null it means removal is in progress. BrowsingDataRemover takes care
// of deleting itself when done.
BrowsingDataRemover* cookies_remover_;
DISALLOW_COPY_AND_ASSIGN(ProfileResetter);
};
#endif // CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_
|