Skip to content

Commit

Permalink
Revert "Remove TabRanker."
Browse files Browse the repository at this point in the history
This reverts commit 979b218.

Reason for revert: Main suspect for causing a build breakage at https://ci.chromium.org/ui/p/chromium/builders/ci/chromeos-octopus-rel/8968/overview

Original change's description:
> Remove TabRanker.
>
> It is not used.
>
> Bug: 784639
> Change-Id: Idd4dc6f0dd8603d3e51b671aab68d761c90580f1
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4064839
> Reviewed-by: Charles Zhao <charleszhao@chromium.org>
> Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
> Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1084960}

Bug: 784639
Change-Id: I735b21c09f9af16a3e6f840d851ae287a2bf9c32
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4116477
Owners-Override: Łukasz Anforowicz <lukasza@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: Iman Saboori <isaboori@google.com>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1085045}
  • Loading branch information
anforowicz authored and Chromium LUCI CQ committed Dec 19, 2022
1 parent ac13ecf commit 0e4647c
Show file tree
Hide file tree
Showing 29 changed files with 7,343 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/BUILD.gn
Expand Up @@ -4399,6 +4399,8 @@ static_library("browser") {
"//chrome/browser/policy:path_parser",
"//chrome/browser/profile_resetter:profile_reset_report_proto",
"//chrome/browser/resource_coordinator:intervention_policy_database_proto",
"//chrome/browser/resource_coordinator:tab_metrics_event_proto",
"//chrome/browser/resource_coordinator/tab_ranker",
"//chrome/browser/resources:component_extension_resources",
"//chrome/browser/share/core:share_targets",
"//chrome/browser/share/proto:proto",
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ash/BUILD.gn
Expand Up @@ -3323,6 +3323,7 @@ source_set("ash") {
"//chrome/browser/image_decoder",
"//chrome/browser/policy/messaging_layer/proto:crd_event_proto",
"//chrome/browser/profiles:profile",
"//chrome/browser/resource_coordinator:tab_metrics_event_proto",
"//chrome/browser/safe_browsing",
"//chrome/browser/ui/webui/ash/crostini_upgrader:mojo_bindings_headers",
"//chrome/browser/ui/webui/bluetooth_internals:mojo_bindings",
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/browser_resources.grd
Expand Up @@ -325,6 +325,10 @@
<include name="IDR_RESET_PASSWORD_JS" file="${root_gen_dir}\chrome\browser\resources\reset_password\tsc\reset_password.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_RESET_PASSWORD_MOJOM_WEBUI_JS" file="${root_gen_dir}\chrome\browser\resources\reset_password\tsc\reset_password.mojom-webui.js" use_base_dir="false" type="BINDATA" />
</if>
<if expr="not is_android">
<include name="IDR_TAB_RANKER_EXAMPLE_PREPROCESSOR_CONFIG_PB" file="resource_coordinator\tab_ranker\example_preprocessor_config.pb" type="BINDATA" />
<include name="IDR_TAB_RANKER_PAIRWISE_EXAMPLE_PREPROCESSOR_CONFIG_PB" file="resource_coordinator\tab_ranker\pairwise_preprocessor_config.pb" type="BINDATA" />
</if>
<if expr="chromeos_ash">
<include name="IDR_SMART_DIM_20190521_EXAMPLE_PREPROCESSOR_CONFIG_PB" file="ash\power\ml\smart_dim\20190521_example_preprocessor_config.pb" type="BINDATA" />
</if>
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/chromeos/BUILD.gn
Expand Up @@ -172,6 +172,7 @@ source_set("chromeos") {
"//chrome/browser/policy/messaging_layer/proto:crd_event_proto",
"//chrome/browser/profiles",
"//chrome/browser/profiles:profile",
"//chrome/browser/resource_coordinator:tab_metrics_event_proto",
"//chrome/browser/resources/chromeos:app_icon_resources",
"//chrome/browser/resources/chromeos/cloud_upload:resources_grit",
"//chrome/browser/resources/settings:resources_grit",
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/resource_coordinator/BUILD.gn
Expand Up @@ -6,6 +6,10 @@ import("//chrome/common/features.gni")
import("//mojo/public/tools/bindings/mojom.gni")
import("//third_party/protobuf/proto_library.gni")

proto_library("tab_metrics_event_proto") {
sources = [ "tab_metrics_event.proto" ]
}

mojom("mojo_bindings") {
sources = [ "lifecycle_unit_state.mojom" ]
webui_module_path = "/"
Expand Down
82 changes: 82 additions & 0 deletions chrome/browser/resource_coordinator/tab_metrics_event.proto
@@ -0,0 +1,82 @@
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;

package metrics;

// Defines specialized fields used by the TabManager.TabMetrics UKM event.
message TabMetricsEvent {
// Represents the MIME type of content.
// MIME type strings have the format "<type>/<subtype>". The values for
// ContentType reflect just the top-level type (e.g., AUDIO is used for both
// "audio/mp3" and "audio/ogg").
// The exception is "text/html", since it's treated quite differently than
// other text.
enum ContentType {
// Could not be determined or not available.
CONTENT_TYPE_UNKNOWN = 0;

// Not one of the types below.
CONTENT_TYPE_OTHER = 1;

// The "application/*" type. Supported application sub-types are enumerated
// in Chrome's PluginType.
CONTENT_TYPE_APPLICATION = 2;

// The "audio/*" type.
CONTENT_TYPE_AUDIO = 3;

// The "image/*" type.
CONTENT_TYPE_IMAGE = 4;

// The "text/*" type. For "text/html", TEXT_HTML is used instead.
CONTENT_TYPE_TEXT = 5;

// The "text/html" type, representing web pages.
CONTENT_TYPE_TEXT_HTML = 6;

// The "video/*" type.
CONTENT_TYPE_VIDEO = 7;
}

optional ContentType content_type = 1;
}

// Defines specialized fields used by the TabManager.WindowMetrics UKM event
// for describing the window used by a set of tabs.
message WindowMetricsEvent {
// Represents the type of the window.
enum Type {
// Could not be determined or not available.
TYPE_UNKNOWN = 0;

// A normal browser window with a tab strip.
TYPE_TABBED = 1;

// A pop-up browser window with no tab strip.
TYPE_POPUP = 2;

// An Extension browser window that is not an AppWindow.
TYPE_EXTENSION = 3;

// An AppWindow for a platform app.
TYPE_APP = 4;
}

optional Type type = 1;

// Represents the show state of the window.
enum ShowState {
SHOW_STATE_UNKNOWN = 0;
SHOW_STATE_NORMAL = 1;
SHOW_STATE_MINIMIZED = 2;
SHOW_STATE_MAXIMIZED = 3;
SHOW_STATE_FULLSCREEN = 4;
}

optional ShowState show_state = 2;
}
46 changes: 46 additions & 0 deletions chrome/browser/resource_coordinator/tab_ranker/BUILD.gn
@@ -0,0 +1,46 @@
# Copyright 2018 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

source_set("tab_ranker") {
# Dependent targets should not include native_inference.h directly.
public = [
"mru_features.h",
"tab_features.h",
"tab_score_predictor.h",
"window_features.h",
]

sources = [
"native_inference.cc",
"native_inference.h",
"pairwise_inference.cc",
"pairwise_inference.h",
"tab_features.cc",
"tab_score_predictor.cc",
"window_features.cc",
]

public_deps = [ "//base" ]

deps = [
"//chrome/browser:resources",
"//chrome/browser/resource_coordinator:tab_manager_features",
"//chrome/browser/resource_coordinator:tab_metrics_event_proto",
"//components/assist_ranker",
"//components/assist_ranker/proto",
"//components/sessions",
"//services/metrics/public/cpp:ukm_builders",
]
}

# target for using GetFullTabFeaturesForTesting in unit tests.
static_library("tab_features_test_helper") {
testonly = true
sources = [
"tab_features_test_helper.cc",
"tab_features_test_helper.h",
]

deps = [ ":tab_ranker" ]
}
3 changes: 3 additions & 0 deletions chrome/browser/resource_coordinator/tab_ranker/OWNERS
@@ -0,0 +1,3 @@
amoylan@chromium.org
charleszhao@chromium.org
michaelpg@chromium.org
56 changes: 56 additions & 0 deletions chrome/browser/resource_coordinator/tab_ranker/README.md
@@ -0,0 +1,56 @@
# Tab Ranker

The Tab Ranker is an experimental model used to predict tab reactivation. We
are setting up experiments to use this model as a factor in deciding which tabs
to discard when the system is low on memory.

## Model

The input to the model is a list of metrics about a background tab, such as
whether it is pinned, how long it has been in the background, and how many
events it has received. The output is a floating point value, where a higher
number suggests the tab is more likely to be reactivated than a lower number.
The range of possible outputs is dependent on the model; what matters is the
relative ordering of scores, not the precise value of a score.

The metrics used for inference are the same metrics logged to UKM by
TabMetricsLogger. Using these metrics, we trained a
[DNN](https://en.wikipedia.org/wiki/Deep_learning#Deep_neural_networks) model.
The inferencing code in `native_inference.cc` consists of the model weights
generated by TensorFlow and basic operations to execute the model over an
example.

See [native_inference.md] for details on how the tf.native code is cleaned up
for Chromium.

## Example preprocessing

Examples are provided to the model as an array of floats, with each element
corresponding to a feature. For scalar metrics like WasRecentlyActive(), this
feature is simply a 0 or 1.

A metric with multiple possible values, like an enum or bucketized number, is
broken into a number of features, each corresponding to one of its possible
values. For example, a value of 7 for the PageTransitionCoreType metric is
represented as a 1 in the `PageTransitionCoreType_7` feature. See
https://en.wikipedia.org/wiki/One-hot.

The AssistRanker handles this example preprocessing based on the configuration
provided in example_preprocessor_config.pb. This can be examined with the
`print_example_preprocessor_config.py` utility:

```
./components/assist_ranker/print_example_preprocessor_config.py \
out/Release \
chrome/browser/resource_coordinator/tab_ranker/example_preprocessor_config.pb
```

## Scoring a tab

Use `TabActivityWatcher::CalculateReactivationScore()` to get a score from a
WebContents.

Internally, `TabScorePredictor::ScoreTab` is the interface to the model. The
caller needs to track a number of metrics about the tab and its window. These
metrics must be calculated in the same way they were logged, as otherwise the
results will not be valid.
Binary file not shown.
25 changes: 25 additions & 0 deletions chrome/browser/resource_coordinator/tab_ranker/mru_features.h
@@ -0,0 +1,25 @@
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_RANKER_MRU_FEATURES_H_
#define CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_RANKER_MRU_FEATURES_H_

#include <stdint.h>

namespace tab_ranker {

// Identifies how recently the tab was used.
struct MRUFeatures {
// Zero-based, so this indicates how many of the |total| tabs are more
// recently used than this tab.
int index = 0;

// Total number of tabs considered when calculating MRU index, ie number of
// non-incognito tabs open.
int total = 0;
};

} // namespace tab_ranker

#endif // CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_RANKER_MRU_FEATURES_H_

0 comments on commit 0e4647c

Please sign in to comment.