• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_
6 #define CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_
7 
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"
14 
15 class Profile;
16 
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
19 // settings.
20 class ProfileResetter : public base::NonThreadSafe,
21                         public BrowsingDataRemover::Observer {
22  public:
23   // Flags indicating what aspects of a profile shall be reset.
24   enum Resettable {
25     DEFAULT_SEARCH_ENGINE = 1 << 0,
26     HOMEPAGE = 1 << 1,
27     CONTENT_SETTINGS = 1 << 2,
28     COOKIES_AND_SITE_DATA = 1 << 3,
29     EXTENSIONS = 1 << 4,
30     STARTUP_PAGES = 1 << 5,
31     PINNED_TABS = 1 << 6,
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
36   };
37 
38   // Bit vector for Resettable enum.
39   typedef uint32 ResettableFlags;
40 
41   COMPILE_ASSERT(sizeof(ResettableFlags) == sizeof(Resettable),
42                  type_ResettableFlags_doesnt_match_Resettable);
43 
44   explicit ProfileResetter(Profile* profile);
45   virtual ~ProfileResetter();
46 
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);
53 
54   bool IsActive() const;
55 
56  private:
57   // Marks |resettable| as done and triggers |callback_| if all pending jobs
58   // have completed.
59   void MarkAsDone(Resettable resettable);
60 
61   void ResetDefaultSearchEngine();
62   void ResetHomepage();
63   void ResetContentSettings();
64   void ResetCookiesAndSiteData();
65   void ResetExtensions();
66   void ResetStartupPages();
67   void ResetPinnedTabs();
68 
69   // BrowsingDataRemover::Observer:
70   virtual void OnBrowsingDataRemoverDone() OVERRIDE;
71 
72   // Callback for when TemplateURLService has loaded.
73   void OnTemplateURLServiceLoaded();
74 
75   Profile* const profile_;
76   scoped_ptr<BrandcodedDefaultSettings> master_settings_;
77   TemplateURLService* template_url_service_;
78 
79   // Flags of a Resetable indicating which reset operations we are still waiting
80   // for.
81   ResettableFlags pending_reset_flags_;
82 
83   // Called on UI thread when reset has been completed.
84   base::Closure callback_;
85 
86   // If non-null it means removal is in progress. BrowsingDataRemover takes care
87   // of deleting itself when done.
88   BrowsingDataRemover* cookies_remover_;
89 
90   scoped_ptr<TemplateURLService::Subscription> template_url_service_sub_;
91 
92   DISALLOW_COPY_AND_ASSIGN(ProfileResetter);
93 };
94 
95 #endif  // CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESETTER_H_
96