Commit cf180193 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Introduce ConflictsDataFetcher

As part of moving the ModuleDatabase to its own sequence, the
chrome://conflicts page still needs to access its content from the UI
thread.

This is done by the ConflictsDataFetcher, which lives on the
ModuleDatabase task runner and returns the resulting data to the
conflicts handler.

Bug: 943303
Change-Id: I73c1413afaa1555abc2ba3c3bc891851b75ad71a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1531090
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarSébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644669}
parent 22be2544
......@@ -2215,6 +2215,8 @@ jumbo_split_static_library("ui") {
"views/try_chrome_dialog_win/try_chrome_dialog.h",
"views/uninstall_view.cc",
"views/uninstall_view.h",
"webui/conflicts/conflicts_data_fetcher.cc",
"webui/conflicts/conflicts_data_fetcher.h",
"webui/conflicts/conflicts_handler.cc",
"webui/conflicts/conflicts_handler.h",
"webui/conflicts/conflicts_ui.cc",
......
This diff is collapsed.
// 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_WEBUI_CONFLICTS_CONFLICTS_DATA_FETCHER_H_
#define CHROME_BROWSER_UI_WEBUI_CONFLICTS_CONFLICTS_DATA_FETCHER_H_
#include <memory>
#include "base/callback.h"
#include "base/optional.h"
#include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h"
#include "build/build_config.h"
#include "chrome/browser/conflicts/module_database_observer_win.h"
#if defined(GOOGLE_CHROME_BUILD)
#include "chrome/browser/conflicts/third_party_conflicts_manager_win.h"
#endif
namespace base {
class DictionaryValue;
class ListValue;
} // namespace base
// This class is responsible for gathering the list of modules for the
// chrome://conflicts page and the state of the third-party features on the
// ModuleDatabase task runner and sending it back to the UI thread. The instance
// should be deleted once the OnConflictsDataFetchedCallback is invoked.
class ConflictsDataFetcher : public ModuleDatabaseObserver {
public:
using UniquePtr =
std::unique_ptr<ConflictsDataFetcher, base::OnTaskRunnerDeleter>;
using OnConflictsDataFetchedCallback =
base::OnceCallback<void(base::DictionaryValue results)>;
~ConflictsDataFetcher() override;
// Creates the instance and initializes it on the ModuleDatabase task runner.
// |on_conflicts_data_fetched_callback| will be invoked on the caller's
// sequence.
static UniquePtr Create(
OnConflictsDataFetchedCallback on_conflicts_data_fetched_callback);
private:
explicit ConflictsDataFetcher(
OnConflictsDataFetchedCallback on_conflicts_data_fetched_callback);
void InitializeOnModuleDatabaseTaskRunner();
#if defined(GOOGLE_CHROME_BUILD)
// Invoked when the ThirdPartyConflictsManager initialization state is
// available.
void OnManagerInitializationComplete(ThirdPartyConflictsManager::State state);
#endif
// Registers this instance to the ModuleDatabase to retrieve the list of
// modules via the ModuleDatabaseObserver API.
void GetListOfModules();
// ModuleDatabaseObserver:
void OnNewModuleFound(const ModuleInfoKey& module_key,
const ModuleInfoData& module_data) override;
void OnModuleDatabaseIdle() override;
OnConflictsDataFetchedCallback on_conflicts_data_fetched_callback_;
// Temporarily holds the module list while the modules are being
// enumerated.
std::unique_ptr<base::ListValue> module_list_;
SEQUENCE_CHECKER(sequence_checker_);
#if defined(GOOGLE_CHROME_BUILD)
base::Optional<ThirdPartyConflictsManager::State>
third_party_conflicts_manager_state_;
base::WeakPtrFactory<ConflictsDataFetcher> weak_ptr_factory_;
#endif
DISALLOW_COPY_AND_ASSIGN(ConflictsDataFetcher);
};
#endif // CHROME_BROWSER_UI_WEBUI_CONFLICTS_CONFLICTS_DATA_FETCHER_H_
......@@ -5,94 +5,40 @@
#ifndef CHROME_BROWSER_UI_WEBUI_CONFLICTS_CONFLICTS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_CONFLICTS_CONFLICTS_HANDLER_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/conflicts/module_database_observer_win.h"
#include "chrome/browser/ui/webui/conflicts/conflicts_data_fetcher.h"
#include "content/public/browser/web_ui_message_handler.h"
#if defined(GOOGLE_CHROME_BUILD)
#include "chrome/browser/conflicts/third_party_conflicts_manager_win.h"
#endif
namespace base {
class DictionaryValue;
class Listvalue;
}
// This class takes care of sending the list of all loaded modules to the
// chrome://conflicts WebUI page when it is requested.
class ConflictsHandler : public content::WebUIMessageHandler,
public ModuleDatabaseObserver {
class ConflictsHandler : public content::WebUIMessageHandler {
public:
ConflictsHandler();
~ConflictsHandler() override;
private:
enum ThirdPartyFeaturesStatus {
// The third-party features are not available in non-Google Chrome builds.
kNonGoogleChromeBuild,
// The third-party features are temporarily disabled on domain-joined
// machines because of a known issue with third-party blocking and the
// IAttachmentExecute::Save() API (https://crbug.com/870998).
// TODO(pmonette): Move IAttachmentExecute::Save() to a utility process and
// remove this.
kEnterpriseManaged,
// The ThirdPartyBlockingEnabled group policy is disabled.
kPolicyDisabled,
// Both the IncompatibleApplicationsWarning and the
// ThirdPartyModulesBlocking features are disabled.
kFeatureDisabled,
// The Module List version received is invalid.
kModuleListInvalid,
// There is no Module List version available.
kNoModuleListAvailable,
// Only the IncompatibleApplicationsWarning feature is initialized.
kWarningInitialized,
// Only the ThirdPartyModulesBlocking feature is initialized.
kBlockingInitialized,
// Both the IncompatibleApplicationsWarning and the
// ThirdPartyModulesBlocking feature are initialized.
kWarningAndBlockingInitialized,
};
// content::WebUIMessageHandler:
void RegisterMessages() override;
// ModuleDatabaseObserver:
void OnNewModuleFound(const ModuleInfoKey& module_key,
const ModuleInfoData& module_data) override;
void OnModuleDatabaseIdle() override;
// Callback for the "requestModuleList" message.
void HandleRequestModuleList(const base::ListValue* args);
#if defined(GOOGLE_CHROME_BUILD)
// Invoked when the ThirdPartyConflictsManager initialization state is
// available.
void OnManagerInitializationComplete(ThirdPartyConflictsManager::State state);
#endif
// Registers this instance to the ModuleDatabase to retrieve the list of
// modules via the ModuleDatabaseObserver API.
void GetListOfModules();
// Returns true if one of the third-party features is enabled and active.
static bool IsThirdPartyFeatureEnabled(ThirdPartyFeaturesStatus status);
// Returns the status string of the third-party features.
static std::string GetThirdPartyFeaturesStatusString(
ThirdPartyFeaturesStatus status);
void OnConflictsDataFetched(base::DictionaryValue results);
// The ID of the callback that will get invoked with the module list.
std::string module_list_callback_id_;
// Temporarily holds the module list while the modules are being
// enumerated.
std::unique_ptr<base::ListValue> module_list_;
base::Optional<ThirdPartyFeaturesStatus> third_party_features_status_;
// Responsible for fetching the list of modules from the ModuleDatabase, which
// lives on a different sequence.
ConflictsDataFetcher::UniquePtr conflicts_data_fetcher_;
base::WeakPtrFactory<ConflictsHandler> weak_ptr_factory_;
......
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