summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h
blob: 025ffb224501b86101d7e1d94410ba1793c0855f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// The classes in this file are alternative implementations of the concept of a
// "prompt memento", a token of some kind that gets stored when we show the
// one-time profile reset prompt, and which then serves as a reminder that we
// should not show the prompt again.
//
// In an ideal world, a single implementation would suffice, however, we expect
// that third party software might accidentally interfere with some of these
// methods. We need this redundancy because we want to make absolutely sure that
// we do not annoy the user with the prompt multiple times.

#ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_MEMENTOS_H_
#define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_MEMENTOS_H_

#include <string>

#include "base/basictypes.h"
#include "base/callback.h"

namespace base {
class FilePath;
}

class Profile;

// This class is a wrapper around the user preference that gets stored when we
// show the one-time profile reset prompt, and which is kept as a reminder that
// we should not show the prompt again.
class PreferenceHostedPromptMemento {
 public:
  explicit PreferenceHostedPromptMemento(Profile* profile);
  ~PreferenceHostedPromptMemento();

  std::string ReadValue() const;
  void StoreValue(const std::string& value);

 private:
  Profile* profile_;

  DISALLOW_COPY_AND_ASSIGN(PreferenceHostedPromptMemento);
};

// This class is a wrapper around the Local State preference that gets stored
// when we show the one-time profile reset prompt, and which is kept as a
// reminder that we should not show the prompt again.
class LocalStateHostedPromptMemento {
 public:
  explicit LocalStateHostedPromptMemento(Profile* profile);
  ~LocalStateHostedPromptMemento();

  std::string ReadValue() const;
  void StoreValue(const std::string& value);

 private:
  // Returns the key that shall be used in the dictionary preference in Local
  // State to uniquely identify this profile.
  std::string GetProfileKey() const;

  Profile* profile_;

  DISALLOW_COPY_AND_ASSIGN(LocalStateHostedPromptMemento);
};

// This class manages a marker file that gets stored when we show the one-time
// profile reset prompt, and which is kept as a reminder that we should not show
// the prompt again.
class FileHostedPromptMemento {
 public:
  typedef base::Callback<void(const std::string&)> ReadValueCallback;

  explicit FileHostedPromptMemento(Profile* profile);
  ~FileHostedPromptMemento();

  // Posts to the FILE thread to read the value, then returns the value to the
  // calling thread. It is safe to destroy this object as soon as this method
  // (synchronously) returns.
  void ReadValue(const ReadValueCallback& callback) const;

  // Asynchronously stores the value on the FILE thread. However, it is safe to
  // destroy this object as soon as this method (synchronously) returns.
  void StoreValue(const std::string& value);

 private:
  static std::string ReadValueOnFileThread(
      const base::FilePath& memento_file_path);
  static void StoreValueOnFileThread(const base::FilePath& memento_file_path,
                                     const std::string& value);

  // Returns the path to the file that shall be used to store this kind of
  // memento for this profile.
  base::FilePath GetMementoFilePath() const;

  Profile* profile_;

  DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMemento);
};

#endif  // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_MEMENTOS_H_