File: promise_app.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (67 lines) | stat: -rw-r--r-- 2,210 bytes parent folder | download | duplicates (7)
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
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/apps/app_service/promise_apps/promise_app.h"

#include <iostream>

#include "base/strings/string_number_conversions.h"
#include "components/services/app_service/public/cpp/macros.h"

namespace apps {

APP_ENUM_TO_STRING(PromiseStatus,
                   kUnknown,
                   kPending,
                   kInstalling,
                   kSuccess,
                   kCancelled)

PromiseApp::PromiseApp(const apps::PackageId& package_id)
    : package_id(package_id) {}
PromiseApp::~PromiseApp() = default;

PromiseAppIcon::PromiseAppIcon() = default;
PromiseAppIcon::~PromiseAppIcon() = default;

bool PromiseApp::operator==(const PromiseApp& rhs) const {
  return this->package_id == rhs.package_id && this->progress == rhs.progress &&
         this->status == rhs.status && this->name == rhs.name &&
         this->installed_app_id == rhs.installed_app_id &&
         this->should_show == rhs.should_show;
}

PromiseAppPtr PromiseApp::Clone() const {
  auto promise_app = std::make_unique<PromiseApp>(package_id);
  if (name.has_value()) {
    promise_app->name = name;
  }
  if (progress.has_value()) {
    promise_app->progress = progress;
  }
  promise_app->status = status;
  promise_app->installed_app_id = installed_app_id;
  if (should_show.has_value()) {
    promise_app->should_show = should_show;
  }
  return promise_app;
}

std::ostream& operator<<(std::ostream& out, const PromiseApp& promise_app) {
  out << "Package_id: " << promise_app.package_id.ToString() << std::endl;
  out << "- Name: " << promise_app.name.value_or("N/A") << std::endl;
  out << "- Progress: "
      << (promise_app.progress.has_value()
              ? base::NumberToString(promise_app.progress.value())
              : "N/A")
      << std::endl;
  out << "- Status: " << EnumToString(promise_app.status) << std::endl;
  out << "- Should Show: " << promise_app.should_show.value_or(false)
      << std::endl;
  out << "- Installed App ID: " << promise_app.installed_app_id.value_or("")
      << std::endl;
  return out;
}

}  // namespace apps