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

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

Issue 2790823004: Retry reinstallation of corrupted policy extensions. (Closed)
Patch Set: fix compile Created 3 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 2017 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/policy_extension_reinstaller.h"
6
7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/threading/thread_task_runner_handle.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "content/public/browser/browser_context.h"
12 #include "extensions/browser/extension_system.h"
13
14 namespace extensions {
15
16 namespace {
17
18 base::Callback<void(const base::Closure& callback, base::TimeDelta delay)>*
Devlin 2017/04/01 03:00:53 This might warrant a typedef :)
lazyboy 2017/04/03 18:13:04 Done.
19 g_reinstall_action_for_test = nullptr;
20
21 const net::BackoffEntry::Policy kPolicyReinstallBackoffPolicy = {
22 // num_errors_to_ignore
23 1,
24
25 // initial_delay_ms (note that we set 'always_use_initial_delay' to false
26 // below)
27 100,
28
29 // multiply_factor
30 2,
31
32 // jitter_factor
33 0.1,
34
35 // maximum_backoff_ms (30 minutes)
36 1000 * 60 * 30,
37
38 // entry_lifetime_ms (6 hours)
39 1000 * 60 * 60 * 6,
40
41 // always_use_initial_delay
42 false,
43 };
44
45 } // namespace
46
47 PolicyExtensionReinstaller::PolicyExtensionReinstaller(
48 content::BrowserContext* context)
49 : context_(context),
50 backoff_entry_(&kPolicyReinstallBackoffPolicy),
51 weak_factory_(this) {}
52
53 PolicyExtensionReinstaller::~PolicyExtensionReinstaller() {}
54
55 // static
56 void PolicyExtensionReinstaller::set_policy_reinstall_action_for_test(
57 base::Callback<void(const base::Closure& callback, base::TimeDelta delay)>*
58 action) {
59 g_reinstall_action_for_test = action;
60 }
61
62 void PolicyExtensionReinstaller::NotifyExtensionDisabledDueToCorruption() {
63 ScheduleNextReinstallAttempt();
64 }
65
66 void PolicyExtensionReinstaller::Fire() {
67 scheduled_fire_pending_ = false;
68 ExtensionSystem* system = ExtensionSystem::Get(context_);
69 ExtensionService* service = system->extension_service();
70 PendingExtensionManager* pending_manager =
71 service->pending_extension_manager();
72 // If there's nothing to repair, then bail out.
73 if (!pending_manager->HasAnyPolicyReinstallForCorruption())
74 return;
75
76 service->CheckForExternalUpdates();
77 ScheduleNextReinstallAttempt();
78 }
79
80 base::TimeDelta PolicyExtensionReinstaller::GetNextFireDelay() {
81 backoff_entry_.InformOfRequest(false);
82 return backoff_entry_.GetTimeUntilRelease();
83 }
84
85 void PolicyExtensionReinstaller::ScheduleNextReinstallAttempt() {
86 if (scheduled_fire_pending_)
87 return;
88
89 scheduled_fire_pending_ = true;
90 base::TimeDelta reinstall_delay = GetNextFireDelay();
91 base::Closure callback =
92 base::Bind(&PolicyExtensionReinstaller::Fire, weak_factory_.GetWeakPtr());
93 if (g_reinstall_action_for_test) {
94 g_reinstall_action_for_test->Run(callback, reinstall_delay);
95 } else {
96 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, callback,
97 reinstall_delay);
98 }
99 }
100
101 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698