summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/ui/webui/discards/discards.mojom
blob: ca07b07113049256fe2eaade7f9b9775d1232354 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module discards.mojom;

import "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom";
import "mojo/public/mojom/base/process_id.mojom";
import "mojo/public/mojom/base/time.mojom";
import "url/mojom/url.mojom";

// Identical to content::Visibility.
enum LifecycleUnitVisibility {
  HIDDEN = 0,
  OCCLUDED = 1,
  VISIBLE = 2,
};

struct SiteCharacteristicsFeature {
  // The cumulative observation time for this feature in seconds, set to 0 once
  // this feature has been observed.
  int64 observation_duration;
  // The time at which this feature has been used (set to 0 if it hasn't been
  // used), in seconds since epoch.
  int64 use_timestamp;
};

struct SiteCharacteristicsPerformanceMeasurement {
  // A decaying average of the CPU usage measurements. Units: microseconds.
  float avg_cpu_usage_us;
  // A decaying average of the process footprint measurements. Units: kilobytes.
  float avg_footprint_kb;
  // A decaying average of the wall-clock load time duration of the tab.
  // Units: microseconds.
  float avg_load_duration_us;
};

struct SiteCharacteristicsDatabaseSize {
  // The total number of rows in the database, or -1 if the value is not
  // available.
  int64 num_rows;

  // The total size of the database on disk in kilobytes, or -1 if the value
  // is not available.
  int64 on_disk_size_kb;
};

// The data stored for a given origin, this should mirror the
// SiteDataProto structure in
// performance_manager/persistence/site_data/site_data.proto.
struct SiteCharacteristicsDatabaseValue {
  // The last time this site has been in the loaded state, in seconds since
  // epoch.
  uint32 last_loaded;

  SiteCharacteristicsFeature updates_favicon_in_background;
  SiteCharacteristicsFeature updates_title_in_background;
  SiteCharacteristicsFeature uses_audio_in_background;
  SiteCharacteristicsFeature uses_notifications_in_background;

  // Load time performance measurement estimates. This maintains a decaying
  // average of the resource usage of a page until shortly after it becomes
  // idle.
  SiteCharacteristicsPerformanceMeasurement? load_time_estimates;
};

// Provides the key and miscellaneous in-memory only data pertaining to a
// row that potentially exists in a database.
struct SiteCharacteristicsDatabaseEntry {
  // The origin associated with this row.
  string origin;

  // This row is pending flush to disk.
  bool is_dirty;

  // NULL if the database entry doesn't exist on disk or in memory.
  SiteCharacteristicsDatabaseValue? value;
};

// Contains information about a specific DB instance.
struct SiteCharacteristicsDatabase {
  // Contains the entries requested.
  array<SiteCharacteristicsDatabaseEntry> db_rows;
};

// Discard related information about a single tab in a browser.
struct TabDiscardsInfo {
  // The URL associated with the tab. This corresponds to GetLastCommittedURL,
  // and is also what is visible in the Omnibox for a given tab.
  string tab_url;
  // The title of the tab, as displayed on the tab itself.
  string title;
  // The visibility of the LifecycleUnit.
  LifecycleUnitVisibility visibility;
  // The loading state of the LifecycleUnit.
  mojom.LifecycleUnitLoadingState loading_state;
  // The state of the LifecycleUnit.
  mojom.LifecycleUnitState state;
  // Whether the tab can be frozen.
  bool can_freeze;
  // List of human-readable reasons why a tab can't be frozen.
  array<string> cannot_freeze_reasons;
  // Whether the tab can be discarded.
  bool can_discard;
  // List of human-readable reasons why a tab can't be discarded.
  array<string> cannot_discard_reasons;
  // The number of times this tab has been discarded in the current browser
  // session.
  int32 discard_count;
  // If the tab is currently discarded, the discard reason.
  mojom.LifecycleUnitDiscardReason discard_reason;
  // The rank of the tab in the "importance to user" list. The tab with 1 is the
  // most important, the tab with N is the least important.
  int32 utility_rank;
  // The time the tab was last active (foreground in a window), in seconds.
  int32 last_active_seconds;
  // A unique ID for the tab. This is unique for a browser session and follows a
  // tab across tab strip operations, reloads and discards.
  int32 id;
  // Whether or not the tab is eligible for auto-discarding by the browser.
  // This can be manipulated by the chrome://discards UI, or via the discards
  // extension API.
  bool is_auto_discardable;
  // True if a reactivation score is calculated for the tab. Reactivation score
  // can be predicted only for background tabs.
  bool has_reactivation_score;
  // Tab Ranker reactivation score, if |has_reactivation_score| is true.
  double reactivation_score;
  // Site engagement score.
  double site_engagement_score;
  // Whether or not the tab has input focus.
  bool has_focus;
  // Delta between Unix Epoch and time at which the lifecycle state has changed.
  mojo_base.mojom.TimeDelta state_change_time;
};

