Commit 71661450 authored by Jiaquan He's avatar Jiaquan He Committed by Commit Bot

app_list: break ChromeSearchResult-SearchResult inheritance.

This commit:
- breaks the inheritance relationship of ChromeSearchResult and SearchResult;
- removes all SearchModel class references from Chrome;
- removes ChromeSearchResult::Duplicate and uses SearchResultMetadata to
  publish results.

Bug: 733662
Change-Id: Iacf407818d74a69daa06c6649cfbf255b8921df4
Reviewed-on: https://chromium-review.googlesource.com/1038766Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Jiaquan He <hejq@google.com>
Cr-Commit-Position: refs/heads/master@{#556690}
parent 3edba584
...@@ -10,18 +10,6 @@ ...@@ -10,18 +10,6 @@
namespace app_list { namespace app_list {
namespace {
void UpdateResult(SearchResult* source, SearchResult* target) {
target->set_display_type(source->display_type());
target->set_title(source->title());
target->set_title_tags(source->title_tags());
target->set_details(source->details());
target->set_details_tags(source->details_tags());
}
} // namespace
SearchModel::SearchModel() SearchModel::SearchModel()
: search_box_(std::make_unique<SearchBoxModel>()), : search_box_(std::make_unique<SearchBoxModel>()),
results_(std::make_unique<SearchResults>()) {} results_(std::make_unique<SearchResults>()) {}
...@@ -77,9 +65,7 @@ void SearchModel::PublishResults( ...@@ -77,9 +65,7 @@ void SearchModel::PublishResults(
ui_result_it->second->answer_card_contents_token()) { ui_result_it->second->answer_card_contents_token()) {
// Update and use the old result if it exists. // Update and use the old result if it exists.
std::unique_ptr<SearchResult> ui_result = std::move(ui_result_it->second); std::unique_ptr<SearchResult> ui_result = std::move(ui_result_it->second);
UpdateResult(new_result.get(), ui_result.get()); ui_result->SetMetadata(new_result->CloneMetadata());
ui_result->set_display_score(new_result->display_score());
results_->Add(std::move(ui_result)); results_->Add(std::move(ui_result));
// Remove the item from the map so that it ends up only with unused // Remove the item from the map so that it ends up only with unused
......
...@@ -21,6 +21,12 @@ SearchResult::~SearchResult() { ...@@ -21,6 +21,12 @@ SearchResult::~SearchResult() {
observer.OnResultDestroying(); observer.OnResultDestroying();
} }
void SearchResult::SetMetadata(ash::mojom::SearchResultMetadataPtr metadata) {
metadata_ = std::move(metadata);
for (auto& observer : observers_)
observer.OnMetadataChanged();
}
void SearchResult::SetIcon(const gfx::ImageSkia& icon) { void SearchResult::SetIcon(const gfx::ImageSkia& icon) {
metadata_->icon = icon; metadata_->icon = icon;
for (auto& observer : observers_) for (auto& observer : observers_)
......
...@@ -123,8 +123,9 @@ class APP_LIST_MODEL_EXPORT SearchResult { ...@@ -123,8 +123,9 @@ class APP_LIST_MODEL_EXPORT SearchResult {
// Invokes a custom action on the result. It does nothing by default. // Invokes a custom action on the result. It does nothing by default.
virtual void InvokeAction(int action_index, int event_flags); virtual void InvokeAction(int action_index, int event_flags);
void SetMetadata(ash::mojom::SearchResultMetadataPtr metadata) { void SetMetadata(ash::mojom::SearchResultMetadataPtr metadata);
metadata_ = std::move(metadata); ash::mojom::SearchResultMetadataPtr CloneMetadata() const {
return metadata_.Clone();
} }
protected: protected:
......
...@@ -13,9 +13,6 @@ include_rules = [ ...@@ -13,9 +13,6 @@ include_rules = [
# For access to testing command line switches. # For access to testing command line switches.
"+ppapi/shared_impl", "+ppapi/shared_impl",
# TODO(hejq): Remove this once app_list is migrated. http://crbug.com/733662
"+ash/app_list/model",
] ]
specific_include_rules = { specific_include_rules = {
"bookmark_app_helper\.cc": [ "bookmark_app_helper\.cc": [
......
include_rules = [ include_rules = [
# TODO(hejq): Remove this once app_list is migrated. http://crbug.com/733662
"+ash/app_list/model",
# Code under //ash runs out-of-process in mash so it must be accessed via mojo # Code under //ash runs out-of-process in mash so it must be accessed via mojo
# interfaces in //ash/public/interfaces. See //ash/README.md. # interfaces in //ash/public/interfaces. See //ash/README.md.
# TODO(mash): Change this to "-ash". # TODO(mash): Change this to "-ash".
......
...@@ -80,7 +80,7 @@ IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest, ...@@ -80,7 +80,7 @@ IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest,
service->FlushForTesting(); service->FlushForTesting();
// Currently the search box is empty, so we have no result. // Currently the search box is empty, so we have no result.
EXPECT_FALSE(model_updater->GetResultByTitle(title)); EXPECT_FALSE(model_updater->GetResultByTitleForTest(title));
// Now a search finds the extension. // Now a search finds the extension.
model_updater->UpdateSearchBox(base::ASCIIToUTF16(title), model_updater->UpdateSearchBox(base::ASCIIToUTF16(title),
...@@ -88,7 +88,7 @@ IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest, ...@@ -88,7 +88,7 @@ IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest,
// Ensure everything is done, from Chrome to Ash and backwards. // Ensure everything is done, from Chrome to Ash and backwards.
service->FlushForTesting(); service->FlushForTesting();
EXPECT_TRUE(model_updater->GetResultByTitle(title)); EXPECT_TRUE(model_updater->GetResultByTitleForTest(title));
// Uninstall the extension. // Uninstall the extension.
UninstallExtension(extension->id()); UninstallExtension(extension->id());
...@@ -97,7 +97,7 @@ IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest, ...@@ -97,7 +97,7 @@ IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest,
service->FlushForTesting(); service->FlushForTesting();
// We cannot find the extension any more. // We cannot find the extension any more.
EXPECT_FALSE(model_updater->GetResultByTitle(title)); EXPECT_FALSE(model_updater->GetResultByTitleForTest(title));
service->DismissAppList(); service->DismissAppList();
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "ash/app_list/model/search/search_result.h"
#include "ash/public/interfaces/app_list.mojom.h" #include "ash/public/interfaces/app_list.mojom.h"
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
...@@ -65,7 +64,7 @@ class AppListModelUpdater { ...@@ -65,7 +64,7 @@ class AppListModelUpdater {
virtual void UpdateSearchBox(const base::string16& text, virtual void UpdateSearchBox(const base::string16& text,
bool initiated_by_user) {} bool initiated_by_user) {}
virtual void PublishSearchResults( virtual void PublishSearchResults(
std::vector<std::unique_ptr<ChromeSearchResult>> results) {} const std::vector<ChromeSearchResult*>& results) {}
// Item field setters only used by ChromeAppListItem and its derived classes. // Item field setters only used by ChromeAppListItem and its derived classes.
virtual void SetItemIcon(const std::string& id, const gfx::ImageSkia& icon) {} virtual void SetItemIcon(const std::string& id, const gfx::ImageSkia& icon) {}
...@@ -80,9 +79,21 @@ class AppListModelUpdater { ...@@ -80,9 +79,21 @@ class AppListModelUpdater {
virtual void SetItemIsInstalling(const std::string& id, bool is_installing) {} virtual void SetItemIsInstalling(const std::string& id, bool is_installing) {}
virtual void SetItemPercentDownloaded(const std::string& id, virtual void SetItemPercentDownloaded(const std::string& id,
int32_t percent_downloaded) {} int32_t percent_downloaded) {}
virtual void ActivateChromeItem(const std::string& id, int event_flags) {} virtual void ActivateChromeItem(const std::string& id, int event_flags) {}
virtual void SetSearchResultMetadata(
const std::string& id,
ash::mojom::SearchResultMetadataPtr metadata) {}
virtual void SetSearchResultIsInstalling(const std::string& id,
bool is_installing) {}
virtual void SetSearchResultPercentDownloaded(const std::string& id,
int percent_downloaded) {}
virtual void SetSearchResultIcon(const std::string& id,
const gfx::ImageSkia& icon) {}
virtual void SetSearchResultBadgeIcon(const std::string& id,
const gfx::ImageSkia& badge_icon) {}
virtual void NotifySearchResultItemInstalled(const std::string& id) {}
// For AppListModel: // For AppListModel:
virtual ChromeAppListItem* FindItem(const std::string& id) = 0; virtual ChromeAppListItem* FindItem(const std::string& id) = 0;
virtual size_t ItemCount() = 0; virtual size_t ItemCount() = 0;
...@@ -127,7 +138,8 @@ class AppListModelUpdater { ...@@ -127,7 +138,8 @@ class AppListModelUpdater {
virtual bool SearchEngineIsGoogle() = 0; virtual bool SearchEngineIsGoogle() = 0;
virtual ChromeSearchResult* FindSearchResult( virtual ChromeSearchResult* FindSearchResult(
const std::string& result_id) = 0; const std::string& result_id) = 0;
virtual ChromeSearchResult* GetResultByTitle(const std::string& title) = 0; virtual ChromeSearchResult* GetResultByTitleForTest(
const std::string& title) = 0;
// Methods for handle model updates in ash: // Methods for handle model updates in ash:
virtual void OnFolderCreated(ash::mojom::AppListItemMetadataPtr item) = 0; virtual void OnFolderCreated(ash::mojom::AppListItemMetadataPtr item) = 0;
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <utility> #include <utility>
#include "ash/app_list/app_list_controller_impl.h" #include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/model/search/search_model.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
...@@ -49,13 +48,6 @@ ash::mojom::AppListController* AppListServiceImpl::GetAppListController() { ...@@ -49,13 +48,6 @@ ash::mojom::AppListController* AppListServiceImpl::GetAppListController() {
return app_list_controller_; return app_list_controller_;
} }
app_list::SearchModel* AppListServiceImpl::GetSearchModelFromAsh() {
DCHECK(!ash_util::IsRunningInMash());
return ash::Shell::HasInstance()
? ash::Shell::Get()->app_list_controller()->search_model()
: nullptr;
}
AppListClientImpl* AppListServiceImpl::GetAppListClient() { AppListClientImpl* AppListServiceImpl::GetAppListClient() {
app_list_client_->UpdateProfile(); app_list_client_->UpdateProfile();
return app_list_client_; return app_list_client_;
......
...@@ -18,10 +18,6 @@ ...@@ -18,10 +18,6 @@
class AppListClientImpl; class AppListClientImpl;
class AppListControllerDelegateImpl; class AppListControllerDelegateImpl;
namespace app_list {
class SearchModel;
} // namespace app_list
namespace base { namespace base {
template <typename T> template <typename T>
struct DefaultSingletonTraits; struct DefaultSingletonTraits;
...@@ -63,10 +59,6 @@ class AppListServiceImpl : public AppListService { ...@@ -63,10 +59,6 @@ class AppListServiceImpl : public AppListService {
ash::mojom::AppListController* GetAppListController(); ash::mojom::AppListController* GetAppListController();
AppListClientImpl* GetAppListClient(); AppListClientImpl* GetAppListClient();
// TODO(hejq): Search model migration is not done yet. Chrome still accesses
// it directly in non-mus+ash mode.
app_list::SearchModel* GetSearchModelFromAsh();
private: private:
friend struct base::DefaultSingletonTraits<AppListServiceImpl>; friend struct base::DefaultSingletonTraits<AppListServiceImpl>;
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include "ash/app_list/model/search/search_model.h"
#include "ash/app_list/model/search/search_result.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/app_list/app_list_service_impl.h" #include "chrome/browser/ui/app_list/app_list_service_impl.h"
#include "chrome/browser/ui/app_list/chrome_app_list_item.h" #include "chrome/browser/ui/app_list/chrome_app_list_item.h"
...@@ -17,32 +15,8 @@ ...@@ -17,32 +15,8 @@
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "ui/base/models/menu_model.h" #include "ui/base/models/menu_model.h"
namespace {
// TODO(hejq): Get rid of these after refactoring ChromeSearchResult.
ChromeSearchResult* ConvertToChromeSearchResult(
app_list::SearchResult* result) {
return static_cast<ChromeSearchResult*>(result);
}
std::vector<std::unique_ptr<app_list::SearchResult>> ConvertToSearchResults(
std::vector<std::unique_ptr<ChromeSearchResult>> results) {
std::vector<std::unique_ptr<app_list::SearchResult>> ash_results;
for (auto& result : results) {
ash_results.push_back(
base::WrapUnique<app_list::SearchResult>(result.release()));
}
return ash_results;
}
} // namespace
ChromeAppListModelUpdater::ChromeAppListModelUpdater(Profile* profile) ChromeAppListModelUpdater::ChromeAppListModelUpdater(Profile* profile)
: profile_(profile), weak_ptr_factory_(this) { : profile_(profile), weak_ptr_factory_(this) {}
// TODO(hejq): remove this when search migration is done.
if (!ash_util::IsRunningInMash())
search_model_ = AppListServiceImpl::GetInstance()->GetSearchModelFromAsh();
}
ChromeAppListModelUpdater::~ChromeAppListModelUpdater() {} ChromeAppListModelUpdater::~ChromeAppListModelUpdater() {}
...@@ -154,18 +128,24 @@ void ChromeAppListModelUpdater::SetSearchHintText( ...@@ -154,18 +128,24 @@ void ChromeAppListModelUpdater::SetSearchHintText(
void ChromeAppListModelUpdater::UpdateSearchBox(const base::string16& text, void ChromeAppListModelUpdater::UpdateSearchBox(const base::string16& text,
bool initiated_by_user) { bool initiated_by_user) {
if (!ash_util::IsRunningInMash()) if (!app_list_controller_)
search_model_->search_box()->Update(text, initiated_by_user); return;
else if (app_list_controller_) app_list_controller_->UpdateSearchBox(text, initiated_by_user);
app_list_controller_->UpdateSearchBox(text, initiated_by_user);
} }
void ChromeAppListModelUpdater::PublishSearchResults( void ChromeAppListModelUpdater::PublishSearchResults(
std::vector<std::unique_ptr<ChromeSearchResult>> results) { const std::vector<ChromeSearchResult*>& results) {
for (auto& result : results) for (auto* const result : results)
result->set_model_updater(this); result->set_model_updater(this);
if (!ash_util::IsRunningInMash()) if (!app_list_controller_)
search_model_->PublishResults(ConvertToSearchResults(std::move(results))); return;
search_results_.clear();
std::vector<ash::mojom::SearchResultMetadataPtr> result_data;
for (auto* result : results) {
search_results_[result->id()] = result;
result_data.push_back(result->CloneMetadata());
}
app_list_controller_->PublishSearchResults(std::move(result_data));
} }
void ChromeAppListModelUpdater::ActivateChromeItem(const std::string& id, void ChromeAppListModelUpdater::ActivateChromeItem(const std::string& id,
...@@ -277,6 +257,41 @@ void ChromeAppListModelUpdater::SetItemPercentDownloaded( ...@@ -277,6 +257,41 @@ void ChromeAppListModelUpdater::SetItemPercentDownloaded(
app_list_controller_->SetItemPercentDownloaded(id, percent_downloaded); app_list_controller_->SetItemPercentDownloaded(id, percent_downloaded);
} }
////////////////////////////////////////////////////////////////////////////////
// Methods only used by ChromeSearchResult that talk to ash directly.
void ChromeAppListModelUpdater::SetSearchResultMetadata(
const std::string& id,
ash::mojom::SearchResultMetadataPtr metadata) {
if (!app_list_controller_)
return;
app_list_controller_->SetSearchResultMetadata(std::move(metadata));
}
void ChromeAppListModelUpdater::SetSearchResultIsInstalling(
const std::string& id,
bool is_installing) {
if (!app_list_controller_)
return;
app_list_controller_->SetSearchResultIsInstalling(id, is_installing);
}
void ChromeAppListModelUpdater::SetSearchResultPercentDownloaded(
const std::string& id,
int percent_downloaded) {
if (!app_list_controller_)
return;
app_list_controller_->SetSearchResultPercentDownloaded(id,
percent_downloaded);
}
void ChromeAppListModelUpdater::NotifySearchResultItemInstalled(
const std::string& id) {
if (!app_list_controller_)
return;
app_list_controller_->NotifySearchResultItemInstalled(id);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Methods for item querying // Methods for item querying
...@@ -315,9 +330,7 @@ bool ChromeAppListModelUpdater::FindItemIndexForTest(const std::string& id, ...@@ -315,9 +330,7 @@ bool ChromeAppListModelUpdater::FindItemIndexForTest(const std::string& id,
} }
bool ChromeAppListModelUpdater::SearchEngineIsGoogle() { bool ChromeAppListModelUpdater::SearchEngineIsGoogle() {
if (!ash_util::IsRunningInMash()) return search_engine_is_google_;
return search_model_->search_engine_is_google();
return false;
} }
void ChromeAppListModelUpdater::GetIdToAppListIndexMap( void ChromeAppListModelUpdater::GetIdToAppListIndexMap(
...@@ -368,6 +381,7 @@ void ChromeAppListModelUpdater::ContextMenuItemSelected(const std::string& id, ...@@ -368,6 +381,7 @@ void ChromeAppListModelUpdater::ContextMenuItemSelected(const std::string& id,
chrome_search_result->ContextMenuItemSelected(command_id, event_flags); chrome_search_result->ContextMenuItemSelected(command_id, event_flags);
} }
// TODO(hejq): move the following search-related methods into SearchController.
void ChromeAppListModelUpdater::GetSearchResultContextMenuModel( void ChromeAppListModelUpdater::GetSearchResultContextMenuModel(
const std::string& result_id, const std::string& result_id,
GetMenuModelCallback callback) { GetMenuModelCallback callback) {
...@@ -378,26 +392,21 @@ void ChromeAppListModelUpdater::GetSearchResultContextMenuModel( ...@@ -378,26 +392,21 @@ void ChromeAppListModelUpdater::GetSearchResultContextMenuModel(
ChromeSearchResult* ChromeAppListModelUpdater::FindSearchResult( ChromeSearchResult* ChromeAppListModelUpdater::FindSearchResult(
const std::string& result_id) { const std::string& result_id) {
return search_model_ ? ConvertToChromeSearchResult( if (search_results_.find(result_id) == search_results_.end())
search_model_->FindSearchResult(result_id)) return nullptr;
: nullptr; return search_results_[result_id];
} }
ChromeSearchResult* ChromeAppListModelUpdater::GetResultByTitle( ChromeSearchResult* ChromeAppListModelUpdater::GetResultByTitleForTest(
const std::string& title) { const std::string& title) {
if (!search_model_)
return nullptr;
base::string16 target_title = base::ASCIIToUTF16(title); base::string16 target_title = base::ASCIIToUTF16(title);
// TODO(hejq): Currently we use a search result's type and diaplay type to for (const auto& result_item : search_results_) {
// check whether it's a result of uninstalled result. We might ChromeSearchResult* result = result_item.second;
// have an attribute to do this when we refactor SearchResult.
for (const auto& result : *search_model_->results()) {
if (result->title() == target_title && if (result->title() == target_title &&
result->result_type() == ash::SearchResultType::kInstalledApp && result->result_type() == ash::SearchResultType::kInstalledApp &&
result->display_type() != result->display_type() !=
ash::SearchResultDisplayType::kRecommendation) { ash::SearchResultDisplayType::kRecommendation) {
return ConvertToChromeSearchResult(result.get()); return result;
} }
} }
return nullptr; return nullptr;
......
...@@ -13,10 +13,6 @@ ...@@ -13,10 +13,6 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h" #include "chrome/browser/ui/app_list/app_list_model_updater.h"
namespace app_list {
class SearchModel;
} // namespace app_list
class ChromeAppListItem; class ChromeAppListItem;
class ChromeAppListModelUpdater : public AppListModelUpdater { class ChromeAppListModelUpdater : public AppListModelUpdater {
...@@ -45,7 +41,7 @@ class ChromeAppListModelUpdater : public AppListModelUpdater { ...@@ -45,7 +41,7 @@ class ChromeAppListModelUpdater : public AppListModelUpdater {
void UpdateSearchBox(const base::string16& text, void UpdateSearchBox(const base::string16& text,
bool initiated_by_user) override; bool initiated_by_user) override;
void PublishSearchResults( void PublishSearchResults(
std::vector<std::unique_ptr<ChromeSearchResult>> results) override; const std::vector<ChromeSearchResult*>& results) override;
// Methods only used by ChromeAppListItem that talk to ash directly. // Methods only used by ChromeAppListItem that talk to ash directly.
void SetItemIcon(const std::string& id, const gfx::ImageSkia& icon) override; void SetItemIcon(const std::string& id, const gfx::ImageSkia& icon) override;
...@@ -61,6 +57,16 @@ class ChromeAppListModelUpdater : public AppListModelUpdater { ...@@ -61,6 +57,16 @@ class ChromeAppListModelUpdater : public AppListModelUpdater {
void SetItemPercentDownloaded(const std::string& id, void SetItemPercentDownloaded(const std::string& id,
int32_t percent_downloaded) override; int32_t percent_downloaded) override;
// Methods only used by ChromeSearchResult that talk to ash directly.
void SetSearchResultMetadata(
const std::string& id,
ash::mojom::SearchResultMetadataPtr metadata) override;
void SetSearchResultIsInstalling(const std::string& id,
bool is_installing) override;
void SetSearchResultPercentDownloaded(const std::string& id,
int percent_downloaded) override;
void NotifySearchResultItemInstalled(const std::string& id) override;
// Methods only for visiting Chrome items that never talk to ash. // Methods only for visiting Chrome items that never talk to ash.
void ActivateChromeItem(const std::string& id, int event_flags) override; void ActivateChromeItem(const std::string& id, int event_flags) override;
ChromeAppListItem* AddChromeItem(std::unique_ptr<ChromeAppListItem> app_item); ChromeAppListItem* AddChromeItem(std::unique_ptr<ChromeAppListItem> app_item);
...@@ -85,7 +91,8 @@ class ChromeAppListModelUpdater : public AppListModelUpdater { ...@@ -85,7 +91,8 @@ class ChromeAppListModelUpdater : public AppListModelUpdater {
void GetSearchResultContextMenuModel(const std::string& result_id, void GetSearchResultContextMenuModel(const std::string& result_id,
GetMenuModelCallback callback) override; GetMenuModelCallback callback) override;
ChromeSearchResult* FindSearchResult(const std::string& result_id) override; ChromeSearchResult* FindSearchResult(const std::string& result_id) override;
ChromeSearchResult* GetResultByTitle(const std::string& title) override; ChromeSearchResult* GetResultByTitleForTest(
const std::string& title) override;
// Methods for AppListSyncableService: // Methods for AppListSyncableService:
void AddItemToOemFolder( void AddItemToOemFolder(
...@@ -111,10 +118,12 @@ class ChromeAppListModelUpdater : public AppListModelUpdater { ...@@ -111,10 +118,12 @@ class ChromeAppListModelUpdater : public AppListModelUpdater {
void SetDelegate(AppListModelUpdaterDelegate* delegate) override; void SetDelegate(AppListModelUpdaterDelegate* delegate) override;
private: private:
app_list::SearchModel* search_model_ = nullptr;
// A map from a ChromeAppListItem's id to its unique pointer. This item set // A map from a ChromeAppListItem's id to its unique pointer. This item set
// matches the one in AppListModel. // matches the one in AppListModel.
std::map<std::string, std::unique_ptr<ChromeAppListItem>> items_; std::map<std::string, std::unique_ptr<ChromeAppListItem>> items_;
// A map from a ChromeSearchResult's id to its unique pointer. This item set
// matches the one in SearchModel.
std::map<std::string, ChromeSearchResult*> search_results_;
Profile* const profile_ = nullptr; Profile* const profile_ = nullptr;
AppListModelUpdaterDelegate* delegate_ = nullptr; AppListModelUpdaterDelegate* delegate_ = nullptr;
ash::mojom::AppListController* app_list_controller_ = nullptr; ash::mojom::AppListController* app_list_controller_ = nullptr;
......
...@@ -21,13 +21,13 @@ AnswerCardResult::AnswerCardResult(Profile* profile, ...@@ -21,13 +21,13 @@ AnswerCardResult::AnswerCardResult(Profile* profile,
list_controller_(list_controller), list_controller_(list_controller),
contents_(contents) { contents_(contents) {
DCHECK(!stripped_result_url.empty()); DCHECK(!stripped_result_url.empty());
set_display_type(ash::SearchResultDisplayType::kCard); SetDisplayType(ash::SearchResultDisplayType::kCard);
set_id(result_url); set_id(result_url);
set_comparable_id(stripped_result_url); set_comparable_id(stripped_result_url);
set_relevance(1); set_relevance(1);
set_answer_card_contents_token(contents ? contents->GetToken() SetAnswerCardContentsToken(contents ? contents->GetToken()
: base::UnguessableToken()); : base::UnguessableToken());
set_title(result_title); SetTitle(result_title);
if (contents) if (contents)
contents->RegisterResult(this); contents->RegisterResult(this);
...@@ -42,11 +42,6 @@ void AnswerCardResult::OnContentsDestroying() { ...@@ -42,11 +42,6 @@ void AnswerCardResult::OnContentsDestroying() {
contents_ = nullptr; contents_ = nullptr;
} }
std::unique_ptr<ChromeSearchResult> AnswerCardResult::Duplicate() const {
return std::make_unique<AnswerCardResult>(
profile_, list_controller_, id(), comparable_id(), title(), contents_);
}
void AnswerCardResult::Open(int event_flags) { void AnswerCardResult::Open(int event_flags) {
list_controller_->OpenURL(profile_, GURL(id()), ui::PAGE_TRANSITION_GENERATED, list_controller_->OpenURL(profile_, GURL(id()), ui::PAGE_TRANSITION_GENERATED,
ui::DispositionFromEventFlags(event_flags)); ui::DispositionFromEventFlags(event_flags));
......
...@@ -31,9 +31,6 @@ class AnswerCardResult : public ChromeSearchResult { ...@@ -31,9 +31,6 @@ class AnswerCardResult : public ChromeSearchResult {
void OnContentsDestroying(); void OnContentsDestroying();
// ChromeSearchResult overrides:
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
void Open(int event_flags) override; void Open(int event_flags) override;
private: private:
......
...@@ -92,14 +92,6 @@ TEST_F(AnswerCardResultTest, Basic) { ...@@ -92,14 +92,6 @@ TEST_F(AnswerCardResultTest, Basic) {
result->Open(ui::EF_NONE); result->Open(ui::EF_NONE);
EXPECT_EQ(kResultUrl, GetLastOpenedUrl().spec()); EXPECT_EQ(kResultUrl, GetLastOpenedUrl().spec());
std::unique_ptr<ChromeSearchResult> result1 = result->Duplicate();
EXPECT_EQ(kResultUrl, result1->id());
EXPECT_EQ(base::ASCIIToUTF16(kResultTitle), result1->title());
EXPECT_EQ(ash::SearchResultDisplayType::kCard, result1->display_type());
EXPECT_EQ(1, result1->relevance());
EXPECT_EQ(GetToken(), result1->answer_card_contents_token());
} }
TEST_F(AnswerCardResultTest, NullContents) { TEST_F(AnswerCardResultTest, NullContents) {
...@@ -108,7 +100,6 @@ TEST_F(AnswerCardResultTest, NullContents) { ...@@ -108,7 +100,6 @@ TEST_F(AnswerCardResultTest, NullContents) {
// Shouldn't crash with null contents. // Shouldn't crash with null contents.
std::unique_ptr<AnswerCardResult> result = CreateResult( std::unique_ptr<AnswerCardResult> result = CreateResult(
kResultUrl, kResultUrlStripped, base::ASCIIToUTF16(kResultTitle)); kResultUrl, kResultUrlStripped, base::ASCIIToUTF16(kResultTitle));
std::unique_ptr<ChromeSearchResult> result1 = result->Duplicate();
} }
TEST_F(AnswerCardResultTest, EarlyDeleteContents) { TEST_F(AnswerCardResultTest, EarlyDeleteContents) {
...@@ -117,8 +108,6 @@ TEST_F(AnswerCardResultTest, EarlyDeleteContents) { ...@@ -117,8 +108,6 @@ TEST_F(AnswerCardResultTest, EarlyDeleteContents) {
kResultUrl, kResultUrlStripped, base::ASCIIToUTF16(kResultTitle)); kResultUrl, kResultUrlStripped, base::ASCIIToUTF16(kResultTitle));
DeleteContents(); DeleteContents();
result->Duplicate();
} }
} // namespace test } // namespace test
......
...@@ -16,10 +16,10 @@ AppResult::AppResult(Profile* profile, ...@@ -16,10 +16,10 @@ AppResult::AppResult(Profile* profile,
: profile_(profile), : profile_(profile),
app_id_(app_id), app_id_(app_id),
controller_(controller) { controller_(controller) {
set_display_type(is_recommendation SetDisplayType(is_recommendation
? ash::SearchResultDisplayType::kRecommendation ? ash::SearchResultDisplayType::kRecommendation
: ash::SearchResultDisplayType::kTile); : ash::SearchResultDisplayType::kTile);
set_result_type(ash::SearchResultType::kInstalledApp); SetResultType(ash::SearchResultType::kInstalledApp);
} }
AppResult::~AppResult() { AppResult::~AppResult() {
......
...@@ -486,7 +486,7 @@ void AppSearchProvider::UpdateRecommendedResults( ...@@ -486,7 +486,7 @@ void AppSearchProvider::UpdateRecommendedResults(
std::unique_ptr<AppResult> result = std::unique_ptr<AppResult> result =
app->data_source()->CreateResult(app->id(), list_controller_, true); app->data_source()->CreateResult(app->id(), list_controller_, true);
result->set_title(app->name()); result->SetTitle(app->name());
// Use the app list order to tiebreak apps that have never been // Use the app list order to tiebreak apps that have never been
// launched. The apps that have been installed or launched recently // launched. The apps that have been installed or launched recently
......
...@@ -79,17 +79,15 @@ ArcAppDataSearchResult::ArcAppDataSearchResult( ...@@ -79,17 +79,15 @@ ArcAppDataSearchResult::ArcAppDataSearchResult(
Profile* profile, Profile* profile,
AppListControllerDelegate* list_controller) AppListControllerDelegate* list_controller)
: data_(std::move(data)), : data_(std::move(data)),
profile_(profile),
list_controller_(list_controller), list_controller_(list_controller),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
set_title(base::UTF8ToUTF16(data_->label)); SetTitle(base::UTF8ToUTF16(data_->label));
set_id(kAppDataSearchPrefix + launch_intent_uri()); set_id(kAppDataSearchPrefix + launch_intent_uri());
if (data_->type == arc::mojom::AppDataResultType::PERSON) { if (data_->type == arc::mojom::AppDataResultType::PERSON) {
set_display_type(ash::SearchResultDisplayType::kTile); SetDisplayType(ash::SearchResultDisplayType::kTile);
} else if (data_->type == arc::mojom::AppDataResultType::NOTE_DOCUMENT) { } else if (data_->type == arc::mojom::AppDataResultType::NOTE_DOCUMENT) {
set_details(base::UTF8ToUTF16(data_->text)); SetDetails(base::UTF8ToUTF16(data_->text));
set_display_type(ash::SearchResultDisplayType::kList); SetDisplayType(ash::SearchResultDisplayType::kList);
} }
// TODO(warx): set default images when icon_png_data() is not available. // TODO(warx): set default images when icon_png_data() is not available.
...@@ -107,14 +105,6 @@ ArcAppDataSearchResult::ArcAppDataSearchResult( ...@@ -107,14 +105,6 @@ ArcAppDataSearchResult::ArcAppDataSearchResult(
ArcAppDataSearchResult::~ArcAppDataSearchResult() = default; ArcAppDataSearchResult::~ArcAppDataSearchResult() = default;
std::unique_ptr<ChromeSearchResult> ArcAppDataSearchResult::Duplicate() const {
std::unique_ptr<ArcAppDataSearchResult> result =
std::make_unique<ArcAppDataSearchResult>(data_.Clone(), profile_,
list_controller_);
result->SetIcon(icon());
return result;
}
void ArcAppDataSearchResult::GetContextMenuModel( void ArcAppDataSearchResult::GetContextMenuModel(
GetMenuModelCallback callback) { GetMenuModelCallback callback) {
// TODO(warx): Enable Context Menu. // TODO(warx): Enable Context Menu.
......
...@@ -31,7 +31,6 @@ class ArcAppDataSearchResult : public ChromeSearchResult { ...@@ -31,7 +31,6 @@ class ArcAppDataSearchResult : public ChromeSearchResult {
~ArcAppDataSearchResult() override; ~ArcAppDataSearchResult() override;
// ChromeSearchResult: // ChromeSearchResult:
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
void GetContextMenuModel(GetMenuModelCallback callback) override; void GetContextMenuModel(GetMenuModelCallback callback) override;
void Open(int event_flags) override; void Open(int event_flags) override;
...@@ -49,8 +48,6 @@ class ArcAppDataSearchResult : public ChromeSearchResult { ...@@ -49,8 +48,6 @@ class ArcAppDataSearchResult : public ChromeSearchResult {
arc::mojom::AppDataResultPtr data_; arc::mojom::AppDataResultPtr data_;
std::unique_ptr<arc::IconDecodeRequest> icon_decode_request_; std::unique_ptr<arc::IconDecodeRequest> icon_decode_request_;
// |profile_| is owned by ProfileInfo.
Profile* const profile_;
// |list_controller_| is owned by AppListServiceAsh and lives until the // |list_controller_| is owned by AppListServiceAsh and lives until the
// service finishes. // service finishes.
AppListControllerDelegate* const list_controller_; AppListControllerDelegate* const list_controller_;
......
...@@ -63,17 +63,17 @@ ArcPlayStoreSearchResult::ArcPlayStoreSearchResult( ...@@ -63,17 +63,17 @@ ArcPlayStoreSearchResult::ArcPlayStoreSearchResult(
profile_(profile), profile_(profile),
list_controller_(list_controller), list_controller_(list_controller),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
set_title(base::UTF8ToUTF16(label().value())); SetTitle(base::UTF8ToUTF16(label().value()));
set_id(kPlayAppPrefix + set_id(kPlayAppPrefix +
crx_file::id_util::GenerateId(install_intent_uri().value())); crx_file::id_util::GenerateId(install_intent_uri().value()));
set_display_type(ash::SearchResultDisplayType::kTile); SetDisplayType(ash::SearchResultDisplayType::kTile);
SetBadgeIcon(gfx::CreateVectorIcon( SetBadgeIcon(gfx::CreateVectorIcon(
is_instant_app() ? kIcBadgeInstantIcon : kIcBadgePlayIcon, is_instant_app() ? kIcBadgeInstantIcon : kIcBadgePlayIcon,
kAppBadgeIconSize, kBadgeColor)); kAppBadgeIconSize, kBadgeColor));
SetFormattedPrice(base::UTF8ToUTF16(formatted_price().value())); SetFormattedPrice(base::UTF8ToUTF16(formatted_price().value()));
SetRating(review_score()); SetRating(review_score());
set_result_type(is_instant_app() ? ash::SearchResultType::kInstantApp SetResultType(is_instant_app() ? ash::SearchResultType::kInstantApp
: ash::SearchResultType::kPlayStoreApp); : ash::SearchResultType::kPlayStoreApp);
icon_decode_request_ = std::make_unique<arc::IconDecodeRequest>( icon_decode_request_ = std::make_unique<arc::IconDecodeRequest>(
base::BindOnce(&ArcPlayStoreSearchResult::SetIcon, base::BindOnce(&ArcPlayStoreSearchResult::SetIcon,
...@@ -84,15 +84,6 @@ ArcPlayStoreSearchResult::ArcPlayStoreSearchResult( ...@@ -84,15 +84,6 @@ ArcPlayStoreSearchResult::ArcPlayStoreSearchResult(
ArcPlayStoreSearchResult::~ArcPlayStoreSearchResult() = default; ArcPlayStoreSearchResult::~ArcPlayStoreSearchResult() = default;
std::unique_ptr<ChromeSearchResult> ArcPlayStoreSearchResult::Duplicate()
const {
std::unique_ptr<ArcPlayStoreSearchResult> result =
std::make_unique<ArcPlayStoreSearchResult>(data_.Clone(), profile_,
list_controller_);
result->SetIcon(icon());
return result;
}
void ArcPlayStoreSearchResult::Open(int event_flags) { void ArcPlayStoreSearchResult::Open(int event_flags) {
if (!LaunchIntent(install_intent_uri().value(), if (!LaunchIntent(install_intent_uri().value(),
list_controller_->GetAppListDisplayId())) { list_controller_->GetAppListDisplayId())) {
......
...@@ -34,7 +34,6 @@ class ArcPlayStoreSearchResult : public ChromeSearchResult, ...@@ -34,7 +34,6 @@ class ArcPlayStoreSearchResult : public ChromeSearchResult,
~ArcPlayStoreSearchResult() override; ~ArcPlayStoreSearchResult() override;
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
void GetContextMenuModel(GetMenuModelCallback callback) override; void GetContextMenuModel(GetMenuModelCallback callback) override;
void Open(int event_flags) override; void Open(int event_flags) override;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/ui/app_list/search/arc_app_result.h" #include "chrome/browser/ui/app_list/search/arc_app_result.h"
#include <utility>
#include "ash/public/cpp/app_list/app_list_constants.h" #include "ash/public/cpp/app_list/app_list_constants.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
...@@ -59,16 +61,6 @@ void ArcAppResult::Open(int event_flags) { ...@@ -59,16 +61,6 @@ void ArcAppResult::Open(int event_flags) {
controller()->DismissView(); controller()->DismissView();
} }
std::unique_ptr<ChromeSearchResult> ArcAppResult::Duplicate() const {
auto copy = std::make_unique<ArcAppResult>(
profile(), app_id(), controller(),
display_type() == ash::SearchResultDisplayType::kRecommendation);
copy->set_title(title());
copy->set_title_tags(title_tags());
copy->set_relevance(relevance());
return copy;
}
void ArcAppResult::GetContextMenuModel(GetMenuModelCallback callback) { void ArcAppResult::GetContextMenuModel(GetMenuModelCallback callback) {
context_menu_ = std::make_unique<ArcAppContextMenu>(this, profile(), app_id(), context_menu_ = std::make_unique<ArcAppContextMenu>(this, profile(), app_id(),
controller()); controller());
......
...@@ -30,7 +30,6 @@ class ArcAppResult : public AppResult, ...@@ -30,7 +30,6 @@ class ArcAppResult : public AppResult,
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
void Open(int event_flags) override; void Open(int event_flags) override;
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
void GetContextMenuModel(GetMenuModelCallback callback) override; void GetContextMenuModel(GetMenuModelCallback callback) override;
// AppContextMenuDelegate overrides: // AppContextMenuDelegate overrides:
......
...@@ -11,7 +11,133 @@ ...@@ -11,7 +11,133 @@
#include "base/containers/adapters.h" #include "base/containers/adapters.h"
#include "chrome/browser/ui/app_list/app_context_menu.h" #include "chrome/browser/ui/app_list/app_context_menu.h"
ChromeSearchResult::ChromeSearchResult() = default; ChromeSearchResult::ChromeSearchResult()
: metadata_(ash::mojom::SearchResultMetadata::New()) {}
ChromeSearchResult::~ChromeSearchResult() = default;
void ChromeSearchResult::SetActions(const Actions& actions) {
metadata_->actions = actions;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetDisplayScore(double display_score) {
metadata_->display_score = display_score;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetIsInstalling(bool is_installing) {
metadata_->is_installing = is_installing;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetTitle(const base::string16& title) {
metadata_->title = title;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetTitleTags(const Tags& tags) {
metadata_->title_tags = tags;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetDetails(const base::string16& details) {
metadata_->details = details;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetDetailsTags(const Tags& tags) {
metadata_->details_tags = tags;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetRating(float rating) {
metadata_->rating = rating;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetFormattedPrice(
const base::string16& formatted_price) {
metadata_->formatted_price = formatted_price;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetDisplayType(DisplayType display_type) {
metadata_->display_type = display_type;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetResultType(ResultType result_type) {
metadata_->result_type = result_type;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetIsOmniboxSearch(bool is_omnibox_search) {
metadata_->is_omnibox_search = is_omnibox_search;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetAnswerCardContentsToken(
const base::UnguessableToken& token) {
metadata_->answer_card_contents_token = token;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetPercentDownloaded(int percent_downloaded) {
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultPercentDownloaded(id(), percent_downloaded);
}
void ChromeSearchResult::SetIcon(const gfx::ImageSkia& icon) {
icon.EnsureRepsForSupportedScales();
metadata_->icon = icon;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::SetBadgeIcon(const gfx::ImageSkia& badge_icon) {
badge_icon.EnsureRepsForSupportedScales();
metadata_->badge_icon = badge_icon;
AppListModelUpdater* updater = model_updater();
if (updater)
updater->SetSearchResultMetadata(id(), CloneMetadata());
}
void ChromeSearchResult::NotifyItemInstalled() {
AppListModelUpdater* updater = model_updater();
if (updater)
updater->NotifySearchResultItemInstalled(id());
}
void ChromeSearchResult::InvokeAction(int action_index, int event_flags) {}
void ChromeSearchResult::UpdateFromMatch( void ChromeSearchResult::UpdateFromMatch(
const app_list::TokenizedString& title, const app_list::TokenizedString& title,
...@@ -23,8 +149,8 @@ void ChromeSearchResult::UpdateFromMatch( ...@@ -23,8 +149,8 @@ void ChromeSearchResult::UpdateFromMatch(
for (const auto& hit : hits) for (const auto& hit : hits)
tags.push_back(Tag(Tag::MATCH, hit.start(), hit.end())); tags.push_back(Tag(Tag::MATCH, hit.start(), hit.end()));
set_title(title.text()); SetTitle(title.text());
set_title_tags(tags); SetTitleTags(tags);
set_relevance(match.relevance()); set_relevance(match.relevance());
} }
......
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "ash/app_list/model/search/search_result.h" #include "ash/public/cpp/app_list/app_list_types.h"
#include "ash/public/interfaces/app_list.mojom.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/unguessable_token.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h" #include "chrome/browser/ui/app_list/app_list_model_updater.h"
namespace app_list { namespace app_list {
...@@ -22,15 +24,68 @@ class TokenizedStringMatch; ...@@ -22,15 +24,68 @@ class TokenizedStringMatch;
// ChromeSearchResult consists of an icon, title text and details text. Title // ChromeSearchResult consists of an icon, title text and details text. Title
// and details text can have tagged ranges that are displayed differently from // and details text can have tagged ranges that are displayed differently from
// default style. // default style.
class ChromeSearchResult : public app_list::SearchResult { class ChromeSearchResult {
public: public:
using ResultType = ash::SearchResultType;
using DisplayType = ash::SearchResultDisplayType;
using Tag = ash::SearchResultTag;
using Tags = ash::SearchResultTags;
using Action = ash::SearchResultAction;
using Actions = ash::SearchResultActions;
ChromeSearchResult(); ChromeSearchResult();
virtual ~ChromeSearchResult();
const base::string16& title() const { return metadata_->title; }
const Tags& title_tags() const { return metadata_->title_tags; }
const base::string16& details() const { return metadata_->details; }
const Tags& details_tags() const { return metadata_->details_tags; }
float rating() const { return metadata_->rating; }
const base::string16& formatted_price() const {
return metadata_->formatted_price;
}
const std::string& id() const { return metadata_->id; }
DisplayType display_type() const { return metadata_->display_type; }
ResultType result_type() const { return metadata_->result_type; }
const Actions& actions() const { return metadata_->actions; }
double display_score() const { return metadata_->display_score; }
bool is_installing() const { return metadata_->is_installing; }
const base::UnguessableToken& answer_card_contents_token() const {
return metadata_->answer_card_contents_token.value();
}
const gfx::ImageSkia& icon() const { return metadata_->icon; }
const gfx::ImageSkia& badge_icon() const { return metadata_->badge_icon; }
const std::string& comparable_id() const { return comparable_id_; } const std::string& comparable_id() const { return comparable_id_; }
// TODO(mukai): Remove this method and really simplify the ownership of // The following methods set Chrome side data here, and call model updater
// SearchResult. Ideally, SearchResult will be copyable. // interface to update Ash.
virtual std::unique_ptr<ChromeSearchResult> Duplicate() const = 0; void SetTitle(const base::string16& title);
void SetTitleTags(const Tags& tags);
void SetDetails(const base::string16& details);
void SetDetailsTags(const Tags& tags);
void SetRating(float rating);
void SetFormattedPrice(const base::string16& formatted_price);
void SetDisplayType(DisplayType display_type);
void SetResultType(ResultType result_type);
void SetDisplayScore(double display_score);
void SetActions(const Actions& actions);
void SetIsOmniboxSearch(bool is_omnibox_search);
void SetAnswerCardContentsToken(const base::UnguessableToken& token);
void SetIsInstalling(bool is_installing);
void SetIcon(const gfx::ImageSkia& icon);
void SetBadgeIcon(const gfx::ImageSkia& badge_icon);
// The following methods call model updater to update Ash.
void SetPercentDownloaded(int percent_downloaded);
void NotifyItemInstalled();
void SetMetadata(ash::mojom::SearchResultMetadataPtr metadata) {
metadata_ = std::move(metadata);
}
ash::mojom::SearchResultMetadataPtr CloneMetadata() const {
return metadata_.Clone();
}
void set_model_updater(AppListModelUpdater* model_updater) { void set_model_updater(AppListModelUpdater* model_updater) {
model_updater_ = model_updater; model_updater_ = model_updater;
...@@ -40,6 +95,12 @@ class ChromeSearchResult : public app_list::SearchResult { ...@@ -40,6 +95,12 @@ class ChromeSearchResult : public app_list::SearchResult {
double relevance() const { return relevance_; } double relevance() const { return relevance_; }
void set_relevance(double relevance) { relevance_ = relevance; } void set_relevance(double relevance) { relevance_ = relevance; }
// Invokes a custom action on the result. It does nothing by default.
virtual void InvokeAction(int action_index, int event_flags);
// Opens the result. Clients should use AppListViewDelegate::OpenSearchResult.
virtual void Open(int event_flags) = 0;
// Updates the result's relevance score, and sets its title and title tags, // Updates the result's relevance score, and sets its title and title tags,
// based on a string match result. // based on a string match result.
void UpdateFromMatch(const app_list::TokenizedString& title, void UpdateFromMatch(const app_list::TokenizedString& title,
...@@ -59,6 +120,8 @@ class ChromeSearchResult : public app_list::SearchResult { ...@@ -59,6 +120,8 @@ class ChromeSearchResult : public app_list::SearchResult {
const Tags& tags); const Tags& tags);
protected: protected:
// These id setters should be called in derived class constructors only.
void set_id(const std::string& id) { metadata_->id = id; }
void set_comparable_id(const std::string& comparable_id) { void set_comparable_id(const std::string& comparable_id) {
comparable_id_ = comparable_id; comparable_id_ = comparable_id;
} }
...@@ -78,6 +141,8 @@ class ChromeSearchResult : public app_list::SearchResult { ...@@ -78,6 +141,8 @@ class ChromeSearchResult : public app_list::SearchResult {
// sorted order, group multiplier and group boost. // sorted order, group multiplier and group boost.
double relevance_ = 0; double relevance_ = 0;
ash::mojom::SearchResultMetadataPtr metadata_;
AppListModelUpdater* model_updater_ = nullptr; AppListModelUpdater* model_updater_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(ChromeSearchResult); DISALLOW_COPY_AND_ASSIGN(ChromeSearchResult);
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/ui/app_list/search/crostini_app_result.h" #include "chrome/browser/ui/app_list/search/crostini_app_result.h"
#include <utility>
#include "ash/public/cpp/app_list/app_list_constants.h" #include "ash/public/cpp/app_list/app_list_constants.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h" #include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -30,16 +32,6 @@ void CrostiniAppResult::Open(int event_flags) { ...@@ -30,16 +32,6 @@ void CrostiniAppResult::Open(int event_flags) {
LaunchCrostiniApp(profile(), app_id()); LaunchCrostiniApp(profile(), app_id());
} }
std::unique_ptr<ChromeSearchResult> CrostiniAppResult::Duplicate() const {
auto copy = std::make_unique<CrostiniAppResult>(
profile(), app_id(), controller(),
display_type() == ash::SearchResultDisplayType::kRecommendation);
copy->set_title(title());
copy->set_title_tags(title_tags());
copy->set_relevance(relevance());
return copy;
}
void CrostiniAppResult::GetContextMenuModel(GetMenuModelCallback callback) { void CrostiniAppResult::GetContextMenuModel(GetMenuModelCallback callback) {
context_menu_ = std::make_unique<CrostiniAppContextMenu>(profile(), app_id(), context_menu_ = std::make_unique<CrostiniAppContextMenu>(profile(), app_id(),
controller()); controller());
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_APP_LIST_SEARCH_CROSTINI_APP_RESULT_H_ #define CHROME_BROWSER_UI_APP_LIST_SEARCH_CROSTINI_APP_RESULT_H_
#include <memory> #include <memory>
#include <string>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/app_icon_loader_delegate.h" #include "chrome/browser/ui/app_icon_loader_delegate.h"
...@@ -28,7 +29,6 @@ class CrostiniAppResult : public AppResult, public AppIconLoaderDelegate { ...@@ -28,7 +29,6 @@ class CrostiniAppResult : public AppResult, public AppIconLoaderDelegate {
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
void Open(int event_flags) override; void Open(int event_flags) override;
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
void GetContextMenuModel(GetMenuModelCallback callback) override; void GetContextMenuModel(GetMenuModelCallback callback) override;
void ExecuteLaunchCommand(int event_flags) override; void ExecuteLaunchCommand(int event_flags) override;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/ui/app_list/search/extension_app_result.h" #include "chrome/browser/ui/app_list/search/extension_app_result.h"
#include <utility>
#include "ash/public/cpp/app_list/app_list_constants.h" #include "ash/public/cpp/app_list/app_list_constants.h"
#include "ash/public/cpp/app_list/app_list_switches.h" #include "ash/public/cpp/app_list/app_list_switches.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
...@@ -78,17 +80,6 @@ void ExtensionAppResult::Open(int event_flags) { ...@@ -78,17 +80,6 @@ void ExtensionAppResult::Open(int event_flags) {
event_flags); event_flags);
} }
std::unique_ptr<ChromeSearchResult> ExtensionAppResult::Duplicate() const {
std::unique_ptr<ChromeSearchResult> copy =
std::make_unique<ExtensionAppResult>(
profile(), app_id(), controller(),
display_type() == ash::SearchResultDisplayType::kRecommendation);
copy->set_title(title());
copy->set_title_tags(title_tags());
copy->set_relevance(relevance());
return copy;
}
void ExtensionAppResult::GetContextMenuModel(GetMenuModelCallback callback) { void ExtensionAppResult::GetContextMenuModel(GetMenuModelCallback callback) {
if (!context_menu_) { if (!context_menu_) {
context_menu_ = std::make_unique<ExtensionAppContextMenu>( context_menu_ = std::make_unique<ExtensionAppContextMenu>(
......
...@@ -40,7 +40,6 @@ class ExtensionAppResult : public AppResult, ...@@ -40,7 +40,6 @@ class ExtensionAppResult : public AppResult,
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
void Open(int event_flags) override; void Open(int event_flags) override;
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
void GetContextMenuModel(GetMenuModelCallback callback) override; void GetContextMenuModel(GetMenuModelCallback callback) override;
private: private:
......
...@@ -24,7 +24,7 @@ InternalAppResult::InternalAppResult(Profile* profile, ...@@ -24,7 +24,7 @@ InternalAppResult::InternalAppResult(Profile* profile,
bool is_recommendation) bool is_recommendation)
: AppResult(profile, app_id, controller, is_recommendation) { : AppResult(profile, app_id, controller, is_recommendation) {
set_id(app_id); set_id(app_id);
set_result_type(ResultType::kInternalApp); SetResultType(ResultType::kInternalApp);
SetIcon( SetIcon(
GetIconForResourceId(GetIconResourceIdByAppId(app_id), kTileIconSize)); GetIconForResourceId(GetIconResourceIdByAppId(app_id), kTileIconSize));
} }
...@@ -43,16 +43,6 @@ void InternalAppResult::Open(int event_flags) { ...@@ -43,16 +43,6 @@ void InternalAppResult::Open(int event_flags) {
OpenInternalApp(id(), profile()); OpenInternalApp(id(), profile());
} }
std::unique_ptr<ChromeSearchResult> InternalAppResult::Duplicate() const {
auto copy = std::make_unique<InternalAppResult>(
profile(), app_id(), controller(),
display_type() == DisplayType::kRecommendation);
copy->set_title(title());
copy->set_title_tags(title_tags());
copy->set_relevance(relevance());
return copy;
}
void InternalAppResult::GetContextMenuModel(GetMenuModelCallback callback) { void InternalAppResult::GetContextMenuModel(GetMenuModelCallback callback) {
const auto* internal_app = app_list::FindInternalApp(id()); const auto* internal_app = app_list::FindInternalApp(id());
DCHECK(internal_app); DCHECK(internal_app);
......
...@@ -28,7 +28,6 @@ class InternalAppResult : public AppResult { ...@@ -28,7 +28,6 @@ class InternalAppResult : public AppResult {
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
void Open(int event_flags) override; void Open(int event_flags) override;
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
void GetContextMenuModel(GetMenuModelCallback callback) override; void GetContextMenuModel(GetMenuModelCallback callback) override;
// AppContextMenuDelegate overrides: // AppContextMenuDelegate overrides:
......
...@@ -52,13 +52,12 @@ LauncherSearchResult::~LauncherSearchResult() { ...@@ -52,13 +52,12 @@ LauncherSearchResult::~LauncherSearchResult() {
icon_image_loader_->RemoveObserver(this); icon_image_loader_->RemoveObserver(this);
} }
std::unique_ptr<ChromeSearchResult> LauncherSearchResult::Duplicate() const { std::unique_ptr<LauncherSearchResult> LauncherSearchResult::Duplicate() const {
LauncherSearchResult* duplicated_result = LauncherSearchResult* duplicated_result =
new LauncherSearchResult(item_id_, discrete_value_relevance_, profile_, new LauncherSearchResult(item_id_, discrete_value_relevance_, profile_,
extension_, icon_image_loader_); extension_, icon_image_loader_);
duplicated_result->set_title(title());
duplicated_result->set_title_tags(title_tags());
duplicated_result->set_model_updater(model_updater()); duplicated_result->set_model_updater(model_updater());
duplicated_result->SetMetadata(CloneMetadata());
return base::WrapUnique(duplicated_result); return base::WrapUnique(duplicated_result);
} }
...@@ -101,8 +100,8 @@ void LauncherSearchResult::Initialize() { ...@@ -101,8 +100,8 @@ void LauncherSearchResult::Initialize() {
set_relevance(static_cast<double>(discrete_value_relevance_) / set_relevance(static_cast<double>(discrete_value_relevance_) /
static_cast<double>( static_cast<double>(
chromeos::launcher_search_provider::kMaxSearchResultScore)); chromeos::launcher_search_provider::kMaxSearchResultScore));
set_details(base::UTF8ToUTF16(extension_->name())); SetDetails(base::UTF8ToUTF16(extension_->name()));
set_result_type(ResultType::kLauncher); SetResultType(ResultType::kLauncher);
icon_image_loader_->AddObserver(this); icon_image_loader_->AddObserver(this);
......
...@@ -30,7 +30,7 @@ class LauncherSearchResult : public ChromeSearchResult, ...@@ -30,7 +30,7 @@ class LauncherSearchResult : public ChromeSearchResult,
std::unique_ptr<chromeos::launcher_search_provider::ErrorReporter> std::unique_ptr<chromeos::launcher_search_provider::ErrorReporter>
error_reporter); error_reporter);
~LauncherSearchResult() override; ~LauncherSearchResult() override;
std::unique_ptr<ChromeSearchResult> Duplicate() const override; std::unique_ptr<LauncherSearchResult> Duplicate() const;
void Open(int event_flags) override; void Open(int event_flags) override;
void OnIconImageChanged(LauncherSearchIconImageLoader* image_loader) override; void OnIconImageChanged(LauncherSearchIconImageLoader* image_loader) override;
......
...@@ -136,14 +136,12 @@ void Mixer::MixAndPublish(const KnownResults& known_results, ...@@ -136,14 +136,12 @@ void Mixer::MixAndPublish(const KnownResults& known_results,
std::sort(results.begin() + original_size, results.end()); std::sort(results.begin() + original_size, results.end());
} }
std::vector<std::unique_ptr<ChromeSearchResult>> new_results; std::vector<ChromeSearchResult*> new_results;
for (const SortData& sort_data : results) { for (const SortData& sort_data : results) {
std::unique_ptr<ChromeSearchResult> new_result = sort_data.result->SetDisplayScore(sort_data.score);
sort_data.result->Duplicate(); new_results.push_back(sort_data.result);
new_result->set_relevance(sort_data.score);
new_results.push_back(std::move(new_result));
} }
model_updater_->PublishSearchResults(std::move(new_results)); model_updater_->PublishSearchResults(new_results);
} }
void Mixer::RemoveDuplicates(SortedResults* results) { void Mixer::RemoveDuplicates(SortedResults* results) {
......
...@@ -133,7 +133,7 @@ OmniboxResult::OmniboxResult(Profile* profile, ...@@ -133,7 +133,7 @@ OmniboxResult::OmniboxResult(Profile* profile,
} }
set_id(match_.destination_url.spec()); set_id(match_.destination_url.spec());
set_comparable_id(match_.stripped_destination_url.spec()); set_comparable_id(match_.stripped_destination_url.spec());
set_result_type(ash::SearchResultType::kOmnibox); SetResultType(ash::SearchResultType::kOmnibox);
// Derive relevance from omnibox relevance and normalize it to [0, 1]. // Derive relevance from omnibox relevance and normalize it to [0, 1].
// The magic number 1500 is the highest score of an omnibox result. // The magic number 1500 is the highest score of an omnibox result.
...@@ -141,7 +141,7 @@ OmniboxResult::OmniboxResult(Profile* profile, ...@@ -141,7 +141,7 @@ OmniboxResult::OmniboxResult(Profile* profile,
set_relevance(match_.relevance / 1500.0); set_relevance(match_.relevance / 1500.0);
if (AutocompleteMatch::IsSearchType(match_.type)) if (AutocompleteMatch::IsSearchType(match_.type))
set_is_omnibox_search(true); SetIsOmniboxSearch(true);
UpdateIcon(); UpdateIcon();
UpdateTitleAndDetails(); UpdateTitleAndDetails();
...@@ -155,11 +155,6 @@ void OmniboxResult::Open(int event_flags) { ...@@ -155,11 +155,6 @@ void OmniboxResult::Open(int event_flags) {
ui::DispositionFromEventFlags(event_flags)); ui::DispositionFromEventFlags(event_flags));
} }
std::unique_ptr<ChromeSearchResult> OmniboxResult::Duplicate() const {
return std::make_unique<OmniboxResult>(profile_, list_controller_,
autocomplete_controller_, match_);
}
void OmniboxResult::UpdateIcon() { void OmniboxResult::UpdateIcon() {
BookmarkModel* bookmark_model = BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForBrowserContext(profile_); BookmarkModelFactory::GetForBrowserContext(profile_);
...@@ -178,27 +173,27 @@ void OmniboxResult::UpdateTitleAndDetails() { ...@@ -178,27 +173,27 @@ void OmniboxResult::UpdateTitleAndDetails() {
const bool use_directly = !IsUrlResultWithDescription(); const bool use_directly = !IsUrlResultWithDescription();
ChromeSearchResult::Tags title_tags; ChromeSearchResult::Tags title_tags;
if (use_directly) { if (use_directly) {
set_title(match_.contents); SetTitle(match_.contents);
ACMatchClassificationsToTags(match_.contents, match_.contents_class, ACMatchClassificationsToTags(match_.contents, match_.contents_class,
&title_tags); &title_tags);
} else { } else {
set_title(match_.description); SetTitle(match_.description);
ACMatchClassificationsToTags(match_.description, match_.description_class, ACMatchClassificationsToTags(match_.description, match_.description_class,
&title_tags); &title_tags);
} }
set_title_tags(title_tags); SetTitleTags(title_tags);
ChromeSearchResult::Tags details_tags; ChromeSearchResult::Tags details_tags;
if (use_directly) { if (use_directly) {
set_details(match_.description); SetDetails(match_.description);
ACMatchClassificationsToTags(match_.description, match_.description_class, ACMatchClassificationsToTags(match_.description, match_.description_class,
&details_tags); &details_tags);
} else { } else {
set_details(match_.contents); SetDetails(match_.contents);
ACMatchClassificationsToTags(match_.contents, match_.contents_class, ACMatchClassificationsToTags(match_.contents, match_.contents_class,
&details_tags); &details_tags);
} }
set_details_tags(details_tags); SetDetailsTags(details_tags);
} }
bool OmniboxResult::IsUrlResultWithDescription() const { bool OmniboxResult::IsUrlResultWithDescription() const {
......
...@@ -28,8 +28,6 @@ class OmniboxResult : public ChromeSearchResult { ...@@ -28,8 +28,6 @@ class OmniboxResult : public ChromeSearchResult {
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
void Open(int event_flags) override; void Open(int event_flags) override;
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
private: private:
void UpdateIcon(); void UpdateIcon();
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "chrome/browser/ui/app_list/search/search_controller.h" #include "chrome/browser/ui/app_list/search/search_controller.h"
#include "chrome/browser/ui/app_list/search/settings_shortcut/settings_shortcut_provider.h" #include "chrome/browser/ui/app_list/search/settings_shortcut/settings_shortcut_provider.h"
#include "chrome/browser/ui/app_list/search/webstore/webstore_provider.h" #include "chrome/browser/ui/app_list/search/webstore/webstore_provider.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
...@@ -89,7 +90,7 @@ std::unique_ptr<SearchController> CreateSearchController( ...@@ -89,7 +90,7 @@ std::unique_ptr<SearchController> CreateSearchController(
webstore_group_id, webstore_group_id,
std::make_unique<WebstoreProvider>(profile, list_controller)); std::make_unique<WebstoreProvider>(profile, list_controller));
} }
if (features::IsAnswerCardEnabled()) { if (features::IsAnswerCardEnabled() && !ash_util::IsRunningInMash()) {
controller->AddProvider( controller->AddProvider(
answer_card_group_id, answer_card_group_id,
std::make_unique<AnswerCardSearchProvider>( std::make_unique<AnswerCardSearchProvider>(
......
...@@ -28,16 +28,16 @@ SearchWebstoreResult::SearchWebstoreResult( ...@@ -28,16 +28,16 @@ SearchWebstoreResult::SearchWebstoreResult(
launch_url_(extension_urls::GetWebstoreSearchPageUrl(query)) { launch_url_(extension_urls::GetWebstoreSearchPageUrl(query)) {
set_id(launch_url_.spec()); set_id(launch_url_.spec());
set_relevance(0.0); set_relevance(0.0);
set_result_type(ash::SearchResultType::kWebStoreApp); SetResultType(ash::SearchResultType::kWebStoreApp);
set_title(base::UTF8ToUTF16(query)); SetTitle(base::UTF8ToUTF16(query));
const base::string16 details = const base::string16 details =
l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE); l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE);
Tags details_tags; Tags details_tags;
details_tags.push_back(Tag(ash::SearchResultTag::DIM, 0, details.length())); details_tags.push_back(Tag(ash::SearchResultTag::DIM, 0, details.length()));
set_details(details); SetDetails(details);
set_details_tags(details_tags); SetDetailsTags(details_tags);
SetIcon(*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( SetIcon(*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_WEBSTORE_ICON_32)); IDR_WEBSTORE_ICON_32));
...@@ -58,8 +58,4 @@ void SearchWebstoreResult::Open(int event_flags) { ...@@ -58,8 +58,4 @@ void SearchWebstoreResult::Open(int event_flags) {
ui::DispositionFromEventFlags(event_flags)); ui::DispositionFromEventFlags(event_flags));
} }
std::unique_ptr<ChromeSearchResult> SearchWebstoreResult::Duplicate() const {
return std::make_unique<SearchWebstoreResult>(profile_, controller_, query_);
}
} // namespace app_list } // namespace app_list
...@@ -27,7 +27,6 @@ class SearchWebstoreResult : public ChromeSearchResult { ...@@ -27,7 +27,6 @@ class SearchWebstoreResult : public ChromeSearchResult {
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
void Open(int event_flags) override; void Open(int event_flags) override;
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
private: private:
Profile* profile_; Profile* profile_;
......
...@@ -30,10 +30,10 @@ SettingsShortcutResult::SettingsShortcutResult( ...@@ -30,10 +30,10 @@ SettingsShortcutResult::SettingsShortcutResult(
const SettingsShortcut& settings_shortcut) const SettingsShortcut& settings_shortcut)
: profile_(profile), settings_shortcut_(settings_shortcut) { : profile_(profile), settings_shortcut_(settings_shortcut) {
set_id(settings_shortcut.shortcut_id); set_id(settings_shortcut.shortcut_id);
set_title( SetTitle(
l10n_util::GetStringUTF16(settings_shortcut.name_string_resource_id)); l10n_util::GetStringUTF16(settings_shortcut.name_string_resource_id));
// TODO(wutao): create a new display type kSettingsShortcut. // TODO(wutao): create a new display type kSettingsShortcut.
set_display_type(DisplayType::kTile); SetDisplayType(DisplayType::kTile);
SetIcon(gfx::ImageSkiaOperations::CreateResizedImage( SetIcon(gfx::ImageSkiaOperations::CreateResizedImage(
gfx::CreateVectorIcon(settings_shortcut.vector_icon, kSettingsColor), gfx::CreateVectorIcon(settings_shortcut.vector_icon, kSettingsColor),
skia::ImageOperations::RESIZE_BEST, skia::ImageOperations::RESIZE_BEST,
...@@ -44,14 +44,6 @@ void SettingsShortcutResult::Open(int event_flags) { ...@@ -44,14 +44,6 @@ void SettingsShortcutResult::Open(int event_flags) {
chrome::ShowSettingsSubPageForProfile(profile_, settings_shortcut_.subpage); chrome::ShowSettingsSubPageForProfile(profile_, settings_shortcut_.subpage);
} }
std::unique_ptr<ChromeSearchResult> SettingsShortcutResult::Duplicate() const {
auto result =
std::make_unique<SettingsShortcutResult>(profile_, settings_shortcut_);
result->set_title_tags(title_tags());
result->set_relevance(relevance());
return result;
}
void SettingsShortcutResult::GetContextMenuModel( void SettingsShortcutResult::GetContextMenuModel(
GetMenuModelCallback callback) { GetMenuModelCallback callback) {
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
......
...@@ -26,7 +26,6 @@ class SettingsShortcutResult : public ChromeSearchResult { ...@@ -26,7 +26,6 @@ class SettingsShortcutResult : public ChromeSearchResult {
// SearchResult overrides: // SearchResult overrides:
void Open(int event_flags) override; void Open(int event_flags) override;
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
void GetContextMenuModel(GetMenuModelCallback callback) override; void GetContextMenuModel(GetMenuModelCallback callback) override;
private: private:
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "chrome/browser/ui/app_list/app_list_test_util.h" #include "chrome/browser/ui/app_list/app_list_test_util.h"
#include "chrome/browser/ui/app_list/search/chrome_search_result.h" #include "chrome/browser/ui/app_list/search/chrome_search_result.h"
#include "chrome/browser/ui/app_list/search/settings_shortcut/settings_shortcut_metadata.h" #include "chrome/browser/ui/app_list/search/settings_shortcut/settings_shortcut_metadata.h"
#include "chrome/browser/ui/app_list/search/settings_shortcut/settings_shortcut_result.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
namespace app_list { namespace app_list {
...@@ -38,11 +37,6 @@ TEST_F(SettingsShortcutResultTest, Basic) { ...@@ -38,11 +37,6 @@ TEST_F(SettingsShortcutResultTest, Basic) {
EXPECT_EQ(shortcut.shortcut_id, result->id()); EXPECT_EQ(shortcut.shortcut_id, result->id());
EXPECT_EQ(l10n_util::GetStringUTF16(shortcut.name_string_resource_id), EXPECT_EQ(l10n_util::GetStringUTF16(shortcut.name_string_resource_id),
result->title()); result->title());
auto result1 = result->Duplicate();
EXPECT_EQ(shortcut.shortcut_id, result1->id());
EXPECT_EQ(l10n_util::GetStringUTF16(shortcut.name_string_resource_id),
result1->title());
} }
} }
......
...@@ -36,7 +36,7 @@ class TestSearchResult : public ChromeSearchResult { ...@@ -36,7 +36,7 @@ class TestSearchResult : public ChromeSearchResult {
TestSearchResult(const std::string& id, double relevance) TestSearchResult(const std::string& id, double relevance)
: instance_id_(instantiation_count++) { : instance_id_(instantiation_count++) {
set_id(id); set_id(id);
set_title(base::UTF8ToUTF16(id)); SetTitle(base::UTF8ToUTF16(id));
set_relevance(relevance); set_relevance(relevance);
} }
~TestSearchResult() override {} ~TestSearchResult() override {}
...@@ -44,9 +44,6 @@ class TestSearchResult : public ChromeSearchResult { ...@@ -44,9 +44,6 @@ class TestSearchResult : public ChromeSearchResult {
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
void Open(int event_flags) override {} void Open(int event_flags) override {}
void InvokeAction(int action_index, int event_flags) override {} void InvokeAction(int action_index, int event_flags) override {}
std::unique_ptr<ChromeSearchResult> Duplicate() const override {
return std::make_unique<TestSearchResult>(id(), relevance());
}
// For reference equality testing. (Addresses cannot be used to test reference // For reference equality testing. (Addresses cannot be used to test reference
// equality because it is possible that an object will be allocated at the // equality because it is possible that an object will be allocated at the
...@@ -85,13 +82,13 @@ class TestSearchProvider : public SearchProvider { ...@@ -85,13 +82,13 @@ class TestSearchProvider : public SearchProvider {
if (bad_relevance_range_) if (bad_relevance_range_)
relevance = 10.0 - i * 10; relevance = 10.0 - i * 10;
TestSearchResult* result = new TestSearchResult(id, relevance); TestSearchResult* result = new TestSearchResult(id, relevance);
result->set_display_type(display_type_); result->SetDisplayType(display_type_);
Add(std::unique_ptr<ChromeSearchResult>(result)); Add(std::unique_ptr<ChromeSearchResult>(result));
} }
} }
void set_prefix(const std::string& prefix) { prefix_ = prefix; } void set_prefix(const std::string& prefix) { prefix_ = prefix; }
void set_display_type(ChromeSearchResult::DisplayType display_type) { void SetDisplayType(ChromeSearchResult::DisplayType display_type) {
display_type_ = display_type; display_type_ = display_type;
} }
void set_count(size_t count) { count_ = count; } void set_count(size_t count) { count_ = count; }
...@@ -250,7 +247,7 @@ TEST_F(MixerTest, RemoveDuplicates) { ...@@ -250,7 +247,7 @@ TEST_F(MixerTest, RemoveDuplicates) {
TEST_F(MixerTest, KnownResultsIgnoredForRecommendations) { TEST_F(MixerTest, KnownResultsIgnoredForRecommendations) {
// This gives omnibox 0 -- 5. // This gives omnibox 0 -- 5.
omnibox_provider()->set_count(6); omnibox_provider()->set_count(6);
omnibox_provider()->set_display_type( omnibox_provider()->SetDisplayType(
ash::SearchResultDisplayType::kRecommendation); ash::SearchResultDisplayType::kRecommendation);
// omnibox 1 -- 4 are "known results". // omnibox 1 -- 4 are "known results".
......
...@@ -52,7 +52,7 @@ WebstoreResult::WebstoreResult(Profile* profile, ...@@ -52,7 +52,7 @@ WebstoreResult::WebstoreResult(Profile* profile,
extension_registry_(NULL), extension_registry_(NULL),
weak_factory_(this) { weak_factory_(this) {
set_id(GetResultIdFromExtensionId(app_id)); set_id(GetResultIdFromExtensionId(app_id));
set_result_type(ash::SearchResultType::kWebStoreSearch); SetResultType(ash::SearchResultType::kWebStoreSearch);
SetDefaultDetails(); SetDefaultDetails();
InitAndStartObserving(); InitAndStartObserving();
...@@ -102,15 +102,6 @@ void WebstoreResult::InvokeAction(int action_index, int event_flags) { ...@@ -102,15 +102,6 @@ void WebstoreResult::InvokeAction(int action_index, int event_flags) {
StartInstall(); StartInstall();
} }
std::unique_ptr<ChromeSearchResult> WebstoreResult::Duplicate() const {
std::unique_ptr<ChromeSearchResult> copy(new WebstoreResult(
profile_, app_id_, icon_url_, is_paid_, item_type_, controller_));
copy->set_title(title());
copy->set_title_tags(title_tags());
copy->set_relevance(relevance());
return copy;
}
void WebstoreResult::InitAndStartObserving() { void WebstoreResult::InitAndStartObserving() {
DCHECK(!install_tracker_ && !extension_registry_); DCHECK(!install_tracker_ && !extension_registry_);
...@@ -152,8 +143,8 @@ void WebstoreResult::SetDefaultDetails() { ...@@ -152,8 +143,8 @@ void WebstoreResult::SetDefaultDetails() {
Tags details_tags; Tags details_tags;
details_tags.push_back(Tag(ash::SearchResultTag::DIM, 0, details.length())); details_tags.push_back(Tag(ash::SearchResultTag::DIM, 0, details.length()));
set_details(details); SetDetails(details);
set_details_tags(details_tags); SetDetailsTags(details_tags);
} }
void WebstoreResult::OnIconLoaded() { void WebstoreResult::OnIconLoaded() {
......
...@@ -50,7 +50,6 @@ class WebstoreResult : public ChromeSearchResult, ...@@ -50,7 +50,6 @@ class WebstoreResult : public ChromeSearchResult,
// ChromeSearchResult overrides: // ChromeSearchResult overrides:
void Open(int event_flags) override; void Open(int event_flags) override;
void InvokeAction(int action_index, int event_flags) override; void InvokeAction(int action_index, int event_flags) override;
std::unique_ptr<ChromeSearchResult> Duplicate() const override;
private: private:
// Set the initial state and start observing both InstallObserver and // Set the initial state and start observing both InstallObserver and
......
...@@ -133,21 +133,21 @@ void FakeAppListModelUpdater::GetSearchResultContextMenuModel( ...@@ -133,21 +133,21 @@ void FakeAppListModelUpdater::GetSearchResultContextMenuModel(
ChromeSearchResult* FakeAppListModelUpdater::FindSearchResult( ChromeSearchResult* FakeAppListModelUpdater::FindSearchResult(
const std::string& result_id) { const std::string& result_id) {
for (auto& result : search_results_) { for (auto*& result : search_results_) {
if (result->id() == result_id) if (result->id() == result_id)
return result.get(); return result;
} }
return nullptr; return nullptr;
} }
ChromeSearchResult* FakeAppListModelUpdater::GetResultByTitle( ChromeSearchResult* FakeAppListModelUpdater::GetResultByTitleForTest(
const std::string& title) { const std::string& title) {
return nullptr; return nullptr;
} }
void FakeAppListModelUpdater::PublishSearchResults( void FakeAppListModelUpdater::PublishSearchResults(
std::vector<std::unique_ptr<ChromeSearchResult>> results) { const std::vector<ChromeSearchResult*>& results) {
search_results_ = std::move(results); search_results_ = results;
} }
ash::mojom::AppListItemMetadataPtr ash::mojom::AppListItemMetadataPtr
......
...@@ -41,7 +41,7 @@ class FakeAppListModelUpdater : public AppListModelUpdater { ...@@ -41,7 +41,7 @@ class FakeAppListModelUpdater : public AppListModelUpdater {
// For SearchModel: // For SearchModel:
void SetSearchEngineIsGoogle(bool is_google) override; void SetSearchEngineIsGoogle(bool is_google) override;
void PublishSearchResults( void PublishSearchResults(
std::vector<std::unique_ptr<ChromeSearchResult>> results) override; const std::vector<ChromeSearchResult*>& results) override;
void ActivateChromeItem(const std::string& id, int event_flags) override; void ActivateChromeItem(const std::string& id, int event_flags) override;
...@@ -60,9 +60,9 @@ class FakeAppListModelUpdater : public AppListModelUpdater { ...@@ -60,9 +60,9 @@ class FakeAppListModelUpdater : public AppListModelUpdater {
void GetSearchResultContextMenuModel(const std::string& result_id, void GetSearchResultContextMenuModel(const std::string& result_id,
GetMenuModelCallback callback) override; GetMenuModelCallback callback) override;
ChromeSearchResult* FindSearchResult(const std::string& result_id) override; ChromeSearchResult* FindSearchResult(const std::string& result_id) override;
ChromeSearchResult* GetResultByTitle(const std::string& title) override; ChromeSearchResult* GetResultByTitleForTest(
const std::vector<std::unique_ptr<ChromeSearchResult>>& search_results() const std::string& title) override;
const { const std::vector<ChromeSearchResult*>& search_results() const {
return search_results_; return search_results_;
} }
...@@ -75,7 +75,7 @@ class FakeAppListModelUpdater : public AppListModelUpdater { ...@@ -75,7 +75,7 @@ class FakeAppListModelUpdater : public AppListModelUpdater {
private: private:
bool search_engine_is_google_ = false; bool search_engine_is_google_ = false;
std::vector<std::unique_ptr<ChromeAppListItem>> items_; std::vector<std::unique_ptr<ChromeAppListItem>> items_;
std::vector<std::unique_ptr<ChromeSearchResult>> search_results_; std::vector<ChromeSearchResult*> search_results_;
AppListModelUpdaterDelegate* delegate_ = nullptr; AppListModelUpdaterDelegate* delegate_ = nullptr;
ash::mojom::AppListItemMetadataPtr FindOrCreateOemFolder( ash::mojom::AppListItemMetadataPtr FindOrCreateOemFolder(
......
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