Commit 85214f0d authored by Eugene But's avatar Eugene But Committed by Chromium LUCI CQ

[ios] Fix kRemoveProtectionFromPrefFile check

Move kRemoveProtectionFromPrefFile check to a later stage when Finch is
actually initialized. Before this change kRemoveProtectionFromPrefFile
chekh would always return false.

Bug: None
Change-Id: I4cb5eeb5b96760572ffa34146b15b9361fb7cd60
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2568217
Auto-Submit: Eugene But <eugenebut@chromium.org>
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833836}
parent 0e1a036d
...@@ -83,25 +83,6 @@ ...@@ -83,25 +83,6 @@
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(
...@@ -502,23 +483,6 @@ void ApplicationContextImpl::CreateLocalState() { ...@@ -502,23 +483,6 @@ 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.
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.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_tick_clock.h" #include "base/time/default_tick_clock.h"
...@@ -78,6 +79,25 @@ ...@@ -78,6 +79,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);
}
#if BUILDFLAG(USE_ALLOCATOR_SHIM) #if BUILDFLAG(USE_ALLOCATOR_SHIM)
// Do not install allocator shim on iOS 13.4 due to high crash volume on this // Do not install allocator shim on iOS 13.4 due to high crash volume on this
// particular version of OS. TODO(crbug.com/1108219): Remove this workaround // particular version of OS. TODO(crbug.com/1108219): Remove this workaround
...@@ -193,6 +213,23 @@ void IOSChromeMainParts::PreCreateThreads() { ...@@ -193,6 +213,23 @@ void IOSChromeMainParts::PreCreateThreads() {
metrics::EnableExpiryChecker(::kExpiredHistogramsHashes, metrics::EnableExpiryChecker(::kExpiredHistogramsHashes,
::kNumExpiredHistograms); ::kNumExpiredHistograms);
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];
}
application_context_->PreCreateThreads(); application_context_->PreCreateThreads();
} }
......
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