Index: chrome/browser/chromeos/arc/arc_watchdog_service.cc |
diff --git a/chrome/browser/chromeos/arc/arc_watchdog_service.cc b/chrome/browser/chromeos/arc/arc_watchdog_service.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0425f5bfb4d221e2a5015cdb80e79917afd9d8bc |
--- /dev/null |
+++ b/chrome/browser/chromeos/arc/arc_watchdog_service.cc |
@@ -0,0 +1,50 @@ |
+// Copyright 2016 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. |
+ |
+#include "chrome/browser/chromeos/arc/arc_watchdog_service.h" |
+ |
+#include "base/bind.h" |
+#include "chrome/browser/chromeos/arc/arc_auth_service.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+namespace arc { |
+ |
+ArcWatchdogService::ArcWatchdogService(ArcBridgeService* bridge_service) |
+ : ArcService(bridge_service), binding_(this), weak_factory_(this) { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ arc_bridge_service()->AddObserver(this); |
+ arc_bridge_service()->watchdog()->AddObserver(this); |
+} |
+ |
+ArcWatchdogService::~ArcWatchdogService() { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ |
+ arc_bridge_service()->watchdog()->RemoveObserver(this); |
+ arc_bridge_service()->RemoveObserver(this); |
+} |
+ |
+void ArcWatchdogService::OnInstanceReady() { |
+ arc_bridge_service()->watchdog()->instance()->Init( |
+ binding_.CreateInterfacePtrAndBind()); |
+} |
+ |
+void ArcWatchdogService::OnBridgeStopped(ArcBridgeService::StopReason reason) { |
+ if (restart_required_) { |
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(&ArcWatchdogService::RestartArc, |
+ weak_factory_.GetWeakPtr())); |
uekawa-
2016/07/21 11:55:38
is it safe to immediately restart ?
I recall there
Polina Bondarenko
2016/07/22 08:16:54
Fixed a CL, but the call, that you're talking abou
|
+ } |
+} |
+ |
+void ArcWatchdogService::ClearArcData() { |
+ restart_required_ = true; |
+ ArcAuthService::Get()->StopArc(); |
+} |
+ |
+void ArcWatchdogService::RestartArc() { |
+ restart_required_ = false; |
+ ArcAuthService::Get()->RestartArc(); |
+} |
+ |
+} // namespace arc |