summaryrefslogtreecommitdiff
path: root/chromium/fuchsia/base/fake_component_context.cc
blob: fa449a8654876a71efeca9122077c8df36f9516e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2018 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 "fuchsia/base/fake_component_context.h"

#include <fuchsia/base/agent_impl.h>

#include <memory>
#include <string>
#include <utility>

#include "base/check.h"
#include "base/notreached.h"
#include "base/run_loop.h"

namespace cr_fuchsia {

FakeComponentContext::FakeComponentContext(
    sys::OutgoingDirectory* outgoing_directory,
    base::StringPiece component_url)
    : binding_(outgoing_directory, this),
      component_url_(component_url.as_string()),
      outgoing_directory_(outgoing_directory) {}

void FakeComponentContext::RegisterCreateComponentStateCallback(
    base::StringPiece agent_url,
    AgentImpl::CreateComponentStateCallback create_component_state_callback) {
  agent_impl_map_.insert(std::make_pair(
      agent_url,
      std::make_unique<AgentImpl>(outgoing_directory_,
                                  std::move(create_component_state_callback))));
}

void FakeComponentContext::DeprecatedConnectToAgent(
    std::string agent_url,
    fidl::InterfaceRequest<::fuchsia::sys::ServiceProvider> services,
    fidl::InterfaceRequest<fuchsia::modular::AgentController> controller) {
  auto it = agent_impl_map_.find(agent_url);
  CHECK(it != agent_impl_map_.end())
      << "Received request for an unknown agent URL: " << agent_url;

  it->second->Connect(component_url_, std::move(services));
}

void FakeComponentContext::NotImplemented_(const std::string& name) {
  NOTIMPLEMENTED() << " API: " << name;
}

FakeComponentContext::~FakeComponentContext() {
  agent_services_.Unbind();
  base::RunLoop().RunUntilIdle();
}

}  // namespace cr_fuchsia