Commit 83a79ccc authored by tby's avatar tby Committed by Commit Bot

[Hashed logging] Log the last-opened app.

This CL adds the most recently launched app to the info included in a
hashed logging event.

Note: there are now a couple of string manipulation functions in
search_controller.cc that probably don't belong there, and are
also duplicated elsewhere. I'll refactor them out into the utilities
class in a separate CL.

Bug: 951287
Change-Id: I0ea7379339aa1ae25788a6c0cc6af73f38a0f004
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1634029Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664134}
parent 239eed83
...@@ -38,6 +38,8 @@ namespace { ...@@ -38,6 +38,8 @@ namespace {
constexpr char kLogDisplayTypeClickedResultZeroState[] = constexpr char kLogDisplayTypeClickedResultZeroState[] =
"Apps.LogDisplayTypeClickedResultZeroState"; "Apps.LogDisplayTypeClickedResultZeroState";
// TODO(931149): Move the string manipulation utilities into a helper class.
// Normalizes training targets by removing any scheme prefix and trailing slash: // Normalizes training targets by removing any scheme prefix and trailing slash:
// "arc://[id]/" to "[id]". This is necessary because apps launched from // "arc://[id]/" to "[id]". This is necessary because apps launched from
// different parts of the launcher have differently formatted IDs. // different parts of the launcher have differently formatted IDs.
...@@ -52,6 +54,16 @@ std::string NormalizeId(const std::string& id) { ...@@ -52,6 +54,16 @@ std::string NormalizeId(const std::string& id) {
return result; return result;
} }
// Remove the Arc app shortcut label from an app ID, if it exists, so that
// "[app]/[label]" becomes "[app]".
std::string RemoveAppShortcutLabel(const std::string& id) {
std::string result(id);
std::size_t delimiter_index = result.find_last_of('/');
if (delimiter_index != std::string::npos)
result.erase(delimiter_index);
return result;
}
} // namespace } // namespace
SearchController::SearchController(AppListModelUpdater* model_updater, SearchController::SearchController(AppListModelUpdater* model_updater,
...@@ -189,10 +201,18 @@ void SearchController::Train(const std::string& id, RankingItemType type) { ...@@ -189,10 +201,18 @@ void SearchController::Train(const std::string& id, RankingItemType type) {
launch_type = ChromeOSAppListLaunchEventProto::RESULTS_LIST; launch_type = ChromeOSAppListLaunchEventProto::RESULTS_LIST;
} }
// TODO(951287): Record the last-used domain and app. // TODO(951287): Record the last-used domain.
AppListLaunchRecorder::GetInstance()->Record( AppListLaunchRecorder::GetInstance()->Record(
{launch_type, NormalizeId(id), base::UTF16ToUTF8(last_query_), {launch_type, NormalizeId(id), base::UTF16ToUTF8(last_query_),
std::string(), std::string()}); std::string(), last_launched_app_id_});
// Only record the last launched app if the hashed logging feature flag is
// enabled, because it is only used by hashed logging.
if (type == RankingItemType::kApp) {
last_launched_app_id_ = NormalizeId(id);
} else if (type == RankingItemType::kArcAppShortcut) {
last_launched_app_id_ = RemoveAppShortcutLabel(NormalizeId(id));
}
} }
for (const auto& provider : providers_) for (const auto& provider : providers_)
......
...@@ -80,6 +80,10 @@ class SearchController { ...@@ -80,6 +80,10 @@ class SearchController {
// The query associated with the most recent search. // The query associated with the most recent search.
base::string16 last_query_; base::string16 last_query_;
// The ID of the most recently launched app. This is used for app list launch
// recording.
std::string last_launched_app_id_;
std::unique_ptr<Mixer> mixer_; std::unique_ptr<Mixer> mixer_;
using Providers = std::vector<std::unique_ptr<SearchProvider>>; using Providers = std::vector<std::unique_ptr<SearchProvider>>;
Providers providers_; Providers providers_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment