Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / profile_resetter / profile_resetter.h
blobb4044fad499b41de11c241bc0ceed85773a303ed
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 <utility>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/strings/string16.h"
18 #include "base/threading/non_thread_safe.h"
19 #include "chrome/browser/browsing_data/browsing_data_remover.h"
20 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
21 #include "components/search_engines/template_url_service.h"
23 class Profile;
25 namespace base {
26 class CancellationFlag;
29 // This class allows resetting certain aspects of a profile to default values.
30 // It is used in case the profile has been damaged due to malware or bad user
31 // settings.
32 class ProfileResetter : public base::NonThreadSafe,
33 public BrowsingDataRemover::Observer {
34 public:
35 // Flags indicating what aspects of a profile shall be reset.
36 enum Resettable {
37 DEFAULT_SEARCH_ENGINE = 1 << 0,
38 HOMEPAGE = 1 << 1,
39 CONTENT_SETTINGS = 1 << 2,
40 COOKIES_AND_SITE_DATA = 1 << 3,
41 EXTENSIONS = 1 << 4,
42 STARTUP_PAGES = 1 << 5,
43 PINNED_TABS = 1 << 6,
44 SHORTCUTS = 1 << 7,
45 // Update ALL if you add new values and check whether the type of
46 // ResettableFlags needs to be enlarged.
47 ALL = DEFAULT_SEARCH_ENGINE | HOMEPAGE | CONTENT_SETTINGS |
48 COOKIES_AND_SITE_DATA | EXTENSIONS | STARTUP_PAGES | PINNED_TABS |
49 SHORTCUTS
52 // Bit vector for Resettable enum.
53 typedef uint32 ResettableFlags;
55 static_assert(sizeof(ResettableFlags) == sizeof(Resettable),
56 "ResettableFlags should be the same size as Resettable");
58 explicit ProfileResetter(Profile* profile);
59 ~ProfileResetter() override;
61 // Resets |resettable_flags| and calls |callback| on the UI thread on
62 // completion. |default_settings| allows the caller to specify some default
63 // settings. |default_settings| shouldn't be NULL. |accepted_send_feedback|
64 // identifies whether the user accepted to send feedback or not.
65 void Reset(ResettableFlags resettable_flags,
66 scoped_ptr<BrandcodedDefaultSettings> master_settings,
67 bool accepted_send_feedback,
68 const base::Closure& callback);
70 bool IsActive() const;
72 private:
73 // Marks |resettable| as done and triggers |callback_| if all pending jobs
74 // have completed.
75 void MarkAsDone(Resettable resettable);
77 void ResetDefaultSearchEngine();
78 void ResetHomepage();
79 void ResetContentSettings();
80 void ResetCookiesAndSiteData();
81 void ResetExtensions();
82 void ResetStartupPages();
83 void ResetPinnedTabs();
84 void ResetShortcuts();
86 // BrowsingDataRemover::Observer:
87 void OnBrowsingDataRemoverDone() override;
89 // Callback for when TemplateURLService has loaded.
90 void OnTemplateURLServiceLoaded();
92 Profile* const profile_;
93 scoped_ptr<BrandcodedDefaultSettings> master_settings_;
94 TemplateURLService* template_url_service_;
96 // Flags of a Resetable indicating which reset operations we are still waiting
97 // for.
98 ResettableFlags pending_reset_flags_;
100 // Called on UI thread when reset has been completed.
101 base::Closure callback_;
103 // If non-null it means removal is in progress. BrowsingDataRemover takes care
104 // of deleting itself when done.
105 BrowsingDataRemover* cookies_remover_;
107 scoped_ptr<TemplateURLService::Subscription> template_url_service_sub_;
109 base::WeakPtrFactory<ProfileResetter> weak_ptr_factory_;
111 DISALLOW_COPY_AND_ASSIGN(ProfileResetter);
114 // Path to shortcut and command line arguments.
115 typedef std::pair<base::FilePath, base::string16> ShortcutCommand;
117 typedef base::RefCountedData<base::CancellationFlag> SharedCancellationFlag;
119 // On Windows returns all the shortcuts which launch Chrome and corresponding
120 // arguments. |cancel| can be passed to abort the operation earlier.
121 // Call on FILE thread.
122 std::vector<ShortcutCommand> GetChromeLaunchShortcuts(
123 const scoped_refptr<SharedCancellationFlag>& cancel);
125 #endif // CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_