// Interface for providing information about discards. Lives in the browser
// process and is invoked in the renderer process via Javascript code running in
// the chrome://discards WebUI.
interface DetailsProvider {
  // Returns an array of TabDiscardsInfo containing discard information about
  // each tab currently open in the browser, across all profiles.
  GetTabDiscardsInfo() => (array<TabDiscardsInfo> infos);

  // Returns the in-memory entries and the entries for the requested origins.
  // Note that any entry may take some time to load from disk, and so there may
  // not be any data for a given entry until on the second or subsequent
  // requests.
  GetSiteCharacteristicsDatabase(
      array<string> explicitly_requested_origins) =>
          (SiteCharacteristicsDatabase? result);

  // Returns the size of the database in number of rows and kilobytes.
  // Note that this may be fairly expensive to acquire, and so shouldn't be
  // called frequently.
  GetSiteCharacteristicsDatabaseSize() =>
      (SiteCharacteristicsDatabaseSize? db_size);

  // Sets the auto-discardable state of a tab, as specified by its stable
  // |tab_id|, earlier returned by GetTabDiscardsInfo. Invokes a callback when
  // the change has been made.
  SetAutoDiscardable(int32 tab_id, bool is_auto_discardable) => ();

  // Discards a tab given its |tab_id|. If |urgent| is specified the unload
  // handlers will not be run, and the tab will be unloaded with prejudice.
  // Invokes a callback when the discard is complete.
  DiscardById(int32 tab_id, bool urgent) => ();

  // Freezes a tab given its |tab_id|.
  FreezeById(int32 tab_id);

  // Loads a tab given its |tab_id|.
  LoadById(int32 tab_id);

  // Discards the least important tab. If |urgent| is specified the unload
  // handlers will not be run, and the tab will be unloaded with prejudice.
  // This can fail to discard a tab if no tabs are currently considered
  // eligible for discard. Invokes a callback when the discard is complete, or
  // if the decision was made not to discard.
  Discard(bool urgent) => ();
};

// Represents the momentary state of a Page CU.
struct PageInfo {
  int64 id;

  url.mojom.Url main_frame_url;

  // TODO(siggi): Estimate data.
};

// Represents the momentary state of a Frame CU.
struct FrameInfo {
  int64 id;

  url.mojom.Url url;
  int64 page_id;
  int64 parent_frame_id;
  int64 process_id;
};

// Represents the momentary state of a Process CU.
struct ProcessInfo {
  int64 id;

  mojo_base.mojom.ProcessId pid;
  mojo_base.mojom.TimeDelta cumulative_cpu_usage;
  uint64 private_footprint_kb;
};

// Used to transport favicon data.
struct FavIconInfo {
  int64 node_id;

  // Contains the base64-encoded icon data, suitable for inclusion in a
  // data URL.
  string icon_data;
};

// Implement to receive a stream of notifications when performance manager
// graph nodes are created, changed or deleted.
interface GraphChangeStream {
  // The |frame| was created.
  FrameCreated(FrameInfo frame);
  // The |page| was created.
  PageCreated(PageInfo pages);
  // The |process| was created.
  ProcessCreated(ProcessInfo process);

  // The |frame| changed.
  FrameChanged(FrameInfo frame);
  // The |page| changed.
  PageChanged(PageInfo page);
  // The |process| changed.
  ProcessChanged(ProcessInfo process);

  // A |favicon| became available, whether because the associated page changed
  // its favicon, or because an initial lookup completed.
  FavIconDataAvailable(FavIconInfo favicon);

  // The node with |node_id| was deleted.
  NodeDeleted(int64 node_id);
};

// This interface allows subscribing to a stream of events that track the state
// of the performance manager graph.
interface GraphDump {
  // Subscribes |change_subscriber| to a graph change stream.
  SubscribeToChanges(pending_remote<GraphChangeStream> change_subscriber);
};