1 // Copyright 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 // The classes in this file are alternative implementations of the concept of a 6 // "prompt memento", a token of some kind that gets stored when we show the 7 // one-time profile reset prompt, and which then serves as a reminder that we 8 // should not show the prompt again. 9 // 10 // In an ideal world, a single implementation would suffice, however, we expect 11 // that third party software might accidentally interfere with some of these 12 // methods. We need this redundancy because we want to make absolutely sure that 13 // we do not annoy the user with the prompt multiple times. 14 15 #ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_MEMENTOS_H_ 16 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_MEMENTOS_H_ 17 18 #include <string> 19 20 #include "base/basictypes.h" 21 #include "base/callback.h" 22 23 namespace base { 24 class FilePath; 25 } 26 27 class Profile; 28 29 // This class is a wrapper around the user preference that gets stored when we 30 // show the one-time profile reset prompt, and which is kept as a reminder that 31 // we should not show the prompt again. 32 class PreferenceHostedPromptMemento { 33 public: 34 explicit PreferenceHostedPromptMemento(Profile* profile); 35 ~PreferenceHostedPromptMemento(); 36 37 std::string ReadValue() const; 38 void StoreValue(const std::string& value); 39 40 private: 41 Profile* profile_; 42 43 DISALLOW_COPY_AND_ASSIGN(PreferenceHostedPromptMemento); 44 }; 45 46 // This class is a wrapper around the Local State preference that gets stored 47 // when we show the one-time profile reset prompt, and which is kept as a 48 // reminder that we should not show the prompt again. 49 class LocalStateHostedPromptMemento { 50 public: 51 explicit LocalStateHostedPromptMemento(Profile* profile); 52 ~LocalStateHostedPromptMemento(); 53 54 std::string ReadValue() const; 55 void StoreValue(const std::string& value); 56 57 private: 58 // Returns the key that shall be used in the dictionary preference in Local 59 // State to uniquely identify this profile. 60 std::string GetProfileKey() const; 61 62 Profile* profile_; 63 64 DISALLOW_COPY_AND_ASSIGN(LocalStateHostedPromptMemento); 65 }; 66 67 // This class manages a marker file that gets stored when we show the one-time 68 // profile reset prompt, and which is kept as a reminder that we should not show 69 // the prompt again. 70 class FileHostedPromptMemento { 71 public: 72 typedef base::Callback<void(const std::string&)> ReadValueCallback; 73 74 explicit FileHostedPromptMemento(Profile* profile); 75 ~FileHostedPromptMemento(); 76 77 // Posts to the FILE thread to read the value, then returns the value to the 78 // calling thread. It is safe to destroy this object as soon as this method 79 // (synchronously) returns. 80 void ReadValue(const ReadValueCallback& callback) const; 81 82 // Asynchronously stores the value on the FILE thread. However, it is safe to 83 // destroy this object as soon as this method (synchronously) returns. 84 void StoreValue(const std::string& value); 85 86 private: 87 static std::string ReadValueOnFileThread( 88 const base::FilePath& memento_file_path); 89 static void StoreValueOnFileThread(const base::FilePath& memento_file_path, 90 const std::string& value); 91 92 // Returns the path to the file that shall be used to store this kind of 93 // memento for this profile. 94 base::FilePath GetMementoFilePath() const; 95 96 Profile* profile_; 97 98 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMemento); 99 }; 100 101 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_MEMENTOS_H_ 102