summaryrefslogtreecommitdiff
path: root/chromium/services/content/service.cc
blob: 5e295321992389bcb3fc1cebb2aa6edc51688d6f (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
56
// 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 "services/content/service.h"

#include <utility>

#include "services/content/navigable_contents_factory_impl.h"
#include "services/content/navigable_contents_impl.h"
#include "services/content/public/mojom/navigable_contents_factory.mojom.h"
#include "services/content/service_delegate.h"

namespace content {

Service::Service(ServiceDelegate* delegate) : delegate_(delegate) {}

Service::~Service() {
  delegate_->WillDestroyServiceInstance(this);
}

void Service::BindNavigableContentsFactory(
    mojo::PendingReceiver<mojom::NavigableContentsFactory> receiver) {
  AddNavigableContentsFactory(std::make_unique<NavigableContentsFactoryImpl>(
      this, std::move(receiver)));
}

void Service::ForceQuit() {
  // Ensure that all bound interfaces are disconnected and no further interface
  // requests will be handled.
  navigable_contents_factories_.clear();
  navigable_contents_.clear();
}

void Service::AddNavigableContentsFactory(
    std::unique_ptr<NavigableContentsFactoryImpl> factory) {
  auto* raw_factory = factory.get();
  navigable_contents_factories_.emplace(raw_factory, std::move(factory));
}

void Service::RemoveNavigableContentsFactory(
    NavigableContentsFactoryImpl* factory) {
  navigable_contents_factories_.erase(factory);
}

void Service::AddNavigableContents(
    std::unique_ptr<NavigableContentsImpl> contents) {
  auto* raw_contents = contents.get();
  navigable_contents_.emplace(raw_contents, std::move(contents));
}

void Service::RemoveNavigableContents(NavigableContentsImpl* contents) {
  navigable_contents_.erase(contents);
}

}  // namespace content