Skip to content

Commit

Permalink
[Launcher impressions] Refactor ChromeSearchResult::GetSearchResulType
Browse files Browse the repository at this point in the history
Most search result data is stored in a SearchResultMetadata object,
which is synced between the ash and chrome objects representing results.
One exception is the ash::SearchResultType enum which, confusingly
named, is only used for metrics.

Currently this enum is available via a virtual method on the chrome-side
only. To fix a race condition in the impressions system, we now need to
treat it like other search result data.

This CL adds methods to SearchResultMetadata, deletes the old chrome
getter, updates all ChromeSearchResult subclasses to correctly set the
metadata.

The ChromeSearchResult subclass updates are mostly trivial, these have
slightly more logic:
 - chrome_search_result itself
 - arc_app_data_search_result
 - omnibox_result

Bug: 1076270
Change-Id: I1b1da0e3248031df3f31c2cd8b622dfb0487e390
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2352256
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Thanh Nguyen <thanhdng@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799446}
  • Loading branch information
tby authored and Commit Bot committed Aug 19, 2020
1 parent a39ef6a commit aca16d8
Show file tree
Hide file tree
Showing 39 changed files with 41 additions and 104 deletions.
4 changes: 4 additions & 0 deletions ash/public/cpp/app_list/app_list_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <vector>

