blob: b85a25f5e80f843ec832ac611b3c944d110ad227 [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
Alexey Baskakov256a3c432019-08-15 02:56:245#include "chrome/browser/web_applications/web_app.h"
6
Alexey Baskakov4768f6232018-11-08 09:26:467#include <ios>
Alexey Baskakov393b2aa2018-10-25 06:42:318#include <ostream>
Alexey Baskakov97881e52019-09-06 05:51:039#include <tuple>
Alexey Baskakov393b2aa2018-10-25 06:42:3110
Alexey Baskakov8975f352018-12-05 02:28:2611#include "base/logging.h"
Alexey Baskakov4768f6232018-11-08 09:26:4612#include "ui/gfx/color_utils.h"
Alexey Baskakovfd3894e2018-10-16 06:09:5813
14namespace web_app {
15
Alexey Baskakove3804cf2019-08-14 00:16:0216WebApp::WebApp(const AppId& app_id)
17 : app_id_(app_id), launch_container_(LaunchContainer::kDefault) {}
Alexey Baskakovfd3894e2018-10-16 06:09:5818
19WebApp::~WebApp() = default;
20
Alexey Baskakov97881e52019-09-06 05:51:0321void WebApp::AddSource(Source::Type source) {
22 sources_[source] = true;
23}
24
25void WebApp::RemoveSource(Source::Type source) {
26 sources_[source] = false;
27}
28
29bool WebApp::HasAnySources() const {
30 return sources_.any();
31}
32
Alexey Baskakov0b50ec62019-10-01 03:29:2333bool WebApp::IsSynced() const {
34 return sources_[Source::kSync];
35}
36
Alexey Baskakovfd3894e2018-10-16 06:09:5837void WebApp::SetName(const std::string& name) {
38 name_ = name;
39}
40
41void WebApp::SetDescription(const std::string& description) {
42 description_ = description;
43}
44
Alexey Baskakov79b06902018-11-08 05:30:0345void WebApp::SetLaunchUrl(const GURL& launch_url) {
46 DCHECK(!launch_url.is_empty() && launch_url.is_valid());
Alexey Baskakovfd3894e2018-10-16 06:09:5847 launch_url_ = launch_url;
48}
49
Alexey Baskakov4768f6232018-11-08 09:26:4650void WebApp::SetScope(const GURL& scope) {
51 DCHECK(scope.is_empty() || scope.is_valid());
52 scope_ = scope;
53}
54
55void WebApp::SetThemeColor(base::Optional<SkColor> theme_color) {
56 theme_color_ = theme_color;
57}
58
Alexey Baskakove3804cf2019-08-14 00:16:0259void WebApp::SetLaunchContainer(LaunchContainer launch_container) {
60 DCHECK_NE(LaunchContainer::kDefault, launch_container);
61 launch_container_ = launch_container;
62}
63
Alexey Baskakov256a3c432019-08-15 02:56:2464void WebApp::SetIsLocallyInstalled(bool is_locally_installed) {
65 is_locally_installed_ = is_locally_installed;
66}
67
Alexey Baskakov8c864f182019-10-04 03:39:5668void WebApp::SetIsSyncPlaceholder(bool is_sync_placeholder) {
69 is_sync_placeholder_ = is_sync_placeholder;
70}
71
Alexey Baskakov8975f352018-12-05 02:28:2672void WebApp::SetIcons(Icons icons) {
Alexey Baskakov8975f352018-12-05 02:28:2673 icons_ = std::move(icons);
74}
75
Alexey Baskakov8c864f182019-10-04 03:39:5676void WebApp::SetSyncData(const SyncData& sync_data) {
77 sync_data_ = sync_data;
78}
79
80WebApp::SyncData::SyncData() = default;
81
82WebApp::SyncData::~SyncData() = default;
83
Alexey Baskakov393b2aa2018-10-25 06:42:3184std::ostream& operator<<(std::ostream& out, const WebApp& app) {
Alexey Baskakov4768f6232018-11-08 09:26:4685 const std::string theme_color =
Alexey Baskakov8c864f182019-10-04 03:39:5686 app.theme_color_.has_value()
87 ? color_utils::SkColorToRgbaString(app.theme_color_.value())
88 : "none";
89 const std::string sync_theme_color =
90 app.sync_data_.theme_color.has_value()
91 ? color_utils::SkColorToRgbaString(app.sync_data_.theme_color.value())
Alexey Baskakov4768f6232018-11-08 09:26:4692 : "none";
Alexey Baskakov256a3c432019-08-15 02:56:2493 const char* launch_container =
Alexey Baskakov8c864f182019-10-04 03:39:5694 LaunchContainerEnumToStr(app.launch_container_);
95 const bool is_locally_installed = app.is_locally_installed_;
96 const bool is_sync_placeholder = app.is_sync_placeholder_;
Alexey Baskakov4768f6232018-11-08 09:26:4697
Alexey Baskakov97881e52019-09-06 05:51:0398 return out << "app_id: " << app.app_id_ << std::endl
99 << " name: " << app.name_ << std::endl
100 << " launch_url: " << app.launch_url_ << std::endl
101 << " scope: " << app.scope_ << std::endl
Alexey Baskakov4768f6232018-11-08 09:26:46102 << " theme_color: " << theme_color << std::endl
Alexey Baskakov256a3c432019-08-15 02:56:24103 << " launch_container: " << launch_container << std::endl
Alexey Baskakov8c864f182019-10-04 03:39:56104 << " sources: " << app.sources_.to_string() << std::endl
Alexey Baskakov256a3c432019-08-15 02:56:24105 << " is_locally_installed: " << is_locally_installed << std::endl
Alexey Baskakov8c864f182019-10-04 03:39:56106 << " is_sync_placeholder: " << is_sync_placeholder << std::endl
107 << " sync_data.name: " << app.sync_data_.name << std::endl
108 << " sync_data.theme_color: " << sync_theme_color << std::endl
Alexey Baskakov97881e52019-09-06 05:51:03109 << " description: " << app.description_;
110}
111
112bool operator==(const WebApp::IconInfo& icon_info1,
113 const WebApp::IconInfo& icon_info2) {
114 return std::tie(icon_info1.url, icon_info1.size_in_px) ==
115 std::tie(icon_info2.url, icon_info2.size_in_px);
116}
117
Alexey Baskakov8c864f182019-10-04 03:39:56118bool operator==(const WebApp::SyncData& sync_data1,
119 const WebApp::SyncData& sync_data2) {
120 return std::tie(sync_data1.name, sync_data1.theme_color) ==
121 std::tie(sync_data2.name, sync_data2.theme_color);
122}
123
Alexey Baskakov97881e52019-09-06 05:51:03124bool operator==(const WebApp& app1, const WebApp& app2) {
125 return std::tie(app1.app_id_, app1.sources_, app1.name_, app1.launch_url_,
126 app1.description_, app1.scope_, app1.theme_color_,
127 app1.icons_, app1.launch_container_,
Alexey Baskakov8c864f182019-10-04 03:39:56128 app1.is_locally_installed_, app1.is_sync_placeholder_,
129 app1.sync_data_) ==
Alexey Baskakov97881e52019-09-06 05:51:03130 std::tie(app2.app_id_, app2.sources_, app2.name_, app2.launch_url_,
131 app2.description_, app2.scope_, app2.theme_color_,
132 app2.icons_, app2.launch_container_,
Alexey Baskakov8c864f182019-10-04 03:39:56133 app2.is_locally_installed_, app2.is_sync_placeholder_,
134 app2.sync_data_);
Alexey Baskakov97881e52019-09-06 05:51:03135}
136
137bool operator!=(const WebApp& app1, const WebApp& app2) {
138 return !(app1 == app2);
Alexey Baskakov393b2aa2018-10-25 06:42:31139}
140
Alexey Baskakovfd3894e2018-10-16 06:09:58141} // namespace web_app