Commit e3c7b644 authored by Thanh Nguyen's avatar Thanh Nguyen Committed by Commit Bot

[Cros SR logging] Initial check-in for zero-state logging.

Add codes in ash that notify chrome about the list of items being
shown to users if any items got clicked. The data
processing and logging parts in chrome will be implemented later.

Bug: 972817
Change-Id: I4a311a4f00838a2966ee813e9606dc1b5eb24ebd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1677807
Commit-Queue: Thanh Nguyen <thanhdng@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarJenny Zhang <jennyz@chromium.org>
Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679810}
parent 3820b726
...@@ -1161,6 +1161,17 @@ void AppListControllerImpl::OnSearchResultVisibilityChanged( ...@@ -1161,6 +1161,17 @@ void AppListControllerImpl::OnSearchResultVisibilityChanged(
client_->OnSearchResultVisibilityChanged(id, visibility); client_->OnSearchResultVisibilityChanged(id, visibility);
} }
void AppListControllerImpl::NotifySearchResultsForLogging(
const base::string16& raw_query,
const ash::SearchResultIdWithPositionIndices& results,
int position_index) {
if (client_) {
base::string16 query;
base::TrimWhitespace(raw_query, base::TRIM_ALL, &query);
client_->NotifySearchResultsForLogging(query, results, position_index);
}
}
bool AppListControllerImpl::IsAssistantAllowedAndEnabled() const { bool AppListControllerImpl::IsAssistantAllowedAndEnabled() const {
if (!chromeos::switches::IsAssistantEnabled()) if (!chromeos::switches::IsAssistantEnabled())
return false; return false;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "ash/app_list/app_list_metrics.h" #include "ash/app_list/app_list_metrics.h"
...@@ -200,6 +201,10 @@ class ASH_EXPORT AppListControllerImpl ...@@ -200,6 +201,10 @@ class ASH_EXPORT AppListControllerImpl
ash::AssistantViewDelegate* GetAssistantViewDelegate() override; ash::AssistantViewDelegate* GetAssistantViewDelegate() override;
void OnSearchResultVisibilityChanged(const std::string& id, void OnSearchResultVisibilityChanged(const std::string& id,
bool visibility) override; bool visibility) override;
void NotifySearchResultsForLogging(
const base::string16& raw_query,
const ash::SearchResultIdWithPositionIndices& results,
int position_index) override;
bool IsAssistantAllowedAndEnabled() const override; bool IsAssistantAllowedAndEnabled() const override;
bool ShouldShowAssistantPrivacyInfo() const override; bool ShouldShowAssistantPrivacyInfo() const override;
void MaybeIncreaseAssistantPrivacyInfoShownCount() override; void MaybeIncreaseAssistantPrivacyInfoShownCount() override;
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#ifndef ASH_APP_LIST_APP_LIST_VIEW_DELEGATE_H_ #ifndef ASH_APP_LIST_APP_LIST_VIEW_DELEGATE_H_
#define ASH_APP_LIST_APP_LIST_VIEW_DELEGATE_H_ #define ASH_APP_LIST_APP_LIST_VIEW_DELEGATE_H_
#include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "ash/app_list/app_list_metrics.h" #include "ash/app_list/app_list_metrics.h"
...@@ -169,6 +171,18 @@ class ASH_PUBLIC_EXPORT AppListViewDelegate { ...@@ -169,6 +171,18 @@ class ASH_PUBLIC_EXPORT AppListViewDelegate {
virtual void OnSearchResultVisibilityChanged(const std::string& id, virtual void OnSearchResultVisibilityChanged(const std::string& id,
bool visibility) = 0; bool visibility) = 0;
// Called if a search result item got clicked, or a list of search result has
// been shown to the user after a certain amount of time. |raw_query| is the
// raw query that produced the results, |results| is a list of items that were
// being shown to the users and their corresponding position indices of them
// (see |SearchResultIdWithPositionIndex| for more details),
// |position_index| is the position index of the clicked item (if no item got
// clicked, |position_index| will be -1).
virtual void NotifySearchResultsForLogging(
const base::string16& raw_query,
const ash::SearchResultIdWithPositionIndices& results,
int position_index) = 0;
// Returns true if the Assistant feature is allowed and enabled. // Returns true if the Assistant feature is allowed and enabled.
virtual bool IsAssistantAllowedAndEnabled() const = 0; virtual bool IsAssistantAllowedAndEnabled() const = 0;
......
...@@ -167,6 +167,11 @@ void AppListTestViewDelegate::OnSearchResultVisibilityChanged( ...@@ -167,6 +167,11 @@ void AppListTestViewDelegate::OnSearchResultVisibilityChanged(
const std::string& id, const std::string& id,
bool visibility) {} bool visibility) {}
void AppListTestViewDelegate::NotifySearchResultsForLogging(
const base::string16& raw_query,
const ash::SearchResultIdWithPositionIndices& results,
int position_index) {}
bool AppListTestViewDelegate::IsAssistantAllowedAndEnabled() const { bool AppListTestViewDelegate::IsAssistantAllowedAndEnabled() const {
return false; return false;
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "ash/app_list/app_list_view_delegate.h" #include "ash/app_list/app_list_view_delegate.h"
...@@ -101,6 +102,10 @@ class AppListTestViewDelegate : public AppListViewDelegate, ...@@ -101,6 +102,10 @@ class AppListTestViewDelegate : public AppListViewDelegate,
ash::AssistantViewDelegate* GetAssistantViewDelegate() override; ash::AssistantViewDelegate* GetAssistantViewDelegate() override;
void OnSearchResultVisibilityChanged(const std::string& id, void OnSearchResultVisibilityChanged(const std::string& id,
bool visibility) override; bool visibility) override;
void NotifySearchResultsForLogging(
const base::string16& raw_query,
const ash::SearchResultIdWithPositionIndices& results,
int position_index) override;
bool IsAssistantAllowedAndEnabled() const override; bool IsAssistantAllowedAndEnabled() const override;
bool ShouldShowAssistantPrivacyInfo() const override; bool ShouldShowAssistantPrivacyInfo() const override;
void MaybeIncreaseAssistantPrivacyInfoShownCount() override; void MaybeIncreaseAssistantPrivacyInfoShownCount() override;
......
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
#ifndef ASH_APP_LIST_TEST_TEST_APP_LIST_CLIENT_H_ #ifndef ASH_APP_LIST_TEST_TEST_APP_LIST_CLIENT_H_
#define ASH_APP_LIST_TEST_TEST_APP_LIST_CLIENT_H_ #define ASH_APP_LIST_TEST_TEST_APP_LIST_CLIENT_H_
#include <memory>
#include <string> #include <string>
#include <utility>
#include <vector>
#include "ash/public/cpp/app_list/app_list_client.h" #include "ash/public/cpp/app_list/app_list_client.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -58,6 +61,10 @@ class TestAppListClient : public app_list::AppListClient { ...@@ -58,6 +61,10 @@ class TestAppListClient : public app_list::AppListClient {
override {} override {}
void OnSearchResultVisibilityChanged(const std::string& id, void OnSearchResultVisibilityChanged(const std::string& id,
bool visibility) override {} bool visibility) override {}
void NotifySearchResultsForLogging(
const base::string16& trimmed_query,
const ash::SearchResultIdWithPositionIndices& results,
int position_index) override {}
private: private:
DISALLOW_COPY_AND_ASSIGN(TestAppListClient); DISALLOW_COPY_AND_ASSIGN(TestAppListClient);
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector> #include <vector>
#include "ash/app_list/app_list_metrics.h" #include "ash/app_list/app_list_metrics.h"
...@@ -32,6 +35,8 @@ namespace app_list { ...@@ -32,6 +35,8 @@ namespace app_list {
namespace { namespace {
constexpr int kMaxResults = 5; constexpr int kMaxResults = 5;
constexpr base::TimeDelta kImpressionThreshold =
base::TimeDelta::FromSeconds(3);
constexpr SkColor kListVerticalBarIconColor = constexpr SkColor kListVerticalBarIconColor =
SkColorSetARGB(0xFF, 0xE8, 0xEA, 0xED); SkColorSetARGB(0xFF, 0xE8, 0xEA, 0xED);
...@@ -110,6 +115,17 @@ void CalculateDisplayIcons( ...@@ -110,6 +115,17 @@ void CalculateDisplayIcons(
} }
} }
ash::SearchResultIdWithPositionIndices GetSearchResultsForLogging(
std::vector<SearchResultView*> search_result_views) {
ash::SearchResultIdWithPositionIndices results;
for (const auto* item : search_result_views) {
if (item->result()) {
results.emplace_back(ash::SearchResultIdWithPositionIndex(
item->result()->id(), item->index_in_container()));
}
}
return results;
}
} // namespace } // namespace
SearchResultListView::SearchResultListView(AppListMainView* main_view, SearchResultListView::SearchResultListView(AppListMainView* main_view,
...@@ -195,12 +211,33 @@ int SearchResultListView::DoUpdate() { ...@@ -195,12 +211,33 @@ int SearchResultListView::DoUpdate() {
} }
} }
// Logic for logging impression of items that were shown to user.
// Each time DoUpdate() called, start a timer that will be fired after a
// certain amount of time |kImpressionThreshold|. If during the waiting time,
// there's another DoUpdate() called, reset the timer and start a new timer
// with updated result list.
if (impression_timer_.IsRunning())
impression_timer_.Stop();
impression_timer_.Start(FROM_HERE, kImpressionThreshold, this,
&SearchResultListView::LogImpressions);
set_container_score( set_container_score(
display_results.empty() ? 0 : display_results.front()->display_score()); display_results.empty() ? 0 : display_results.front()->display_score());
return display_results.size(); return display_results.size();
} }
void SearchResultListView::LogImpressions() {
// Since no items is actually clicked, send the position index of clicked item
// as -1.
if (main_view_->search_box_view()->is_search_box_active()) {
view_delegate_->NotifySearchResultsForLogging(
view_delegate_->GetSearchModel()->search_box()->text(),
GetSearchResultsForLogging(search_result_views_),
-1 /* position_index */);
}
}
void SearchResultListView::Layout() { void SearchResultListView::Layout() {
results_container_->SetBoundsRect(GetLocalBounds()); results_container_->SetBoundsRect(GetLocalBounds());
} }
...@@ -224,6 +261,10 @@ void SearchResultListView::SearchResultActivated(SearchResultView* view, ...@@ -224,6 +261,10 @@ void SearchResultListView::SearchResultActivated(SearchResultView* view,
view_delegate_->GetSearchModel()); view_delegate_->GetSearchModel());
view_delegate_->LogResultLaunchHistogram( view_delegate_->LogResultLaunchHistogram(
SearchResultLaunchLocation::kResultList, view->index_in_container()); SearchResultLaunchLocation::kResultList, view->index_in_container());
view_delegate_->NotifySearchResultsForLogging(
view_delegate_->GetSearchModel()->search_box()->text(),
GetSearchResultsForLogging(search_result_views_),
view->index_in_container());
view_delegate_->OpenSearchResult( view_delegate_->OpenSearchResult(
view->result()->id(), event_flags, view->result()->id(), event_flags,
ash::AppListLaunchedFrom::kLaunchedFromSearchBox, ash::AppListLaunchedFrom::kLaunchedFromSearchBox,
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ash/app_list/views/search_result_view.h" #include "ash/app_list/views/search_result_view.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace app_list { namespace app_list {
...@@ -65,6 +66,9 @@ class APP_LIST_EXPORT SearchResultListView : public SearchResultContainerView { ...@@ -65,6 +66,9 @@ class APP_LIST_EXPORT SearchResultListView : public SearchResultContainerView {
// Overridden from views::View: // Overridden from views::View:
void Layout() override; void Layout() override;
int GetHeightForWidth(int w) const override; int GetHeightForWidth(int w) const override;
// Log the set of recommendations (impression) that were shown to the user
// after a priod of time.
void LogImpressions();
AppListMainView* main_view_; // Owned by views hierarchy. AppListMainView* main_view_; // Owned by views hierarchy.
AppListViewDelegate* view_delegate_; // Not owned. AppListViewDelegate* view_delegate_; // Not owned.
...@@ -73,6 +77,9 @@ class APP_LIST_EXPORT SearchResultListView : public SearchResultContainerView { ...@@ -73,6 +77,9 @@ class APP_LIST_EXPORT SearchResultListView : public SearchResultContainerView {
std::vector<SearchResultView*> search_result_views_; // Not owned. std::vector<SearchResultView*> search_result_views_; // Not owned.
// Used for logging impression shown to users.
base::OneShotTimer impression_timer_;
DISALLOW_COPY_AND_ASSIGN(SearchResultListView); DISALLOW_COPY_AND_ASSIGN(SearchResultListView);
}; };
......
...@@ -128,6 +128,11 @@ class ASH_PUBLIC_EXPORT AppListClient { ...@@ -128,6 +128,11 @@ class ASH_PUBLIC_EXPORT AppListClient {
mojo::PendingReceiver<content::mojom::NavigableContentsFactory> mojo::PendingReceiver<content::mojom::NavigableContentsFactory>
receiver) = 0; receiver) = 0;
virtual void NotifySearchResultsForLogging(
const base::string16& trimmed_query,
const ash::SearchResultIdWithPositionIndices& results,
int position_index) = 0;
protected: protected:
virtual ~AppListClient() = default; virtual ~AppListClient() = default;
}; };
......
...@@ -300,6 +300,22 @@ struct ASH_PUBLIC_EXPORT SearchResultMetadata { ...@@ -300,6 +300,22 @@ struct ASH_PUBLIC_EXPORT SearchResultMetadata {
bool notify_visibility_change = false; bool notify_visibility_change = false;
}; };
// A struct holding a search result id and its corresponding position index that
// was being shown to the user.
struct SearchResultIdWithPositionIndex {
SearchResultIdWithPositionIndex(std::string result_id, int index)
: id(result_id), position_index(index) {}
// The id of the result.
std::string id;
// The position index of the result.
int position_index;
};
using SearchResultIdWithPositionIndices =
std::vector<SearchResultIdWithPositionIndex>;
} // namespace ash } // namespace ash
#endif // ASH_PUBLIC_CPP_APP_LIST_APP_LIST_TYPES_H_ #endif // ASH_PUBLIC_CPP_APP_LIST_APP_LIST_TYPES_H_
...@@ -3400,6 +3400,8 @@ jumbo_split_static_library("ui") { ...@@ -3400,6 +3400,8 @@ jumbo_split_static_library("ui") {
"app_list/search/common/url_icon_source.h", "app_list/search/common/url_icon_source.h",
"app_list/search/extension_app_result.cc", "app_list/search/extension_app_result.cc",
"app_list/search/extension_app_result.h", "app_list/search/extension_app_result.h",
"app_list/search/logging/search_ranking_event_logger.cc",
"app_list/search/logging/search_ranking_event_logger.h",
"app_list/search/mixer.cc", "app_list/search/mixer.cc",
"app_list/search/mixer.h", "app_list/search/mixer.h",
"app_list/search/omnibox_provider.cc", "app_list/search/omnibox_provider.cc",
......
...@@ -517,6 +517,13 @@ void AppListClientImpl::LaunchApp(Profile* profile, ...@@ -517,6 +517,13 @@ void AppListClientImpl::LaunchApp(Profile* profile,
DismissView(); DismissView();
} }
void AppListClientImpl::NotifySearchResultsForLogging(
const base::string16& trimmed_query,
const ash::SearchResultIdWithPositionIndices& results,
int position_index) {
search_ranking_event_logger_.Log(trimmed_query, results, position_index);
}
ash::ShelfLaunchSource AppListClientImpl::AppListSourceToLaunchSource( ash::ShelfLaunchSource AppListClientImpl::AppListSourceToLaunchSource(
AppListSource source) { AppListSource source) {
switch (source) { switch (source) {
......
...@@ -7,8 +7,11 @@ ...@@ -7,8 +7,11 @@
#include <stdint.h> #include <stdint.h>
#include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include <vector>
#include "ash/public/cpp/app_list/app_list_client.h" #include "ash/public/cpp/app_list/app_list_client.h"
#include "ash/public/cpp/shelf_types.h" #include "ash/public/cpp/shelf_types.h"
...@@ -19,6 +22,7 @@ ...@@ -19,6 +22,7 @@
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "chrome/browser/ui/app_list/app_launch_event_logger.h" #include "chrome/browser/ui/app_list/app_launch_event_logger.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/search/logging/search_ranking_event_logger.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h" #include "components/search_engines/template_url_service_observer.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
...@@ -84,6 +88,10 @@ class AppListClientImpl ...@@ -84,6 +88,10 @@ class AppListClientImpl
override; override;
void OnSearchResultVisibilityChanged(const std::string& id, void OnSearchResultVisibilityChanged(const std::string& id,
bool visible) override; bool visible) override;
void NotifySearchResultsForLogging(
const base::string16& trimmed_query,
const ash::SearchResultIdWithPositionIndices& results,
int position_index) override;
// user_manager::UserManager::UserSessionStateObserver: // user_manager::UserManager::UserSessionStateObserver:
void ActiveUserChanged(const user_manager::User* active_user) override; void ActiveUserChanged(const user_manager::User* active_user) override;
...@@ -185,6 +193,7 @@ class AppListClientImpl ...@@ -185,6 +193,7 @@ class AppListClientImpl
bool app_list_visible_ = false; bool app_list_visible_ = false;
app_list::AppLaunchEventLogger app_launch_event_logger_; app_list::AppLaunchEventLogger app_launch_event_logger_;
app_list::SearchRankingEventLogger search_ranking_event_logger_;
base::WeakPtrFactory<AppListClientImpl> weak_ptr_factory_{this}; base::WeakPtrFactory<AppListClientImpl> weak_ptr_factory_{this};
......
// Copyright 2019 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.
#include <string>
#include <utility>
#include <vector>
#include "base/logging.h"
#include "chrome/browser/ui/app_list/search/logging/search_ranking_event_logger.h"
namespace app_list {
SearchRankingEventLogger::SearchRankingEventLogger() {}
SearchRankingEventLogger::~SearchRankingEventLogger() = default;
void SearchRankingEventLogger::Log(
const base::string16& trimmed_query,
const ash::SearchResultIdWithPositionIndices& search_results,
int position_index) {
if (trimmed_query.empty()) {
LogSuggestedZeroStateItems(search_results, position_index);
} else {
// TODO(crbug.com/972817): Add the logics for query-based events.
}
}
void SearchRankingEventLogger::LogSuggestedZeroStateItems(
const ash::SearchResultIdWithPositionIndices& search_results,
int position_index) {
// TODO(crbug.com/972817): Add the logics to log the suggested items.
}
} // namespace app_list
// Copyright 2019 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.
#ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_LOGGING_SEARCH_RANKING_EVENT_LOGGER_H_
#define CHROME_BROWSER_UI_APP_LIST_SEARCH_LOGGING_SEARCH_RANKING_EVENT_LOGGER_H_
#include <string>
#include <utility>
#include <vector>
#include "ash/public/cpp/app_list/app_list_types.h"
#include "base/logging.h"
#include "base/time/time.h"
namespace app_list {
class SearchRankingEventLogger {
public:
SearchRankingEventLogger();
~SearchRankingEventLogger();
// Called if a search result item got clicked, or a list of search result has
// been shown to the user after a certain amount of time. |raw_query| is the
// raw query that produced the results, |results| is a list of items that were
// being shown to the users and their corresponding position indices of them
// (see |SearchResultIdWithPositionIndex| for more details),
// |position_index| is the position index of the clicked item (if no item got
// clicked, |position_index| will be -1).
void Log(const base::string16& trimmed_query,
const ash::SearchResultIdWithPositionIndices& search_results,
int position_index);
private:
// Logs suggested items either from impressions or from click events.
void LogSuggestedZeroStateItems(
const ash::SearchResultIdWithPositionIndices& search_results,
int position_index);
};
} // namespace app_list
#endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_LOGGING_SEARCH_RANKING_EVENT_LOGGER_H_
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