Commit fe8107bf authored by wutao's avatar wutao Committed by Commit Bot

app_list: Handle foreign tab update in AppSearchProvider

This patch handles the foreign tab update in AppSearchProvider, so that
the suggested results can be updated in home launcher.

Bug: 843839
Test: manual.
Change-Id: I4895cdaa475dcb4eaedebada90629eaff6743857
Reviewed-on: https://chromium-review.googlesource.com/1140522
Commit-Queue: Tao Wu <wutao@chromium.org>
Reviewed-by: default avatarJenny Zhang <jennyz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577656}
parent 8854e43a
......@@ -35,6 +35,7 @@
#include "chrome/browser/extensions/extension_ui_util.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
#include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
......@@ -45,6 +46,9 @@
#include "chrome/browser/ui/app_list/search/crostini_app_result.h"
#include "chrome/browser/ui/app_list/search/extension_app_result.h"
#include "chrome/browser/ui/app_list/search/internal_app_result.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/driver/sync_service_observer.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
......@@ -345,12 +349,23 @@ class ArcDataSource : public AppSearchProvider::DataSource,
DISALLOW_COPY_AND_ASSIGN(ArcDataSource);
};
class InternalDataSource : public AppSearchProvider::DataSource {
class InternalDataSource : public AppSearchProvider::DataSource,
syncer::SyncServiceObserver {
public:
InternalDataSource(Profile* profile, AppSearchProvider* owner)
: AppSearchProvider::DataSource(profile, owner) {}
: AppSearchProvider::DataSource(profile, owner) {
browser_sync::ProfileSyncService* service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
if (service)
service->AddObserver(this);
}
~InternalDataSource() override = default;
~InternalDataSource() override {
browser_sync::ProfileSyncService* service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
if (service)
service->RemoveObserver(this);
}
// AppSearchProvider::DataSource overrides:
void AddApps(AppSearchProvider::Apps* apps) override {
......@@ -382,6 +397,11 @@ class InternalDataSource : public AppSearchProvider::DataSource {
list_controller, is_recommended);
}
// syncer::SyncServiceObserver overrides:
void OnForeignSessionUpdated(syncer::SyncService* sync) override {
owner()->RefreshAppsAndUpdateResults(/*force_inline=*/false);
}
private:
DISALLOW_COPY_AND_ASSIGN(InternalDataSource);
};
......
......@@ -10,12 +10,10 @@
#include "ash/public/cpp/app_list/internal_app_id_constants.h"
#include "chrome/browser/favicon/large_icon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/app_list/app_context_menu.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/internal_app/internal_app_metadata.h"
#include "chrome/browser/ui/app_list/search/search_util.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/favicon/core/favicon_server_fetcher_params.h"
#include "components/favicon/core/large_icon_service.h"
#include "components/favicon_base/fallback_icon_style.h"
......@@ -38,21 +36,11 @@ InternalAppResult::InternalAppResult(Profile* profile,
if (id() == kInternalAppIdContinueReading) {
large_icon_service_ =
LargeIconServiceFactory::GetForBrowserContext(profile);
browser_sync::ProfileSyncService* service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
service->AddObserver(this);
service->TriggerRefresh(syncer::ModelTypeSet(syncer::SESSIONS));
UpdateContinueReadingFavicon(/*continue_to_google_server=*/true);
}
}
InternalAppResult::~InternalAppResult() {
if (id() == kInternalAppIdContinueReading) {
browser_sync::ProfileSyncService* service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
service->RemoveObserver(this);
}
}
InternalAppResult::~InternalAppResult() = default;
void InternalAppResult::ExecuteLaunchCommand(int event_flags) {
Open(event_flags);
......@@ -74,10 +62,6 @@ void InternalAppResult::Open(int event_flags) {
OpenInternalApp(id(), profile(), event_flags);
}
void InternalAppResult::OnForeignSessionUpdated(syncer::SyncService* sync) {
UpdateContinueReadingFavicon(/*continue_to_google_server=*/true);
}
void InternalAppResult::UpdateContinueReadingFavicon(
bool continue_to_google_server) {
base::string16 title;
......
......@@ -12,7 +12,6 @@
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/ui/app_list/search/app_result.h"
#include "components/favicon_base/favicon_types.h"
#include "components/sync/driver/sync_service_observer.h"
#include "url/gurl.h"
class AppListControllerDelegate;
......@@ -26,15 +25,11 @@ namespace favicon_base {
struct LargeIconImageResult;
} // namespace favicon_base
namespace syncer {
class SyncService;
} // namespace syncer
namespace app_list {
class AppContextMenu;
class InternalAppResult : public AppResult, syncer::SyncServiceObserver {
class InternalAppResult : public AppResult {
public:
InternalAppResult(Profile* profile,
const std::string& app_id,
......@@ -53,9 +48,6 @@ class InternalAppResult : public AppResult, syncer::SyncServiceObserver {
// ChromeSearchResult overrides:
AppContextMenu* GetAppContextMenu() override;
// syncer::SyncServiceObserver overrides:
void OnForeignSessionUpdated(syncer::SyncService* sync) override;
// Get large icon image from servers and update icon for continue reading.
// If there is no cache hit on LargeIconService and
// |continue_to_google_server| is true, will try to download the icon from
......
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