Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/chrome_content_verifier_delegate.h" | 5 #include "chrome/browser/extensions/chrome_content_verifier_delegate.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/syslog_logging.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/syslog_logging.h" | |
| 19 #include "base/threading/thread_task_runner_handle.h" | |
| 18 #include "base/version.h" | 20 #include "base/version.h" |
| 19 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
| 24 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 25 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
| 26 #include "extensions/browser/management_policy.h" | 28 #include "extensions/browser/management_policy.h" |
| 27 #include "extensions/common/constants.h" | 29 #include "extensions/common/constants.h" |
| 28 #include "extensions/common/extension.h" | 30 #include "extensions/common/extension.h" |
| 29 #include "extensions/common/extension_urls.h" | 31 #include "extensions/common/extension_urls.h" |
| 30 #include "extensions/common/extensions_client.h" | 32 #include "extensions/common/extensions_client.h" |
| 31 #include "extensions/common/manifest.h" | 33 #include "extensions/common/manifest.h" |
| 32 #include "extensions/common/manifest_url_handlers.h" | 34 #include "extensions/common/manifest_url_handlers.h" |
| 35 #include "net/base/backoff_entry.h" | |
| 33 #include "net/base/escape.h" | 36 #include "net/base/escape.h" |
| 34 | 37 |
| 35 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
| 36 #include "chrome/browser/extensions/extension_assets_manager_chromeos.h" | 39 #include "chrome/browser/extensions/extension_assets_manager_chromeos.h" |
| 37 #endif | 40 #endif |
| 38 | 41 |
| 39 namespace { | 42 namespace { |
| 40 | 43 |
| 41 const char kContentVerificationExperimentName[] = | 44 const char kContentVerificationExperimentName[] = |
| 42 "ExtensionContentVerification"; | 45 "ExtensionContentVerification"; |
| 43 | 46 |
| 47 const net::BackoffEntry::Policy kPolicyReinstallBackoffPolicy = { | |
| 48 // num_errors_to_ignore | |
| 49 1, | |
| 50 | |
| 51 // initial_delay_ms (note that we set 'always_use_initial_delay' to false | |
| 52 // below) | |
| 53 100, | |
| 54 | |
| 55 // multiply_factor | |
| 56 2, | |
| 57 | |
| 58 // jitter_factor | |
| 59 0.1, | |
| 60 | |
| 61 // maximum_backoff_ms (30 minutes) | |
| 62 1000 * 60 * 30, | |
| 63 | |
| 64 // entry_lifetime_ms (6 hours) | |
| 65 1000 * 60 * 60 * 6, | |
| 66 | |
| 67 // always_use_initial_delay | |
| 68 false, | |
| 69 }; | |
| 70 | |
| 71 base::LazyInstance<base::Callback<void(base::TimeDelta delay)>> | |
|
Devlin
2016/11/29 22:31:24
Any need for this to a be a lazy instance rather t
asargent_no_longer_on_chrome
2016/11/30 00:11:48
I think I did it this way out of habit because we
| |
| 72 g_reinstall_action_for_test = LAZY_INSTANCE_INITIALIZER; | |
| 73 | |
| 44 } // namespace | 74 } // namespace |
| 45 | 75 |
| 46 namespace extensions { | 76 namespace extensions { |
| 47 | 77 |
| 48 // static | 78 // static |
| 49 ContentVerifierDelegate::Mode ChromeContentVerifierDelegate::GetDefaultMode() { | 79 ContentVerifierDelegate::Mode ChromeContentVerifierDelegate::GetDefaultMode() { |
| 50 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 80 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 51 | 81 |
| 52 Mode experiment_value; | 82 Mode experiment_value; |
| 53 #if defined(GOOGLE_CHROME_BUILD) | 83 #if defined(GOOGLE_CHROME_BUILD) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 if (system->management_policy()->MustRemainEnabled(extension, NULL)) { | 209 if (system->management_policy()->MustRemainEnabled(extension, NULL)) { |
| 180 PendingExtensionManager* pending_manager = | 210 PendingExtensionManager* pending_manager = |
| 181 service->pending_extension_manager(); | 211 service->pending_extension_manager(); |
| 182 if (pending_manager->IsPolicyReinstallForCorruptionExpected(extension_id)) | 212 if (pending_manager->IsPolicyReinstallForCorruptionExpected(extension_id)) |
| 183 return; | 213 return; |
| 184 SYSLOG(WARNING) << "Corruption detected in policy extension " | 214 SYSLOG(WARNING) << "Corruption detected in policy extension " |
| 185 << extension_id << " installed at: " | 215 << extension_id << " installed at: " |
| 186 << extension->path().value(); | 216 << extension->path().value(); |
| 187 pending_manager->ExpectPolicyReinstallForCorruption(extension_id); | 217 pending_manager->ExpectPolicyReinstallForCorruption(extension_id); |
| 188 service->DisableExtension(extension_id, Extension::DISABLE_CORRUPTED); | 218 service->DisableExtension(extension_id, Extension::DISABLE_CORRUPTED); |
| 189 service->CheckForExternalUpdates(); | 219 |
| 220 net::BackoffEntry* backoff_entry = nullptr; | |
| 221 auto iter = policy_reinstall_backoff_.find(extension_id); | |
| 222 if (iter != policy_reinstall_backoff_.end()) { | |
| 223 backoff_entry = iter->second.get(); | |
| 224 } else { | |
| 225 policy_reinstall_backoff_[extension_id] = | |
| 226 base::MakeUnique<net::BackoffEntry>(&kPolicyReinstallBackoffPolicy); | |
| 227 backoff_entry = policy_reinstall_backoff_[extension_id].get(); | |
|
Devlin
2016/11/29 22:31:24
nit: you could avoid a double look-up with either:
asargent_no_longer_on_chrome
2016/11/30 00:11:48
Done.
| |
| 228 } | |
| 229 backoff_entry->InformOfRequest(false); | |
| 230 | |
| 231 base::TimeDelta reinstall_delay = backoff_entry->GetTimeUntilRelease(); | |
| 232 if (!g_reinstall_action_for_test.Get().is_null()) { | |
| 233 g_reinstall_action_for_test.Get().Run(reinstall_delay); | |
| 234 } else { | |
| 235 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 236 FROM_HERE, base::Bind(&ExtensionService::CheckForExternalUpdates, | |
| 237 service->AsWeakPtr()), | |
| 238 reinstall_delay); | |
| 239 } | |
| 190 return; | 240 return; |
| 191 } | 241 } |
| 192 DLOG(WARNING) << "Disabling extension " << extension_id << " ('" | 242 DLOG(WARNING) << "Disabling extension " << extension_id << " ('" |
| 193 << extension->name() | 243 << extension->name() |
| 194 << "') due to content verification failure. In tests you " | 244 << "') due to content verification failure. In tests you " |
| 195 << "might want to use a ScopedIgnoreContentVerifierForTest " | 245 << "might want to use a ScopedIgnoreContentVerifierForTest " |
| 196 << "instance to prevent this."; | 246 << "instance to prevent this."; |
| 197 service->DisableExtension(extension_id, Extension::DISABLE_CORRUPTED); | 247 service->DisableExtension(extension_id, Extension::DISABLE_CORRUPTED); |
| 198 ExtensionPrefs::Get(context_)->IncrementCorruptedDisableCount(); | 248 ExtensionPrefs::Get(context_)->IncrementCorruptedDisableCount(); |
| 199 UMA_HISTOGRAM_BOOLEAN("Extensions.CorruptExtensionBecameDisabled", true); | 249 UMA_HISTOGRAM_BOOLEAN("Extensions.CorruptExtensionBecameDisabled", true); |
| 200 UMA_HISTOGRAM_ENUMERATION("Extensions.CorruptExtensionDisabledReason", | 250 UMA_HISTOGRAM_ENUMERATION("Extensions.CorruptExtensionDisabledReason", |
| 201 reason, ContentVerifyJob::FAILURE_REASON_MAX); | 251 reason, ContentVerifyJob::FAILURE_REASON_MAX); |
| 202 } else if (!base::ContainsKey(would_be_disabled_ids_, extension_id)) { | 252 } else if (!base::ContainsKey(would_be_disabled_ids_, extension_id)) { |
| 203 UMA_HISTOGRAM_BOOLEAN("Extensions.CorruptExtensionWouldBeDisabled", true); | 253 UMA_HISTOGRAM_BOOLEAN("Extensions.CorruptExtensionWouldBeDisabled", true); |
| 204 would_be_disabled_ids_.insert(extension_id); | 254 would_be_disabled_ids_.insert(extension_id); |
| 205 } | 255 } |
| 206 } | 256 } |
| 207 | 257 |
| 258 // static | |
| 259 void ChromeContentVerifierDelegate::set_policy_reinstall_action_for_test( | |
| 260 base::Callback<void(base::TimeDelta delay)> action) { | |
| 261 g_reinstall_action_for_test.Get() = action; | |
| 262 } | |
| 208 | 263 |
| 209 } // namespace extensions | 264 } // namespace extensions |
| OLD | NEW |