| OLD | NEW |
| 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/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "chromeos/dbus/session_manager_client.h" |
| 13 #include "components/arc/arc_bridge_service.h" | 14 #include "components/arc/arc_bridge_service.h" |
| 14 #include "components/arc/arc_service.h" | 15 #include "components/arc/arc_service.h" |
| 15 #include "components/prefs/pref_change_registrar.h" | 16 #include "components/prefs/pref_change_registrar.h" |
| 16 #include "components/prefs/pref_member.h" | 17 #include "components/prefs/pref_member.h" |
| 17 #include "components/signin/core/account_id/account_id.h" | 18 #include "components/signin/core/account_id/account_id.h" |
| 18 | 19 |
| 19 namespace arc { | 20 namespace arc { |
| 20 | 21 |
| 21 class ArcBridgeService; | 22 class ArcBridgeService; |
| 22 | 23 |
| 23 // 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 |
| 24 // necessary. | 25 // necessary. |
| 25 class ArcUserDataService : public ArcService, | 26 class ArcUserDataService : public ArcService, |
| 26 public ArcBridgeService::Observer { | 27 public ArcBridgeService::Observer { |
| 27 public: | 28 public: |
| 28 explicit ArcUserDataService( | 29 explicit ArcUserDataService( |
| 29 ArcBridgeService* arc_bridge_service, | 30 ArcBridgeService* arc_bridge_service, |
| 30 std::unique_ptr<BooleanPrefMember> arc_enabled_pref, | 31 std::unique_ptr<BooleanPrefMember> arc_enabled_pref, |
| 31 const AccountId& account_id); | 32 const AccountId& account_id); |
| 32 ~ArcUserDataService() override; | 33 ~ArcUserDataService() override; |
| 33 | 34 |
| 35 using ArcDataCallback = chromeos::SessionManagerClient::ArcCallback; |
| 36 |
| 34 // ArcBridgeService::Observer: | 37 // ArcBridgeService::Observer: |
| 35 // Called whenever the arc bridge is stopped to potentially remove data if | 38 // Called whenever the arc bridge is stopped to potentially wipe data if |
| 36 // the user has not opted in. | 39 // the user has not opted in or it is required. |
| 37 void OnBridgeStopped(ArcBridgeService::StopReason reason) override; | 40 void OnBridgeStopped(ArcBridgeService::StopReason reason) override; |
| 38 | 41 |
| 42 // Requires to wipe ARC user data after the next ARC bridge shutdown and call |
| 43 // |callback| with an operation result. |
| 44 void RequireUserDataWiped(const ArcDataCallback& callback); |
| 45 |
| 39 private: | 46 private: |
| 40 base::ThreadChecker thread_checker_; | 47 base::ThreadChecker thread_checker_; |
| 41 | 48 |
| 42 // Checks if ARC is both stopped and disabled (not opt-in) and triggers | 49 // Checks if ARC is both stopped and disabled (not opt-in) or data wipe is |
| 43 // removal of user data if both conditions are true. | 50 // required and triggers removal of user data. |
| 44 void ClearIfDisabled(); | 51 void WipeIfRequired(); |
| 45 | 52 |
| 46 // Callback when the kArcEnabled preference changes. It watches for instances | 53 // Callback when the kArcEnabled preference changes. It watches for instances |
| 47 // where the preference is disabled and remembers this so that it can wipe | 54 // where the preference is disabled and remembers this so that it can wipe |
| 48 // user data once the bridge has stopped. | 55 // user data once the bridge has stopped. |
| 49 void OnOptInPreferenceChanged(); | 56 void OnOptInPreferenceChanged(); |
| 50 | 57 |
| 51 const std::unique_ptr<BooleanPrefMember> arc_enabled_pref_; | 58 const std::unique_ptr<BooleanPrefMember> arc_enabled_pref_; |
| 52 | 59 |
| 53 // Account ID for the account for which we currently have opt-in information. | 60 // Account ID for the account for which we currently have opt-in information. |
| 54 AccountId primary_user_account_id_; | 61 AccountId primary_user_account_id_; |
| 55 | 62 |
| 56 // Registrar used to monitor ARC enabled state. | 63 // Registrar used to monitor ARC enabled state. |
| 57 PrefChangeRegistrar pref_change_registrar_; | 64 PrefChangeRegistrar pref_change_registrar_; |
| 58 | 65 |
| 59 // Set to true when kArcEnabled goes from true to false and set to false | 66 // Set to true when kArcEnabled goes from true to false or user data wipe is |
| 60 // again after user data has been wiped. This ensures data is wiped even if | 67 // required and set to false again after user data has been wiped. |
| 61 // the user tries to enable ARC before the bridge has shut down. | 68 // This ensures data is wiped even if the user tries to enable ARC before the |
| 62 bool arc_disabled_ = false; | 69 // bridge has shut down. |
| 70 bool arc_user_data_wipe_required_ = false; |
| 71 |
| 72 // Callback object that is passed to RemoveArcData to be invoked with a |
| 73 // result of ARC user data wipe. |
| 74 // Set when ARC user data wipe is required by RequireUserDataWiped. |
| 75 ArcDataCallback callback_; |
| 63 | 76 |
| 64 base::WeakPtrFactory<ArcUserDataService> weak_ptr_factory_; | 77 base::WeakPtrFactory<ArcUserDataService> weak_ptr_factory_; |
| 65 | 78 |
| 66 DISALLOW_COPY_AND_ASSIGN(ArcUserDataService); | 79 DISALLOW_COPY_AND_ASSIGN(ArcUserDataService); |
| 67 }; | 80 }; |
| 68 | 81 |
| 69 } // namespace arc | 82 } // namespace arc |
| 70 | 83 |
| 71 #endif // COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_ | 84 #endif // COMPONENTS_ARC_USER_DATA_ARC_USER_DATA_SERVICE_H_ |
| OLD | NEW |