Commit eda00578 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove NotificationService usage from first_run.cc.

FirstRunDelayedExtensionUpdater used NOTIFICATION_PROFILE_CREATED to
tell the first created profile's ExtensionSystem to run an update as
soon as it was ready. Instead, set a (static) flag in ExtensionUpdater
to do the same for the first ExtensionUpdater that is brought up.

Bug: 268984
Change-Id: I82e113c45a5f77954c4674460e2b0582d78dfcfd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1798887Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Auto-Submit: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700489}
parent 18d8d9e0
...@@ -264,9 +264,12 @@ bool ChromeRuntimeAPIDelegate::CheckForUpdates( ...@@ -264,9 +264,12 @@ bool ChromeRuntimeAPIDelegate::CheckForUpdates(
true, kUpdateThrottled, ""))); true, kUpdateThrottled, "")));
} else { } else {
info.callbacks.push_back(callback); info.callbacks.push_back(callback);
updater->CheckExtensionSoon(
extension_id, base::Bind(&ChromeRuntimeAPIDelegate::UpdateCheckComplete, extensions::ExtensionUpdater::CheckParams params;
base::Unretained(this), extension_id)); params.ids = {extension_id};
params.callback = base::Bind(&ChromeRuntimeAPIDelegate::UpdateCheckComplete,
base::Unretained(this), extension_id);
updater->CheckNow(std::move(params));
} }
return true; return true;
} }
......
...@@ -52,6 +52,8 @@ typedef extensions::ExtensionDownloaderDelegate::PingResult PingResult; ...@@ -52,6 +52,8 @@ typedef extensions::ExtensionDownloaderDelegate::PingResult PingResult;
namespace { namespace {
bool g_should_immediately_update = false;
// For sanity checking on update frequency - enforced in release mode only. // For sanity checking on update frequency - enforced in release mode only.
#if defined(NDEBUG) #if defined(NDEBUG)
const int kMinUpdateFrequencySeconds = 30; const int kMinUpdateFrequencySeconds = 30;
...@@ -184,7 +186,10 @@ void ExtensionUpdater::Start() { ...@@ -184,7 +186,10 @@ void ExtensionUpdater::Start() {
alive_ = true; alive_ = true;
// Check soon, and set up the first delayed check. // Check soon, and set up the first delayed check.
if (!g_skip_scheduled_checks_for_tests) { if (!g_skip_scheduled_checks_for_tests) {
CheckSoon(); if (g_should_immediately_update)
CheckNow({});
else
CheckSoon();
ScheduleNextCheck(); ScheduleNextCheck();
} }
} }
...@@ -250,6 +255,11 @@ void ExtensionUpdater::SetExtensionDownloaderForTesting( ...@@ -250,6 +255,11 @@ void ExtensionUpdater::SetExtensionDownloaderForTesting(
downloader_.swap(downloader); downloader_.swap(downloader);
} }
// static
void ExtensionUpdater::UpdateImmediatelyForFirstRun() {
g_should_immediately_update = true;
}
void ExtensionUpdater::DoCheckSoon() { void ExtensionUpdater::DoCheckSoon() {
DCHECK(will_check_soon_); DCHECK(will_check_soon_);
CheckNow(CheckParams()); CheckNow(CheckParams());
...@@ -393,14 +403,6 @@ void ExtensionUpdater::CheckNow(CheckParams params) { ...@@ -393,14 +403,6 @@ void ExtensionUpdater::CheckNow(CheckParams params) {
} }
} }
void ExtensionUpdater::CheckExtensionSoon(const std::string& extension_id,
FinishedCallback callback) {
CheckParams params;
params.ids = {extension_id};
params.callback = std::move(callback);
CheckNow(std::move(params));
}
void ExtensionUpdater::OnExtensionDownloadStageChanged(const std::string& id, void ExtensionUpdater::OnExtensionDownloadStageChanged(const std::string& id,
Stage stage) { Stage stage) {
InstallationReporter::Get(profile_)->ReportDownloadingStage(id, stage); InstallationReporter::Get(profile_)->ReportDownloadingStage(id, stage);
......
...@@ -123,10 +123,6 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate, ...@@ -123,10 +123,6 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
// already a pending task that has not yet run. // already a pending task that has not yet run.
void CheckSoon(); void CheckSoon();
// Starts an update check for the specified extension soon.
void CheckExtensionSoon(const std::string& extension_id,
FinishedCallback callback);
// Starts an update check right now, instead of waiting for the next // Starts an update check right now, instead of waiting for the next
// regularly scheduled check or a pending check from CheckSoon(). // regularly scheduled check or a pending check from CheckSoon().
void CheckNow(CheckParams params); void CheckNow(CheckParams params);
...@@ -143,6 +139,10 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate, ...@@ -143,6 +139,10 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
void SetExtensionDownloaderForTesting( void SetExtensionDownloaderForTesting(
std::unique_ptr<ExtensionDownloader> downloader); std::unique_ptr<ExtensionDownloader> downloader);
// After this is called, the next ExtensionUpdater instance to be started will
// call CheckNow() instead of CheckSoon() for its initial update.
static void UpdateImmediatelyForFirstRun();
private: private:
friend class ExtensionUpdaterTest; friend class ExtensionUpdaterTest;
friend class ExtensionUpdaterFileHandler; friend class ExtensionUpdaterFileHandler;
......
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/updater/extension_updater.h" #include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/browser/first_run/first_run_internal.h" #include "chrome/browser/first_run/first_run_internal.h"
#include "chrome/browser/google/google_brand.h" #include "chrome/browser/google/google_brand.h"
...@@ -51,12 +49,7 @@ ...@@ -51,12 +49,7 @@
#include "chrome/installer/util/master_preferences_constants.h" #include "chrome/installer/util/master_preferences_constants.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_system.h"
#include "google_apis/gaia/gaia_auth_util.h" #include "google_apis/gaia/gaia_auth_util.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -122,47 +115,6 @@ class ImportEndedObserver : public importer::ImporterProgressObserver { ...@@ -122,47 +115,6 @@ class ImportEndedObserver : public importer::ImporterProgressObserver {
DISALLOW_COPY_AND_ASSIGN(ImportEndedObserver); DISALLOW_COPY_AND_ASSIGN(ImportEndedObserver);
}; };
// Helper class that makes sure extensions get updated as soon as the
// ExtensionService is ready.
class FirstRunDelayedExtensionUpdater : public content::NotificationObserver {
public:
static void Create() { new FirstRunDelayedExtensionUpdater(); }
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override {
DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CREATED, type);
content::BrowserContext* context = content::Source<Profile>(source).ptr();
extensions::ExtensionSystem::Get(context)->ready().Post(
FROM_HERE,
base::BindOnce(&FirstRunDelayedExtensionUpdater::OnExtensionSystemReady,
base::Unretained(this), context));
}
private:
FirstRunDelayedExtensionUpdater() {
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources());
}
~FirstRunDelayedExtensionUpdater() override = default;
void OnExtensionSystemReady(content::BrowserContext* context) {
// Process the notification and delete this.
extensions::ExtensionService* service =
extensions::ExtensionSystem::Get(context)->extension_service();
if (service) {
// Trigger an extension update check. If the extension specified in the
// master pref is older than the live extension it will get updated which
// is the same as get it installed.
service->updater()->CheckNow(extensions::ExtensionUpdater::CheckParams());
}
delete this;
}
content::NotificationRegistrar registrar_;
};
// Launches the import, via |importer_host|, from |source_profile| into // Launches the import, via |importer_host|, from |source_profile| into
// |target_profile| for the items specified in the |items_to_import| bitfield. // |target_profile| for the items specified in the |items_to_import| bitfield.
// This may be done in a separate process depending on the platform, but it will // This may be done in a separate process depending on the platform, but it will
...@@ -468,7 +420,7 @@ ProcessMasterPreferencesResult ProcessMasterPreferences( ...@@ -468,7 +420,7 @@ ProcessMasterPreferencesResult ProcessMasterPreferences(
base::DictionaryValue* extensions = 0; base::DictionaryValue* extensions = 0;
if (install_prefs->GetExtensionsBlock(&extensions)) { if (install_prefs->GetExtensionsBlock(&extensions)) {
DVLOG(1) << "Extensions block found in master preferences"; DVLOG(1) << "Extensions block found in master preferences";
FirstRunDelayedExtensionUpdater::Create(); extensions::ExtensionUpdater::UpdateImmediatelyForFirstRun();
} }
internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs);
......
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