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

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

Issue 2790823004: Retry reinstallation of corrupted policy extensions. (Closed)
Patch Set: address comments 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 PolicyExtensionReinstaller::ReinstallCallback* g_reinstall_action_for_test =
19 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 ReinstallCallback* action) {
58 g_reinstall_action_for_test = action;
59 }
60
61 void PolicyExtensionReinstaller::NotifyExtensionDisabledDueToCorruption() {
62 ScheduleNextReinstallAttempt();
63 }
64
65 void PolicyExtensionReinstaller::Fire() {
66 scheduled_fire_pending_ = false;
67 ExtensionSystem* system = ExtensionSystem::Get(context_);
68 ExtensionService* service = system->extension_service();
69 PendingExtensionManager* pending_manager =
70 service->pending_extension_manager();
71 // If there's nothing to repair, then bail out.
72 if (!pending_manager->HasAnyPolicyReinstallForCorruption())
73 return;
74
75 service->CheckForExternalUpdates();
76 ScheduleNextReinstallAttempt();
77 }
78
79 base::TimeDelta PolicyExtensionReinstaller::GetNextFireDelay() {
80 backoff_entry_.InformOfRequest(false);
81 return backoff_entry_.GetTimeUntilRelease();
82 }
83
84 void PolicyExtensionReinstaller::ScheduleNextReinstallAttempt() {
85 if (scheduled_fire_pending_)
86 return;
87
88 scheduled_fire_pending_ = true;
89 base::TimeDelta reinstall_delay = GetNextFireDelay();
90 base::Closure callback =
91 base::Bind(&PolicyExtensionReinstaller::Fire, weak_factory_.GetWeakPtr());
92 if (g_reinstall_action_for_test) {
93 g_reinstall_action_for_test->Run(callback, reinstall_delay);
94 } else {
95 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, callback,
96 reinstall_delay);
97 }
98 }
99
100 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698