summaryrefslogtreecommitdiff
path: root/chromium/components/arc/arc_data_remover.h
blob: 107b521091047da3d9857945daa4c00e89454b6d (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
// Copyright 2017 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.

#ifndef COMPONENTS_ARC_ARC_DATA_REMOVER_H_
#define COMPONENTS_ARC_ARC_DATA_REMOVER_H_

#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/threading/thread_checker.h"
#include "chromeos/cryptohome/cryptohome_parameters.h"
#include "components/prefs/pref_member.h"

class PrefService;

namespace arc {

// Manages ARC's user data removal operation.
class ArcDataRemover {
 public:
  ArcDataRemover(PrefService* prefs,
                 const cryptohome::Identification& cryptohome_id);
  ~ArcDataRemover();

  // Schedules to remove the data. This is persistent, calling Run() just
  // after rebooting may execute the removing.
  void Schedule();

  // Returns whether data removal is scheduled or not for testing purpose.
  bool IsScheduledForTesting() const;

  // Executes the removing, if scheduled.
  // This must run while ARC instance is stopped.
  // If not scheduled, |callback| will be synchronously called with nullopt.
  using RunCallback = base::OnceCallback<void(base::Optional<bool> result)>;
  void Run(RunCallback callback);

 private:
  void OnDataRemoved(RunCallback callback, bool success);

  THREAD_CHECKER(thread_checker_);

  // Pref accessor to the "arc.data.remove_requested".
  BooleanPrefMember pref_;

  // Cryptohome ID for the user whose /data is being deleted.
  const cryptohome::Identification cryptohome_id_;

  base::WeakPtrFactory<ArcDataRemover> weak_factory_;
  DISALLOW_COPY_AND_ASSIGN(ArcDataRemover);
};

}  // namespace arc

#endif  // COMPONENTS_ARC_ARC_DATA_REMOVER_H_