| Index: extensions/browser/api/runtime/runtime_api.cc
|
| diff --git a/extensions/browser/api/runtime/runtime_api.cc b/extensions/browser/api/runtime/runtime_api.cc
|
| index 11b8f758f56a819e41c73c945e49fde2d5607cf1..0c6390bfcdfec92b5c44669487ca831a851fe417 100644
|
| --- a/extensions/browser/api/runtime/runtime_api.cc
|
| +++ b/extensions/browser/api/runtime/runtime_api.cc
|
| @@ -68,15 +68,6 @@ const char kUpdatesDisabledError[] = "Autoupdate is not enabled.";
|
| // A preference key storing the url loaded when an extension is uninstalled.
|
| const char kUninstallUrl[] = "uninstall_url";
|
|
|
| -// A preference key storing the information about an extension that was
|
| -// installed but not loaded. We keep the pending info here so that we can send
|
| -// chrome.runtime.onInstalled event during the extension load.
|
| -const char kPrefPendingOnInstalledEventDispatchInfo[] =
|
| - "pending_on_installed_event_dispatch_info";
|
| -
|
| -// Previously installed version number.
|
| -const char kPrefPreviousVersion[] = "previous_version";
|
| -
|
| // The name of the directory to be returned by getPackageDirectoryEntry. This
|
| // particular value does not matter to user code, but is chosen for consistency
|
| // with the equivalent Pepper API.
|
| @@ -218,6 +209,10 @@ RuntimeAPI::RuntimeAPI(content::BrowserContext* context)
|
| // per browser context, since it updates internal state when called.
|
| dispatch_chrome_updated_event_ =
|
| ExtensionsBrowserClient::Get()->DidVersionUpdate(browser_context_);
|
| +
|
| + ExtensionRegistry::Get(browser_context_)
|
| + ->lazy_event_dispatch_util()
|
| + ->AddObserver(this);
|
| }
|
|
|
| RuntimeAPI::~RuntimeAPI() {
|
| @@ -225,15 +220,6 @@ RuntimeAPI::~RuntimeAPI() {
|
|
|
| void RuntimeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
|
| const Extension* extension) {
|
| - base::Version previous_version;
|
| - if (ReadPendingOnInstallInfoFromPref(extension->id(), &previous_version)) {
|
| - base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent,
|
| - browser_context_, extension->id(), previous_version, false));
|
| - RemovePendingOnInstallInfoFromPref(extension->id());
|
| - }
|
| -
|
| if (!dispatch_chrome_updated_event_)
|
| return;
|
|
|
| @@ -244,30 +230,19 @@ void RuntimeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
|
| browser_context_, extension->id(), base::Version(), true));
|
| }
|
|
|
| -void RuntimeAPI::OnExtensionWillBeInstalled(
|
| - content::BrowserContext* browser_context,
|
| - const Extension* extension,
|
| - bool is_update,
|
| - const std::string& old_name) {
|
| - // This extension might be disabled before it has a chance to load, e.g. if
|
| - // the extension increased its permissions. So instead of trying to send the
|
| - // onInstalled event here, we remember the fact in prefs and fire the event
|
| - // when the extension is actually loaded.
|
| - StorePendingOnInstallInfoToPref(extension);
|
| -}
|
| -
|
| void RuntimeAPI::OnExtensionUninstalled(
|
| content::BrowserContext* browser_context,
|
| const Extension* extension,
|
| UninstallReason reason) {
|
| - RemovePendingOnInstallInfoFromPref(extension->id());
|
| -
|
| RuntimeEventRouter::OnExtensionUninstalled(
|
| browser_context_, extension->id(), reason);
|
| }
|
|
|
| void RuntimeAPI::Shutdown() {
|
| delegate_->RemoveUpdateObserver(this);
|
| + ExtensionRegistry::Get(browser_context_)
|
| + ->lazy_event_dispatch_util()
|
| + ->RemoveObserver(this);
|
| }
|
|
|
| void RuntimeAPI::OnAppUpdateAvailable(const Extension* extension) {
|
| @@ -283,53 +258,6 @@ void RuntimeAPI::OnBackgroundHostStartup(const Extension* extension) {
|
| RuntimeEventRouter::DispatchOnStartupEvent(browser_context_, extension->id());
|
| }
|
|
|
| -bool RuntimeAPI::ReadPendingOnInstallInfoFromPref(
|
| - const ExtensionId& extension_id,
|
| - base::Version* previous_version) {
|
| - ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_);
|
| - DCHECK(prefs);
|
| -
|
| - const base::DictionaryValue* info = nullptr;
|
| - if (!prefs->ReadPrefAsDictionary(
|
| - extension_id, kPrefPendingOnInstalledEventDispatchInfo, &info)) {
|
| - return false;
|
| - }
|
| -
|
| - std::string previous_version_string;
|
| - info->GetString(kPrefPreviousVersion, &previous_version_string);
|
| - // |previous_version_string| can be empty.
|
| - *previous_version = base::Version(previous_version_string);
|
| - return true;
|
| -}
|
| -
|
| -void RuntimeAPI::RemovePendingOnInstallInfoFromPref(
|
| - const ExtensionId& extension_id) {
|
| - ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_);
|
| - DCHECK(prefs);
|
| -
|
| - prefs->UpdateExtensionPref(extension_id,
|
| - kPrefPendingOnInstalledEventDispatchInfo, nullptr);
|
| -}
|
| -
|
| -void RuntimeAPI::StorePendingOnInstallInfoToPref(const Extension* extension) {
|
| - ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_);
|
| - DCHECK(prefs);
|
| -
|
| - // |pending_on_install_info| currently only contains a version string. Instead
|
| - // of making the pref hold a plain string, we store it as a dictionary value
|
| - // so that we can add more stuff to it in the future if necessary.
|
| - std::unique_ptr<base::DictionaryValue> pending_on_install_info(
|
| - new base::DictionaryValue());
|
| - base::Version previous_version = ExtensionRegistry::Get(browser_context_)
|
| - ->GetStoredVersion(extension->id());
|
| - pending_on_install_info->SetString(
|
| - kPrefPreviousVersion,
|
| - previous_version.IsValid() ? previous_version.GetString() : "");
|
| - prefs->UpdateExtensionPref(extension->id(),
|
| - kPrefPendingOnInstalledEventDispatchInfo,
|
| - std::move(pending_on_install_info));
|
| -}
|
| -
|
| void RuntimeAPI::ReloadExtension(const std::string& extension_id) {
|
| delegate_->ReloadExtension(extension_id);
|
| }
|
| @@ -634,6 +562,16 @@ void RuntimeEventRouter::OnExtensionUninstalled(
|
| RuntimeAPI::GetFactoryInstance()->Get(context)->OpenURL(uninstall_url);
|
| }
|
|
|
| +void RuntimeAPI::OnExtensionInstalledAndLoaded(
|
| + content::BrowserContext* browser_context,
|
| + const Extension* extension,
|
| + const base::Version& previous_version) {
|
| + base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent,
|
| + browser_context_, extension->id(), previous_version, false));
|
| +}
|
| +
|
| ExtensionFunction::ResponseAction RuntimeGetBackgroundPageFunction::Run() {
|
| ExtensionHost* host = ProcessManager::Get(browser_context())
|
| ->GetBackgroundHostForExtension(extension_id());
|
|
|