1 // Copyright 2015 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_TRIGGERED_PROFILE_RESETTER_H_ 6 #define CHROME_BROWSER_PROFILE_RESETTER_TRIGGERED_PROFILE_RESETTER_H_ 7 8 #include <stddef.h> 9 10 #include "base/macros.h" 11 #include "base/strings/string16.h" 12 #include "build/build_config.h" 13 #include "components/keyed_service/core/keyed_service.h" 14 15 class Profile; 16 17 // This service is responsible for evaluating whether a profile reset trigger 18 // has been set and not yet consumed by |profile_|. If it has, the profile is 19 // eligible for reset and a profile reset UI will be shown to the user. The 20 // intended use case for this is to provide a sanctioned profile reset API for 21 // third party tools (anti-virus or cleaner tools) that wish to reset users' 22 // profiles as part of their cleanup flow. 23 // 24 // To use this mechanism from a third party tool, perform the following steps: 25 // 1) Create (or open) the registry key 26 // HKCU\Software\$PRODUCT_NAME\TriggeredReset where $PRODUCT_NAME is one 27 // of the values "Google\\Chrome" or "Chromium". 28 // 2) Set a REG_SZ value called "ToolName" to the localized name of the tool. 29 // This string (truncated to kMaxToolNameLength) will be displayed in a 30 // notification UI. The "ToolName" should be just the name of the tool, 31 // e.g. "AwesomeAV". 32 // 3) Set a REG_QWORD value called "Timestamp" with a timestamp for the reset 33 // event. This value should be obtained from a call to 34 // ::GetSystemTimeAsFileTime() at the time the reset is requested. This 35 // value will be persisted in the profile when it is reset and will be used 36 // to avoid multiple resets. 37 // 38 // Some considerations: 39 // 40 // * Chrome supports multiple profiles. When the above steps are followed, 41 // each profile will enter the reset flow as it is opened. 42 // * New profiles created while any timestamp is present will not get the reset 43 // flow. 44 class TriggeredProfileResetter : public KeyedService { 45 public: 46 enum : size_t { kMaxToolNameLength = 100 }; 47 48 explicit TriggeredProfileResetter(Profile* profile); 49 ~TriggeredProfileResetter() override; 50 51 // Causes the TriggeredProfileResetter to look for the presence of a trigger. 52 // If a trigger is found, it is disarmed so that future instances of the 53 // service will no longer trigger a reset. Subsequent calls to HasResetTrigger 54 // will return whether |profile_| is subject to a reset. 55 virtual void Activate(); 56 57 // Returns true iff the given profile has a trigger set for a reset UI flow 58 // according to the description in the class comment. Must call Activate() 59 // first. 60 virtual bool HasResetTrigger(); 61 62 // Clears the reset trigger such that subsequent calls to |HasResetTrigger| 63 // will return false. 64 virtual void ClearResetTrigger(); 65 66 // Returns the name of the tool that performed the reset. This string will be 67 // truncated to a length of |kMaxToolNameLength|. 68 virtual base::string16 GetResetToolName(); 69 70 private: 71 #if defined(OS_WIN) 72 Profile* profile_; 73 #endif // defined(OS_WIN) 74 75 bool has_reset_trigger_ = false; 76 bool activate_called_ = false; 77 78 base::string16 tool_name_; 79 80 DISALLOW_COPY_AND_ASSIGN(TriggeredProfileResetter); 81 }; 82 83 // Exposed for testing. 84 extern const wchar_t kTriggeredResetRegistryPath[]; 85 extern const wchar_t kTriggeredResetToolName[]; 86 extern const wchar_t kTriggeredResetTimestamp[]; 87 88 #endif // CHROME_BROWSER_PROFILE_RESETTER_TRIGGERED_PROFILE_RESETTER_H_ 89