Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/browser/extensions/update_install_gate.cc

Issue 1890163004: extensions: Abstract out install delay strategy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for comments in #4 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_gate.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 UpdateInstallGate::UpdateInstallGate(ExtensionService* service)
17 : service_(service) {}
18
19 InstallGate::Action UpdateInstallGate::ShouldDelay(const Extension* extension,
20 bool install_immediately) {
21 // Allow installation when |install_immediately| is set or ExtensionService
22 // is not ready. UpdateInstallGate blocks update when the old version of
23 // the extension is not idle (i.e. in use). When ExtensionService is not
24 // ready, the old version is definitely idle, so the installation is allowed
25 // to proceeded. This essentially allows the delayed installation to happen
26 // during the initialization of ExtensionService.
27 if (install_immediately || !service_->is_ready())
28 return INSTALL;
29
30 const Extension* old = service_->GetInstalledExtension(extension->id());
31 // If there is no old extension, this is not an update, so don't delay.
32 if (!old)
33 return INSTALL;
34
35 if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) {
36 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
37 // Delay installation if the extension listens for the onUpdateAvailable
38 // event.
39 return extensions::EventRouter::Get(service_->profile())
40 ->ExtensionHasEventListener(extension->id(),
41 kOnUpdateAvailableEvent)
42 ? DELAY
43 : INSTALL;
44 } else {
45 // Delay installation if the extension is not idle.
46 return !extensions::util::IsExtensionIdle(extension->id(),
47 service_->profile())
48 ? DELAY
49 : INSTALL;
50 }
51 }
52
53 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/update_install_gate.h ('k') | chrome/browser/extensions/update_install_gate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698