1 // Copyright 2020 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/chromeos/child_accounts/time_limits/app_time_limit_utils.h"
6 
7 #include "chrome/browser/chromeos/child_accounts/time_limits/app_types.h"
8 #include "chrome/common/extensions/extension_constants.h"
9 #include "components/services/app_service/public/mojom/types.mojom.h"
10 #include "extensions/common/constants.h"
11 
12 namespace chromeos {
13 namespace app_time {
14 
AppTypeForReporting(apps::mojom::AppType type)15 enterprise_management::App::AppType AppTypeForReporting(
16     apps::mojom::AppType type) {
17   switch (type) {
18     case apps::mojom::AppType::kArc:
19       return enterprise_management::App::ARC;
20     case apps::mojom::AppType::kBuiltIn:
21       return enterprise_management::App::BUILT_IN;
22     case apps::mojom::AppType::kCrostini:
23       return enterprise_management::App::CROSTINI;
24     case apps::mojom::AppType::kExtension:
25       return enterprise_management::App::EXTENSION;
26     case apps::mojom::AppType::kPluginVm:
27       return enterprise_management::App::PLUGIN_VM;
28     case apps::mojom::AppType::kWeb:
29       return enterprise_management::App::WEB;
30     default:
31       return enterprise_management::App::UNKNOWN;
32   }
33 }
34 
GetChromeAppId()35 AppId GetChromeAppId() {
36   return AppId(apps::mojom::AppType::kExtension, extension_misc::kChromeAppId);
37 }
38 
IsWebAppOrExtension(const AppId & app_id)39 bool IsWebAppOrExtension(const AppId& app_id) {
40   return app_id.app_type() == apps::mojom::AppType::kWeb ||
41          app_id.app_type() == apps::mojom::AppType::kExtension;
42 }
43 
44 // Returns true if the application shares chrome's time limit.
ContributesToWebTimeLimit(const AppId & app_id,AppState state)45 bool ContributesToWebTimeLimit(const AppId& app_id, AppState state) {
46   if (state == AppState::kAlwaysAvailable)
47     return false;
48 
49   return IsWebAppOrExtension(app_id);
50 }
51 
52 }  // namespace app_time
53 }  // namespace chromeos
54