Commit 2fac7fe4 authored by Eugene But's avatar Eugene But Committed by Commit Bot

[ios] Allow removing file protection for local state file

According to Stability.iOS.UTE.MobileSessionAppState, a large number
of Unexplained Termination Events happen in background. There is an
assumption that "clean exit beacon" does not get written because
prefs file is protected. This CL allows removing protection in the
experiment. The experiment will be run on Canary and Dev to test
the assumption. There is no intention to roll this out to Beta or Stable.

If experiment will confirm the assumption, then clean exit beacon
file will be decoupled from prefs to remove the protection.

Bug: None
Change-Id: If816c4b3ed28ba5b2649e63526d5cfea93f839c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2506175Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824585}
parent 429dcbed
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "base/time/default_clock.h" #include "base/time/default_clock.h"
...@@ -83,6 +84,25 @@ ...@@ -83,6 +84,25 @@
namespace { namespace {
// If enabled local state file will have NSURLFileProtectionNone protection
// level set for NSURLFileProtectionKey key. The purpose of this feature is to
// understand if file protection interferes with "clean exit beacon" pref.
const base::Feature kRemoveProtectionFromPrefFile{
"RemoveProtectionFromPrefFile", base::FEATURE_DISABLED_BY_DEFAULT};
// Sets |level| value for NSURLFileProtectionKey key for the URL with given
// |local_state_path|.
void SetProtectionLevel(const base::FilePath& file_path, id level) {
NSString* file_path_string = base::SysUTF8ToNSString(file_path.value());
NSURL* file_path_url = [NSURL fileURLWithPath:file_path_string
isDirectory:NO];
NSError* error = nil;
BOOL protection_set = [file_path_url setResourceValue:level
forKey:NSURLFileProtectionKey
error:&error];
DCHECK(protection_set) << base::SysNSStringToUTF8(error.localizedDescription);
}
// Requests a network::mojom::ProxyResolvingSocketFactory on the UI thread. // Requests a network::mojom::ProxyResolvingSocketFactory on the UI thread.
// Note that this cannot be called on a thread that is not the UI thread. // Note that this cannot be called on a thread that is not the UI thread.
void RequestProxyResolvingSocketFactoryOnUIThread( void RequestProxyResolvingSocketFactoryOnUIThread(
...@@ -484,6 +504,24 @@ void ApplicationContextImpl::CreateLocalState() { ...@@ -484,6 +504,24 @@ void ApplicationContextImpl::CreateLocalState() {
base::FilePath local_state_path; base::FilePath local_state_path;
CHECK(base::PathService::Get(ios::FILE_LOCAL_STATE, &local_state_path)); CHECK(base::PathService::Get(ios::FILE_LOCAL_STATE, &local_state_path));
NSString* const kRemoveProtectionFromPrefFileKey =
@"RemoveProtectionFromPrefKey";
if (base::FeatureList::IsEnabled(kRemoveProtectionFromPrefFile)) {
SetProtectionLevel(local_state_path, NSURLFileProtectionNone);
[NSUserDefaults.standardUserDefaults
setBool:YES
forKey:kRemoveProtectionFromPrefFileKey];
} else if ([NSUserDefaults.standardUserDefaults
boolForKey:kRemoveProtectionFromPrefFileKey]) {
// Restore default protection level when user is no longer in the
// experimental group.
SetProtectionLevel(local_state_path,
NSFileProtectionCompleteUntilFirstUserAuthentication);
[NSUserDefaults.standardUserDefaults
removeObjectForKey:kRemoveProtectionFromPrefFileKey];
}
scoped_refptr<PrefRegistrySimple> pref_registry(new PrefRegistrySimple); scoped_refptr<PrefRegistrySimple> pref_registry(new PrefRegistrySimple);
// Register local state preferences. // Register local state preferences.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment