blob: 47631b9623d3c523ad22775686c7b6e57652672f [file] [log] [blame]
Alexey Baskakovfd3894e2018-10-16 06:09:581// Copyright 2018 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/web_applications/web_app_registrar.h"
6
7#include "base/logging.h"
8#include "chrome/browser/web_applications/web_app.h"
9
10namespace web_app {
11
12WebAppRegistrar::WebAppRegistrar() {}
13
14WebAppRegistrar::~WebAppRegistrar() = default;
15
16void WebAppRegistrar::RegisterApp(std::unique_ptr<WebApp> web_app) {
17 const auto app_id = web_app->app_id();
18 DCHECK(!app_id.empty());
19 DCHECK(!GetAppById(app_id));
20
21 registry_.emplace(std::make_pair(app_id, std::move(web_app)));
22}
23
24std::unique_ptr<WebApp> WebAppRegistrar::UnregisterApp(const AppId& app_id) {
25 DCHECK(!app_id.empty());
26
27 auto kv = registry_.find(app_id);
28 DCHECK(kv != registry_.end());
29
30 auto web_app = std::move(kv->second);
31 registry_.erase(kv);
32 return web_app;
33}
34
35WebApp* WebAppRegistrar::GetAppById(const AppId& app_id) {
36 auto kv = registry_.find(app_id);
37 return kv == registry_.end() ? nullptr : kv->second.get();
38}
39
40} // namespace web_app