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 #include "chrome/browser/chromeos/arc/arc_enterprise_reporting_service.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/logging.h" |
| 11 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
| 12 #include "components/arc/arc_service_manager.h" |
| 13 #include "components/arc/user_data/arc_user_data_service.h" |
| 14 |
| 15 namespace arc { |
| 16 |
| 17 ArcEnterpriseReportingService::ArcEnterpriseReportingService( |
| 18 ArcBridgeService* bridge_service) |
| 19 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) { |
| 20 arc_bridge_service()->enterprise_reporting()->AddObserver(this); |
| 21 } |
| 22 |
| 23 ArcEnterpriseReportingService::~ArcEnterpriseReportingService() { |
| 24 DCHECK(thread_checker_.CalledOnValidThread()); |
| 25 arc_bridge_service()->enterprise_reporting()->RemoveObserver(this); |
| 26 } |
| 27 |
| 28 void ArcEnterpriseReportingService::OnInstanceReady() { |
| 29 DCHECK(thread_checker_.CalledOnValidThread()); |
| 30 arc_bridge_service()->enterprise_reporting()->instance()->Init( |
| 31 binding_.CreateInterfacePtrAndBind()); |
| 32 } |
| 33 |
| 34 void ArcEnterpriseReportingService::ReportManagementState( |
| 35 mojom::ManagementState state) { |
| 36 DCHECK(thread_checker_.CalledOnValidThread()); |
| 37 VLOG(1) << "ReportManagementState state=" << state; |
| 38 |
| 39 if (state == mojom::ManagementState::MANAGED_DO_LOST) { |
| 40 DCHECK(arc::ArcServiceManager::Get()); |
| 41 ArcServiceManager::Get()->arc_user_data_service()->RequireUserDataWiped( |
| 42 base::Bind(&ArcEnterpriseReportingService::RestartArc, |
| 43 weak_ptr_factory_.GetWeakPtr())); |
| 44 ArcAuthService::Get()->StopArc(); |
| 45 } |
| 46 } |
| 47 |
| 48 void ArcEnterpriseReportingService::RestartArc(bool result) { |
| 49 DCHECK(thread_checker_.CalledOnValidThread()); |
| 50 if (!result) |
| 51 LOG(ERROR) << "Required ARC user data wipe failed."; |
| 52 |
| 53 // Restart ARC anyway. Let the enterprise reporting instance decide whether |
| 54 // the ARC user data wipe is still required or not. |
| 55 VLOG(1) << "Restart ARC"; |
| 56 ArcAuthService::Get()->EnableArc(); |
| 57 } |
| 58 |
| 59 } // namespace arc |
OLD | NEW |