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

Unified Diff: components/arc/arc_bridge_service_impl.h

Issue 2194193002: Fix ArcBridgeBootstrap race issues. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ArcBridgeBootstrap race issues. 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 side-by-side diff with in-line comments
Download patch
Index: components/arc/arc_bridge_service_impl.h
diff --git a/components/arc/arc_bridge_service_impl.h b/components/arc/arc_bridge_service_impl.h
index a9b5c44ccc5f21aa823ace2ef3e07fd1c160e56f..0bff2a39f1063b52bf8a86215f3b0315e74fcb30 100644
--- a/components/arc/arc_bridge_service_impl.h
+++ b/components/arc/arc_bridge_service_impl.h
@@ -6,15 +6,10 @@
#define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_
#include <memory>
-#include <string>
-#include <vector>
-#include "base/files/scoped_file.h"
-#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "components/arc/arc_bridge_bootstrap.h"
#include "components/arc/arc_bridge_service.h"
-#include "mojo/public/cpp/bindings/binding.h"
namespace base {
class SequencedTaskRunner;
@@ -27,23 +22,29 @@ namespace arc {
class ArcBridgeServiceImpl : public ArcBridgeService,
public ArcBridgeBootstrap::Delegate {
public:
- explicit ArcBridgeServiceImpl(std::unique_ptr<ArcBridgeBootstrap> bootstrap);
+ // This is the delegate interface for testing purpose only.
+ class Delegate {
+ public:
+ // Creates ArcBridgeBootstrap instance.
+ virtual std::unique_ptr<ArcBridgeBootstrap> CreateBootstrap() = 0;
+ };
+
+ ArcBridgeServiceImpl();
~ArcBridgeServiceImpl() override;
void HandleStartup() override;
void Shutdown() override;
+ // |delegate| is managed by the caller. This is only for testing purpose.
+ void SetDelegateForTesting(Delegate* delegate) { delegate_ = delegate; }
+
// Normally, reconnecting after connection shutdown happens after a short
// delay. When testing, however, we'd like it to happen immediately to avoid
// adding unnecessary delays.
void DisableReconnectDelayForTesting();
private:
- friend class ArcBridgeTest;
- FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart);
- FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped);
-
// If all pre-requisites are true (ARC is available, it has been enabled, and
// the session has started), and ARC is stopped, start ARC. If ARC is running
// and the pre-requisites stop being true, stop ARC.
@@ -53,17 +54,13 @@ class ArcBridgeServiceImpl : public ArcBridgeService,
void StopInstance();
// ArcBridgeBootstrap::Delegate:
- void OnConnectionEstablished(mojom::ArcBridgeInstancePtr instance) override;
+ void OnReady() override;
void OnStopped(StopReason reason) override;
std::unique_ptr<ArcBridgeBootstrap> bootstrap_;
// If the user's session has started.
- bool session_started_;
-
- // Mojo endpoint.
- // TODO(hidehiko): Move this to ArcBridgeBootstrap.
- std::unique_ptr<mojom::ArcBridgeHost> arc_bridge_host_;
+ bool session_started_ = false;
// If the instance had already been started but the connection to it was
// lost. This should make the instance restart.
@@ -72,6 +69,9 @@ class ArcBridgeServiceImpl : public ArcBridgeService,
// Delay the reconnection.
bool use_delay_before_reconnecting_ = true;
+ // Delegate to inject a fake ArcBridgeBootstrap instance for testing.
+ Delegate* delegate_ = nullptr;
+
// WeakPtrFactory to use callbacks.
base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_;

Powered by Google App Engine
This is Rietveld 408576698