| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/update_install_delayer.h" |
| 6 |
| 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/extension_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "extensions/browser/event_router.h" |
| 11 #include "extensions/common/extension.h" |
| 12 #include "extensions/common/manifest_handlers/background_info.h" |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 UpdateInstallDelayer::UpdateInstallDelayer(ExtensionService* service) |
| 17 : service_(service) {} |
| 18 |
| 19 InstallDelayer::Action UpdateInstallDelayer::GetDelayedInstallAction( |
| 20 const Extension* extension, |
| 21 bool install_immediately) { |
| 22 if (install_immediately || !service_->is_ready()) |
| 23 return INSTALL; |
| 24 |
| 25 const Extension* old = service_->GetInstalledExtension(extension->id()); |
| 26 // If there is no old extension, this is not an update, so don't delay. |
| 27 if (!old) |
| 28 return INSTALL; |
| 29 |
| 30 if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) { |
| 31 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; |
| 32 // Delay installation if the extension listens for the onUpdateAvailable |
| 33 // event. |
| 34 return extensions::EventRouter::Get(service_->profile()) |
| 35 ->ExtensionHasEventListener(extension->id(), |
| 36 kOnUpdateAvailableEvent) |
| 37 ? DELAY |
| 38 : INSTALL; |
| 39 } else { |
| 40 // Delay installation if the extension is not idle. |
| 41 return !extensions::util::IsExtensionIdle(extension->id(), |
| 42 service_->profile()) |
| 43 ? DELAY |
| 44 : INSTALL; |
| 45 } |
| 46 } |
| 47 |
| 48 } // namespace extensions |
| OLD | NEW |