File: worker_id_set.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (106 lines) | stat: -rw-r--r-- 4,071 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
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_SERVICE_WORKER_WORKER_ID_SET_H_
#define EXTENSIONS_BROWSER_SERVICE_WORKER_WORKER_ID_SET_H_

#include <set>
#include <vector>

#include "base/auto_reset.h"
#include "base/debug/crash_logging.h"
#include "extensions/browser/service_worker/worker_id.h"
#include "extensions/common/extension_id.h"

namespace content {
class BrowserContext;
}

// Set of WorkersIds that provides faster retrieval/removal of workers by
// extension id, render process id etc.
namespace extensions {

class WorkerIdSet {
 public:
  WorkerIdSet();

  WorkerIdSet(const WorkerIdSet&) = delete;
  WorkerIdSet& operator=(const WorkerIdSet&) = delete;

  ~WorkerIdSet();

  void Add(const WorkerId& worker_id, content::BrowserContext* context);
  bool Remove(const WorkerId& worker_id);
  bool Contains(const WorkerId& worker_id) const;
  std::vector<WorkerId> GetAllForExtension(
      const ExtensionId& extension_id) const;
  std::vector<WorkerId> GetAllForExtension(const ExtensionId& extension_id,
                                           int render_process_id) const;
  std::vector<WorkerId> GetAllForExtension(const ExtensionId& extension_id,
                                           int64_t worker_version_id) const;

  std::vector<WorkerId> GetAllForTesting() const;
  static base::AutoReset<bool> AllowMultipleWorkersPerExtensionForTesting();
  size_t count_for_testing() const { return workers_.size(); }

 private:
  std::set<WorkerId> workers_;
};

namespace debug {

// Helper for adding a set of multiple worker related crash keys.
//
// It is meant to be created when we detect exactly two entries for the same
// worker that will be recorded in `WorkerIdSet::Add()`.
//
// These crash keys set information relevant to when two workers are attempting
// to be added to the `WorkerIdSet`. All keys are logged every time this class
// is instantiated. Each key describes its possible values.
//
//  The "previous" `WorkerId` is the one that existed before
//  `WorkerIdSet::Add()` is called. The "new" `WorkerId` is the duplicate that
//  will be added once `WorkerIdSet::Add()` completes.
class ScopedMultiWorkerCrashKeys {
 public:
  explicit ScopedMultiWorkerCrashKeys(const ExtensionId& extension_id,
                                      const WorkerId& previous_worker_id,
                                      const WorkerId& new_worker_id,
                                      content::BrowserContext* context);
  ~ScopedMultiWorkerCrashKeys();

 private:
  base::debug::ScopedCrashKeyString extension_id_crash_key_;

  // Whether the previous and new worker version ids match. Values are: "yes",
  // or "no".
  base::debug::ScopedCrashKeyString identical_version_ids_crash_key_;
  // The `version_id`s for each worker. A (stringified) int64_t that identifies
  // what version of code a worker is running.
  base::debug::ScopedCrashKeyString previous_worker_version_id_crash_key_;
  base::debug::ScopedCrashKeyString new_worker_version_id_crash_key_;

  // The `content::ServiceWorkerRunningInfo::ServiceWorkerStatus`
  // (`ServiceWorkerVersion::Status`) for the previous and new `WorkerId`s.
  base::debug::ScopedCrashKeyString previous_worker_lifecycle_state_crash_key_;
  base::debug::ScopedCrashKeyString new_worker_lifecycle_state_crash_key_;

  // Whether the renderer process ids for the previous and new worker match.
  // Values are: "yes", or "no".
  base::debug::ScopedCrashKeyString
      identical_worker_render_process_ids_crash_key_;

  // Whether the renderer process id for the previous and new worker for this
  // specific extension are running or not. Values are: "yes", or "no".
  base::debug::ScopedCrashKeyString
      previous_worker_render_process_running_crash_key_;
  base::debug::ScopedCrashKeyString
      new_worker_render_process_running_crash_key_;
};

}  // namespace debug

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_SERVICE_WORKER_WORKER_ID_SET_H_