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.
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.
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.
15 #ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_MEMENTOS_H_
16 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_MEMENTOS_H_
20 #include "base/basictypes.h"
21 #include "base/callback.h"
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
{
34 explicit PreferenceHostedPromptMemento(Profile
* profile
);
35 ~PreferenceHostedPromptMemento();
37 std::string
ReadValue() const;
38 void StoreValue(const std::string
& value
);
43 DISALLOW_COPY_AND_ASSIGN(PreferenceHostedPromptMemento
);
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
{
51 explicit LocalStateHostedPromptMemento(Profile
* profile
);
52 ~LocalStateHostedPromptMemento();
54 std::string
ReadValue() const;
55 void StoreValue(const std::string
& value
);
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;
64 DISALLOW_COPY_AND_ASSIGN(LocalStateHostedPromptMemento
);
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
70 class FileHostedPromptMemento
{
72 typedef base::Callback
<void(const std::string
&)> ReadValueCallback
;
74 explicit FileHostedPromptMemento(Profile
* profile
);
75 ~FileHostedPromptMemento();
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;
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
);
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
);
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;
98 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMemento
);
101 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_MEMENTOS_H_