File: whats_new_util.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 (115 lines) | stat: -rw-r--r-- 3,518 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2021 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/ui/webui/whats_new/whats_new_util.h"

#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "components/prefs/pref_service.h"
#include "net/base/url_util.h"
#include "ui/base/ui_base_features.h"
#include "url/gurl.h"

namespace whats_new {
bool g_is_remote_content_disabled = false;

#if !BUILDFLAG(IS_CHROMEOS)
// For testing purposes, so that WebUI tests run on non-branded
// CQ bots.
BASE_FEATURE(kForceEnabled,
             "WhatsNewForceEnabled",
             base::FEATURE_DISABLED_BY_DEFAULT);
#endif

bool IsEnabled() {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && !BUILDFLAG(IS_CHROMEOS)
  return true;
#elif !BUILDFLAG(IS_CHROMEOS)
  return base::FeatureList::IsEnabled(whats_new::kForceEnabled);
#else
  return false;
#endif
}

void DisableRemoteContentForTests() {
  g_is_remote_content_disabled = true;
}

void LogStartupType(StartupType type) {
#if !BUILDFLAG(IS_CHROMEOS)
  base::UmaHistogramEnumeration("WhatsNew.StartupType", type);
#endif
}

bool IsRemoteContentDisabled() {
  return g_is_remote_content_disabled;
}

bool ShouldShowForState(PrefService* local_state,
                        bool promotional_tabs_enabled) {
#if BUILDFLAG(IS_CHROMEOS)
  return false;
#else
  LogStartupType(StartupType::kCalledShouldShow);

  if (!promotional_tabs_enabled) {
    whats_new::LogStartupType(whats_new::StartupType::kPromotionalTabsDisabled);
    return false;
  }

  if (!local_state ||
      !local_state->FindPreference(prefs::kLastWhatsNewVersion)) {
    LogStartupType(StartupType::kInvalidState);
    return false;
  }

  // Allow disabling the What's New experience in tests using the standard
  // kNoFirstRun switch. This behavior can be overridden using the
  // kForceWhatsNew switch for the What's New experience integration tests.
  const base::CommandLine* command_line =
      base::CommandLine::ForCurrentProcess();
  if ((command_line->HasSwitch(switches::kNoFirstRun) &&
       !command_line->HasSwitch(switches::kForceWhatsNew)) ||
      !IsEnabled()) {
    LogStartupType(StartupType::kFeatureDisabled);
    return false;
  }

  int last_version = local_state->GetInteger(prefs::kLastWhatsNewVersion);

  // Don't show What's New if it's already been shown for the current major
  // milestone.
  if (CHROME_VERSION_MAJOR <= last_version) {
    LogStartupType(StartupType::kAlreadyShown);
    return false;
  }

  // Set the last version here to indicate that What's New should not attempt
  // to display again for this milestone. This prevents the page from
  // potentially displaying multiple times in a given milestone, e.g. for
  // multiple profile relaunches (see https://crbug.com/1274313).
  local_state->SetInteger(prefs::kLastWhatsNewVersion, CHROME_VERSION_MAJOR);
  return true;
#endif
}

GURL GetWebUIStartupURL() {
#if !BUILDFLAG(IS_CHROMEOS)
  return net::AppendQueryParameter(GURL(chrome::kChromeUIWhatsNewURL), "auto",
                                   "true");
#else
  NOTREACHED();
#endif
}

}  // namespace whats_new