Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: components/arc/user_data/arc_user_data_service.h

Issue 2145813002: Clear old ARC instance before opt-in. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed test Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_ 5 #ifndef COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_
6 #define COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_ 6 #define COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/threading/thread_checker.h" 11 #include "base/threading/thread_checker.h"
12 #include "components/arc/arc_bridge_service.h" 12 #include "components/arc/arc_bridge_service.h"
13 #include "components/arc/arc_service.h" 13 #include "components/arc/arc_service.h"
14 #include "components/prefs/pref_change_registrar.h"
14 #include "components/prefs/pref_member.h" 15 #include "components/prefs/pref_member.h"
15 #include "components/signin/core/account_id/account_id.h" 16 #include "components/signin/core/account_id/account_id.h"
16 17
18 class PrefService;
19
17 namespace arc { 20 namespace arc {
18 21
19 class ArcBridgeService; 22 class ArcBridgeService;
20 23
21 // This class controls the lifecycle of ARC user data, removing it when 24 // This class controls the lifecycle of ARC user data, removing it when
22 // necessary. 25 // necessary.
23 class ArcUserDataService : public ArcService, 26 class ArcUserDataService : public ArcService,
24 public ArcBridgeService::Observer { 27 public ArcBridgeService::Observer {
25 public: 28 public:
26 explicit ArcUserDataService( 29 explicit ArcUserDataService(
27 ArcBridgeService* arc_bridge_service, 30 ArcBridgeService* arc_bridge_service,
28 std::unique_ptr<BooleanPrefMember> arc_enabled_pref, 31 std::unique_ptr<BooleanPrefMember> arc_enabled_pref,
32 PrefService* pref_service,
29 const AccountId& account_id); 33 const AccountId& account_id);
30 ~ArcUserDataService() override; 34 ~ArcUserDataService() override;
31 35
32 // ArcBridgeService::Observer: 36 // ArcBridgeService::Observer:
33 // Called whenever the arc bridge is stopped to potentially remove data if 37 // Called whenever the arc bridge is stopped to potentially remove data if
34 // the user has not opted in. 38 // the user has not opted in.
35 void OnBridgeStopped(ArcBridgeService::StopReason reason) override; 39 void OnBridgeStopped(ArcBridgeService::StopReason reason) override;
36 40
37 private: 41 private:
38 base::ThreadChecker thread_checker_; 42 base::ThreadChecker thread_checker_;
39 43
40 // Checks if ARC is both stopped and disabled (not opt-in) and triggers 44 // Checks if ARC is both stopped and disabled (not opt-in) and triggers
41 // removal of user data if both conditions are true. 45 // removal of user data if both conditions are true.
42 void ClearIfDisabled(); 46 void ClearIfDisabled();
43 47
48 // Callback when the kArcEnabled preference changes. It watches for instances
49 // where the preference is disabled and remembers this so that it can wipe
50 // user data once the bridge has stopped.
51 void OnOptInPreferenceChanged();
52
44 const std::unique_ptr<BooleanPrefMember> arc_enabled_pref_; 53 const std::unique_ptr<BooleanPrefMember> arc_enabled_pref_;
45 54
46 // Account ID for the account for which we currently have opt-in information. 55 // Account ID for the account for which we currently have opt-in information.
47 AccountId primary_user_account_id_; 56 AccountId primary_user_account_id_;
48 57
58 // Registrar used to monitor ARC enabled state.
59 PrefChangeRegistrar pref_change_registrar_;
60
61 // Set to true when kArcEnabled goes from true to false and set to false
62 // again after user data has been wiped. This ensures data is wiped even if
63 // the user tries to enable ARC before the bridge has shut down.
64 bool arc_disabled_ = false;
65
66 base::WeakPtrFactory<ArcUserDataService> weak_ptr_factory_;
67
49 DISALLOW_COPY_AND_ASSIGN(ArcUserDataService); 68 DISALLOW_COPY_AND_ASSIGN(ArcUserDataService);
50 }; 69 };
51 70
52 } // namespace arc 71 } // namespace arc
53 72
54 #endif // COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_ 73 #endif // COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698