#include "ash/public/cpp/app_list/app_list_metrics.h"
#include "ash/public/cpp/ash_public_export.h"
#include "base/optional.h"
#include "base/strings/string16.h"
Expand Down Expand Up @@ -275,6 +276,9 @@ struct ASH_PUBLIC_EXPORT SearchResultMetadata {
// indicates no subtype has been set.
int result_subtype = -1;

// A search result type used for metrics.
ash::SearchResultType metrics_type = ash::SEARCH_RESULT_TYPE_BOUNDARY;

// Which UI container(s) the result should be displayed in.
SearchResultDisplayType display_type = SearchResultDisplayType::kList;

Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/ui/app_list/app_list_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ void AppListClientImpl::OpenSearchResult(const std::string& result_id,
// Send training signal to search controller.
search_controller_->Train(std::move(app_launch_data));

RecordSearchResultOpenTypeHistogram(
launched_from, result->GetSearchResultType(), IsTabletMode());
RecordSearchResultOpenTypeHistogram(launched_from, result->metrics_type(),
IsTabletMode());

if (launch_as_default)
RecordDefaultSearchResultOpenTypeHistogram(result->GetSearchResultType());
RecordDefaultSearchResultOpenTypeHistogram(result->metrics_type());

if (!search_controller_->GetLastQueryLength() &&
launched_from == ash::AppListLaunchedFrom::kLaunchedFromSearchBox)
RecordZeroStateSuggestionOpenTypeHistogram(result->GetSearchResultType());
RecordZeroStateSuggestionOpenTypeHistogram(result->metrics_type());

// OpenResult may cause |result| to be deleted.
search_controller_->OpenResult(result, event_flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ AnswerCardResult::AnswerCardResult(Profile* profile,
DCHECK(!stripped_search_result_url.is_empty());
SetDisplayType(ash::SearchResultDisplayType::kCard);
SetResultType(ash::AppListSearchResultType::kAnswerCard);
SetMetricsType(ash::ANSWER_CARD);
SetQueryUrl(potential_card_url);
SetEquivalentResutlId(stripped_search_result_url.spec());
set_id(potential_card_url.spec());
Expand All @@ -33,8 +34,4 @@ void AnswerCardResult::Open(int event_flags) {
ui::DispositionFromEventFlags(event_flags));
}

ash::SearchResultType AnswerCardResult::GetSearchResultType() const {
return ash::ANSWER_CARD;
}

} // namespace app_list
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class AnswerCardResult : public ChromeSearchResult {

void Open(int event_flags) override;

ash::SearchResultType GetSearchResultType() const override;

const GURL& search_result_url() const { return search_result_url_; }

private:
Expand Down
5 changes: 1 addition & 4 deletions chrome/browser/ui/app_list/search/app_result.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ AppResult::AppResult(Profile* profile,
controller_(controller) {
SetDisplayType(ash::SearchResultDisplayType::kTile);
SetResultType(ash::AppListSearchResultType::kInstalledApp);
SetMetricsType(ash::SEARCH_RESULT_TYPE_BOUNDARY);
SetIsRecommendation(is_recommendation);
}

Expand All @@ -41,8 +42,4 @@ void AppResult::UpdateFromLastLaunchedOrInstalledTime(
set_relevance(1 / (weeks + 1));
}

ash::SearchResultType AppResult::GetSearchResultType() const {
return ash::SEARCH_RESULT_TYPE_BOUNDARY;
}

} // namespace app_list
2 changes: 0 additions & 2 deletions chrome/browser/ui/app_list/search/app_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class AppResult : public ChromeSearchResult, public AppContextMenuDelegate {

const std::string& app_id() const { return app_id_; }

ash::SearchResultType GetSearchResultType() const override;

base::WeakPtr<AppResult> GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/app_list/search/app_service_app_result.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ AppServiceAppResult::AppServiceAppResult(Profile* profile,
CallLoadIcon(true, allow_placeholder_icon);
}

SetMetricsType(GetSearchResultType());

switch (app_type_) {
case apps::mojom::AppType::kBuiltIn:
set_id(app_id);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/app_list/search/app_service_app_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class AppServiceAppResult : public AppResult {
void Open(int event_flags) override;
void GetContextMenuModel(GetMenuModelCallback callback) override;
void OnVisibilityChanged(bool visibility) override;
ash::SearchResultType GetSearchResultType() const override;
AppContextMenu* GetAppContextMenu() override;

// AppContextMenuDelegate overrides:
void ExecuteLaunchCommand(int event_flags) override;

ash::SearchResultType GetSearchResultType() const;
void Launch(int event_flags, apps::mojom::LaunchSource launch_source);

void CallLoadIcon(bool chip, bool allow_placeholder_icon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ ArcAppDataSearchResult::ArcAppDataSearchResult(
set_id(kAppDataSearchPrefix + launch_intent_uri());
if (data_->type == arc::mojom::AppDataResultType::PERSON) {
SetDisplayType(ash::SearchResultDisplayType::kTile);
SetMetricsType(ash::APP_DATA_RESULT_PERSON);
} else if (data_->type == arc::mojom::AppDataResultType::NOTE_DOCUMENT) {
SetDetails(base::UTF8ToUTF16(data_->text));
SetDisplayType(ash::SearchResultDisplayType::kList);
SetMetricsType(ash::APP_DATA_RESULT_NOTE_DOCUMENT);
} else {
NOTREACHED();
SetMetricsType(ash::SEARCH_RESULT_TYPE_BOUNDARY);
}

// TODO(warx): set default images when icon_png_data() is not available.
Expand Down Expand Up @@ -144,16 +149,4 @@ void ArcAppDataSearchResult::ApplyIcon(const gfx::ImageSkia& icon) {
SetIcon(icon);
}

ash::SearchResultType ArcAppDataSearchResult::GetSearchResultType() const {
switch (data_->type) {
case arc::mojom::AppDataResultType::PERSON:
return ash::APP_DATA_RESULT_PERSON;
case arc::mojom::AppDataResultType::NOTE_DOCUMENT:
return ash::APP_DATA_RESULT_NOTE_DOCUMENT;
default:
NOTREACHED();
return ash::SEARCH_RESULT_TYPE_BOUNDARY;
}
}

} // namespace app_list
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ArcAppDataSearchResult : public ChromeSearchResult {
// ChromeSearchResult:
void GetContextMenuModel(GetMenuModelCallback callback) override;
void Open(int event_flags) override;
ash::SearchResultType GetSearchResultType() const override;

private:
const std::string& launch_intent_uri() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ArcAppReinstallAppResult::ArcAppReinstallAppResult(
SetResultType(ash::AppListSearchResultType::kPlayStoreReinstallApp);
SetTitle(base::UTF8ToUTF16(mojom_data->title));
SetDisplayType(ash::SearchResultDisplayType::kTile);
SetMetricsType(ash::PLAY_STORE_REINSTALL_APP);
SetDisplayIndex(ash::SearchResultDisplayIndex::kSixthIndex);
SetIsRecommendation(true);
set_relevance(kAppReinstallRelevance);
Expand All @@ -59,8 +60,4 @@ void ArcAppReinstallAppResult::OnVisibilityChanged(bool visibility) {
observer_->OnVisibilityChanged(package_name_, visibility);
}

ash::SearchResultType ArcAppReinstallAppResult::GetSearchResultType() const {
return ash::PLAY_STORE_REINSTALL_APP;
}

} // namespace app_list
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class ArcAppReinstallAppResult : public ChromeSearchResult {
// ChromeSearchResult:
void Open(int event_flags) override;
void OnVisibilityChanged(bool visibility) override;
ash::SearchResultType GetSearchResultType() const override;

private:
// Observer passed in constructor. not owned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ class TestSearchResult : public ChromeSearchResult {
// set_id is protected in chromesearchresult.
ChromeSearchResult::set_id(str);
}
ash::SearchResultType GetSearchResultType() const override {
return ash::SEARCH_RESULT_TYPE_BOUNDARY;
}
};
} // namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ArcAppShortcutSearchResult::ArcAppShortcutSearchResult(
SetAccessibleName(ComputeAccessibleName());
SetResultType(ash::AppListSearchResultType::kArcAppShortcut);
SetDisplayType(ash::SearchResultDisplayType::kTile);
SetMetricsType(ash::PLAY_STORE_APP_SHORTCUT);
SetIsRecommendation(is_recommendation);

const int icon_dimension =
Expand Down Expand Up @@ -81,10 +82,6 @@ void ArcAppShortcutSearchResult::Open(int event_flags) {
list_controller_->GetAppListDisplayId());
}

ash::SearchResultType ArcAppShortcutSearchResult::GetSearchResultType() const {
return ash::PLAY_STORE_APP_SHORTCUT;
}

void ArcAppShortcutSearchResult::OnAppImageUpdated(
const std::string& app_id,
const gfx::ImageSkia& image) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class ArcAppShortcutSearchResult : public ChromeSearchResult,

// ChromeSearchResult:
void Open(int event_flags) override;
ash::SearchResultType GetSearchResultType() const override;

private:
// AppIconLoaderDelegate:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ ArcPlayStoreSearchResult::ArcPlayStoreSearchResult(
SetRating(review_score());
SetResultType(is_instant_app() ? ash::AppListSearchResultType::kInstantApp
: ash::AppListSearchResultType::kPlayStoreApp);
SetMetricsType(is_instant_app() ? ash::PLAY_STORE_INSTANT_APP
: ash::PLAY_STORE_UNINSTALLED_APP);

if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
apps::ArcRawIconPngDataToImageSkia(
Expand Down Expand Up @@ -160,11 +162,6 @@ void ArcPlayStoreSearchResult::Open(int event_flags) {
list_controller_->GetAppListDisplayId());
}

ash::SearchResultType ArcPlayStoreSearchResult::GetSearchResultType() const {
return is_instant_app() ? ash::PLAY_STORE_INSTANT_APP
: ash::PLAY_STORE_UNINSTALLED_APP;
}

void ArcPlayStoreSearchResult::GetContextMenuModel(
GetMenuModelCallback callback) {
context_menu_ = std::make_unique<ArcPlayStoreAppContextMenu>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ArcPlayStoreSearchResult : public ChromeSearchResult,
// ChromeSearchResult overrides:
void GetContextMenuModel(GetMenuModelCallback callback) override;
void Open(int event_flags) override;
ash::SearchResultType GetSearchResultType() const override;

// app_list::AppContextMenuDelegate overrides:
void ExecuteLaunchCommand(int event_flags) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class AssistantSearchResult : public ChromeSearchResult {
SetDisplayIndex(ash::SearchResultDisplayIndex::kFirstIndex);
SetDisplayType(ash::SearchResultDisplayType::kChip);
SetResultType(ash::AppListSearchResultType::kAssistantChip);
SetMetricsType(ash::SearchResultType::ASSISTANT);
SetTitle(base::UTF8ToUTF16(conversation_starter.text));
SetChipIcon(gfx::CreateVectorIcon(
ash::kAssistantIcon,
Expand All @@ -97,11 +98,6 @@ class AssistantSearchResult : public ChromeSearchResult {
~AssistantSearchResult() override = default;

private:
// ChromeSearchResult:
ash::SearchResultType GetSearchResultType() const override {
return ash::SearchResultType::ASSISTANT;
}

void Open(int event_flags) override {
// Opening of |action_url_| is delegated to the Assistant controller as only
// the Assistant controller knows how to handle Assistant deep links.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Expect {
EXPECT_EQ(r_.display_index(), ash::SearchResultDisplayIndex::kFirstIndex);
EXPECT_EQ(r_.display_type(), ash::SearchResultDisplayType::kChip);
EXPECT_EQ(r_.result_type(), ash::AppListSearchResultType::kAssistantChip);
EXPECT_EQ(r_.GetSearchResultType(), ash::SearchResultType::ASSISTANT);
EXPECT_EQ(r_.metrics_type(), ash::SearchResultType::ASSISTANT);
EXPECT_TRUE(r_.chip_icon().BackedBySameObjectAs(gfx::CreateVectorIcon(
ash::kAssistantIcon,
ash::AppListConfig::instance().suggestion_chip_icon_dimension(),
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/ui/app_list/search/chrome_search_result.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ void ChromeSearchResult::SetResultType(ResultType result_type) {
SetSearchResultMetadata();
}

void ChromeSearchResult::SetMetricsType(MetricsType metrics_type) {
metadata_->metrics_type = metrics_type;
SetSearchResultMetadata();
}

void ChromeSearchResult::SetDisplayIndex(DisplayIndex display_index) {
metadata_->display_index = display_index;
SetSearchResultMetadata();
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/app_list/search/chrome_search_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ChromeSearchResult {
public:
using ResultType = ash::AppListSearchResultType;
using DisplayType = ash::SearchResultDisplayType;
using MetricsType = ash::SearchResultType;
using Tag = ash::SearchResultTag;
using Tags = ash::SearchResultTags;
using Action = ash::SearchResultAction;
Expand All @@ -59,6 +60,7 @@ class ChromeSearchResult {
ash::AppListSearchResultType result_type() const {
return metadata_->result_type;
}
MetricsType metrics_type() const { return metadata_->metrics_type; }
DisplayIndex display_index() const { return metadata_->display_index; }
float position_priority() const { return metadata_->position_priority; }
const Actions& actions() const { return metadata_->actions; }
Expand Down Expand Up @@ -88,6 +90,7 @@ class ChromeSearchResult {
void SetFormattedPrice(const base::string16& formatted_price);
void SetDisplayType(DisplayType display_type);
void SetResultType(ResultType result_type);
void SetMetricsType(MetricsType metrics_type);
void SetDisplayIndex(DisplayIndex display_index);
void SetPositionPriority(float position_priority);
void SetDisplayScore(double display_score);
Expand Down Expand Up @@ -155,9 +158,6 @@ class ChromeSearchResult {
// subtype after construction is not reflected in ash.
int result_subtype() const { return metadata_->result_subtype; }

// Get the type of the result, used in metrics.
virtual ash::SearchResultType GetSearchResultType() const = 0;

protected:
// These id setters should be called in derived class constructors only.
void set_id(const std::string& id) { metadata_->id = id; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ DriveQuickAccessResult::DriveQuickAccessResult(const base::FilePath& filepath,
: ZeroStateFileResult(filepath, relevance, profile) {
set_id(kDriveQuickAccessResultPrefix + filepath.value());
SetResultType(ResultType::kDriveQuickAccess);
}

ash::SearchResultType DriveQuickAccessResult::GetSearchResultType() const {
return ash::DRIVE_QUICK_ACCESS;
SetMetricsType(ash::DRIVE_QUICK_ACCESS);
}

} // namespace app_list
3 changes: 0 additions & 3 deletions chrome/browser/ui/app_list/search/drive_quick_access_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class DriveQuickAccessResult : public ZeroStateFileResult {
DriveQuickAccessResult(const base::FilePath& filepath,
float relevance,
Profile* profile);

// ZeroStateFileResult:
ash::SearchResultType GetSearchResultType() const override;
};

} // namespace app_list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ void LauncherSearchResult::Open(int event_flags) {
service->OnOpenResult(extension_->id(), item_id_);
}

ash::SearchResultType LauncherSearchResult::GetSearchResultType() const {
return ash::LAUNCHER_SEARCH_PROVIDER_RESULT;
}

LauncherSearchResult::LauncherSearchResult(
const std::string& item_id,
const std::string& icon_type,
Expand All @@ -81,6 +77,7 @@ void LauncherSearchResult::Initialize() {
chromeos::launcher_search_provider::kMaxSearchResultScore));
SetDetails(base::UTF8ToUTF16(extension_->name()));
SetResultType(ResultType::kLauncher);
SetMetricsType(ash::LAUNCHER_SEARCH_PROVIDER_RESULT);

SetIcon(GetIconFromType(icon_type_));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class LauncherSearchResult : public ChromeSearchResult {

// ChromeSearchResult overrides:
void Open(int event_flags) override;
ash::SearchResultType GetSearchResultType() const override;

private:
// Constructor for duplicating a result.
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/app_list/search/omnibox_result.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ OmniboxResult::OmniboxResult(Profile* profile,
set_id(match_.stripped_destination_url.spec());
SetResultType(ash::AppListSearchResultType::kOmnibox);
set_result_subtype(static_cast<int>(match_.type));
SetMetricsType(GetSearchResultType());

// Derive relevance from omnibox relevance and normalize it to [0, 1].
// The magic number 1500 is the highest score of an omnibox result.
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/ui/app_list/search/omnibox_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class OmniboxResult : public ChromeSearchResult {
// ChromeSearchResult overrides:
void Open(int event_flags) override;
void InvokeAction(int action_index, int event_flags) override;
ash::SearchResultType GetSearchResultType() const override;

// Returns the URL that will be navigated to by this search result.
GURL DestinationURL() const;
Expand All @@ -59,6 +58,8 @@ class OmniboxResult : public ChromeSearchResult {

void RecordOmniboxResultHistogram();

ash::SearchResultType GetSearchResultType() const;

Profile* profile_;
AppListControllerDelegate* list_controller_;
AutocompleteController* autocomplete_controller_;
Expand Down
Loading

0 comments on commit aca16d8

Please sign in to comment.