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

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

Issue 1890163004: extensions: Abstract out install delay strategy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win,mac compile 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_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())
asargent_no_longer_on_chrome 2016/04/16 00:20:22 It's unintuitive that we'd return INSTALL if servi
xiyuan 2016/04/18 20:44:30 Added a comment to explain. The update is blocked
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698