OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_ | |
6 #define COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/threading/thread_checker.h" | |
13 #include "components/arc/arc_bridge_service.h" | |
14 #include "components/arc/arc_service.h" | |
15 #include "components/prefs/pref_change_registrar.h" | |
16 #include "components/prefs/pref_member.h" | |
17 #include "components/signin/core/account_id/account_id.h" | |
18 | |
19 namespace arc { | |
20 | |
21 class ArcBridgeService; | |
22 | |
23 // This class controls the lifecycle of ARC user data, removing it when | |
24 // necessary. | |
25 class ArcUserDataService : public ArcService, | |
26 public ArcBridgeService::Observer { | |
27 public: | |
28 explicit ArcUserDataService( | |
29 ArcBridgeService* arc_bridge_service, | |
30 std::unique_ptr<BooleanPrefMember> arc_enabled_pref, | |
31 const AccountId& account_id); | |
32 ~ArcUserDataService() override; | |
33 | |
34 // ArcBridgeService::Observer: | |
35 // Called whenever the arc bridge is stopped to potentially remove data if | |
36 // the user has not opted in. | |
37 void OnBridgeStopped(ArcBridgeService::StopReason reason) override; | |
38 | |
39 private: | |
40 base::ThreadChecker thread_checker_; | |
41 | |
42 // Checks if ARC is both stopped and disabled (not opt-in) and triggers | |
43 // removal of user data if both conditions are true. | |
44 void ClearIfDisabled(); | |
45 | |
46 // Callback when the kArcEnabled preference changes. It watches for instances | |
47 // where the preference is disabled and remembers this so that it can wipe | |
48 // user data once the bridge has stopped. | |
49 void OnOptInPreferenceChanged(); | |
50 | |
51 const std::unique_ptr<BooleanPrefMember> arc_enabled_pref_; | |
52 | |
53 // Account ID for the account for which we currently have opt-in information. | |
54 AccountId primary_user_account_id_; | |
55 | |
56 // Registrar used to monitor ARC enabled state. | |
57 PrefChangeRegistrar pref_change_registrar_; | |
58 | |
59 // Set to true when kArcEnabled goes from true to false and set to false | |
60 // again after user data has been wiped. This ensures data is wiped even if | |
61 // the user tries to enable ARC before the bridge has shut down. | |
62 bool arc_disabled_ = false; | |
63 | |
64 base::WeakPtrFactory<ArcUserDataService> weak_ptr_factory_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(ArcUserDataService); | |
67 }; | |
68 | |
69 } // namespace arc | |
70 | |
71 #endif // COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_ | |
OLD | NEW |