File: application_lifetime.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; 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 (117 lines) | stat: -rw-r--r-- 3,800 bytes parent folder | download | duplicates (4)
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
116
117
// Copyright 2012 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/lifetime/application_lifetime.h"

#include <memory>
#include <set>
#include <string>

#include "base/logging.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/lifetime/browser_shutdown.h"
#include "chrome/browser/ui/profiles/profile_picker.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/pref_names.h"
#include "components/language/core/browser/pref_names.h"
#include "components/language/core/common/locale_util.h"
#include "components/prefs/pref_service.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "ui/aura/env.h"
#endif  // BUILDFLAG(IS_CHROMEOS)

#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/lifetime/application_lifetime_desktop.h"
#endif  // !BUILDFLAG(IS_ANDROID)

namespace chrome {

namespace {

void AttemptExitInternal(bool try_to_quit_application) {
  // On Mac, the platform-specific part handles setting this.
#if !BUILDFLAG(IS_MAC)
  if (try_to_quit_application) {
    browser_shutdown::SetTryingToQuit(true);
  }
#endif  // !BUILDFLAG(IS_MAC)

#if !BUILDFLAG(IS_ANDROID)
  OnClosingAllBrowsers(true);
#endif  // !BUILDFLAG(IS_ANDROID)

  g_browser_process->platform_part()->AttemptExit(try_to_quit_application);
}

}  // namespace

// The ChromeOS implementations are in application_lifetime_chromeos.cc
#if !BUILDFLAG(IS_CHROMEOS)

void AttemptUserExit() {
  // Reset the restart bit that might have been set in cancelled restart
  // request.
#if !BUILDFLAG(IS_ANDROID)
  ProfilePicker::Hide();
#endif  // !BUILDFLAG(IS_ANDROID)
  PrefService* pref_service = g_browser_process->local_state();
  pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false);
  AttemptExitInternal(false);
}

void AttemptRelaunch() {
  AttemptRestart();
}

void AttemptExit() {
  // If we know that all browsers can be closed without blocking,
  // don't notify users of crashes beyond this point.
  // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit
  // so crashes during shutdown are still reported in UMA.
#if !BUILDFLAG(IS_ANDROID)
  // Android doesn't use Browser.
  if (AreAllBrowsersCloseable()) {
    MarkAsCleanShutdown();
  }
#endif  // !BUILDFLAG(IS_ANDROID)
  AttemptExitInternal(true);
}

#endif  // !BUILDFLAG(IS_CHROMEOS)

void ExitIgnoreUnloadHandlers() {
  VLOG(1) << "ExitIgnoreUnloadHandlers";
#if !BUILDFLAG(IS_ANDROID)
  // We always mark exit cleanly.
  MarkAsCleanShutdown();

#if BUILDFLAG(IS_CHROMEOS)
  // Disable window occlusion tracking on exit before closing all browser
  // windows to make shutdown faster. Note that the occlusion tracking is
  // paused indefinitely. It is okay do so on Chrome OS because there is
  // no way to abort shutdown and go back to user sessions at this point.
  DCHECK(aura::Env::HasInstance());
  aura::Env::GetInstance()->PauseWindowOcclusionTracking();

  // On ChromeOS ExitIgnoreUnloadHandlers() is used to handle SIGTERM.
  // In this case, AreAllBrowsersCloseable()
  // can be false in following cases. a) power-off b) signout from
  // screen locker.
  browser_shutdown::OnShutdownStarting(
      AreAllBrowsersCloseable() ? browser_shutdown::ShutdownType::kBrowserExit
                                : browser_shutdown::ShutdownType::kEndSession);
#else   // !BUILDFLAG(IS_CHROMEOS)
  // For desktop browsers, always perform a silent exit.
  browser_shutdown::OnShutdownStarting(
      browser_shutdown::ShutdownType::kSilentExit);
#endif  // BUILDFLAG(IS_CHROMEOS)
#endif  // !BUILDFLAG(IS_ANDROID)
  AttemptExitInternal(true);
}

}  // namespace chrome