-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable ephemeral storage keep alive by default #8526
Conversation
@@ -85,6 +92,33 @@ void EphemeralStorageTabHelper::ReadyToCommitNavigation( | |||
CreateEphemeralStorageAreasForDomainAndURL(new_domain, new_url); | |||
} | |||
|
|||
void EphemeralStorageTabHelper::ClearEphemeralLifetimeKeepalive( | |||
const content::TLDEphemeralLifetimeKey& key) { | |||
ClearLocalStorageKeepAlive( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be simpler if TLDEphemeralLifetime owned local_storage_namespace_
, but I'd rather do that refactoring in a follow-up
@@ -33,7 +33,8 @@ namespace { | |||
constexpr char kSessionStorageSuffix[] = "/ephemeral-session-storage"; | |||
constexpr char kLocalStorageSuffix[] = "/ephemeral-local-storage"; | |||
|
|||
const base::TimeDelta kStorageKeepAliveDelay = base::TimeDelta::FromSeconds(30); | |||
const base::TimeDelta kStorageKeepAliveDelay = base::TimeDelta::FromSeconds( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this way kStorageKeepAliveDelay
cannot be controlled via Griffin or --enable-features
, because the value is set before FieldTrials initialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, right, I need to lazy initialize it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I don't really need this const at all
@@ -100,6 +105,10 @@ class EphemeralStorageBrowserTest : public InProcessBrowserTest { | |||
https_server_.GetURL("b.com", "/ephemeral_storage.html"); | |||
c_site_ephemeral_storage_url_ = | |||
https_server_.GetURL("c.com", "/ephemeral_storage.html"); | |||
|
|||
ephemeral_storage::EphemeralStorageTabHelper:: | |||
SetKeepAliveTimeDelayForTesting( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not ScopedFeatureList::InitAndEnableFeatureWithParameters
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that still ok to use when the feature is enabled by default? If so I'll remove SetKeepAliveTimeDelayForTesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it must be ok because it still has InitAndEnable for kBraveEphemeralStorage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually this seems to complicate running in both the enabled and disabled state so I'm going to leave it as-is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about creating ScopedEphemeralStorageKeepAliveTimeDelayForTesting
? it can be used as a member in test classes:
class Test : ... {
...
private:
// Maybe the delay can be set to 2, but can be overriden so both variants can work:
ScopedEphemeralStorageKeepAliveTimeDelayForTesting
scoped_ephemeral_storage_keep_alive_;
ScopedEphemeralStorageKeepAliveTimeDelayForTesting
scoped_ephemeral_storage_keep_alive_manual_{2};
};
Bonus: it can reset the value to the default state at test shutdown.
Also you can create a utility function for tests which will run a RunLoop
with PostDelayedTask
using the time delay set by the scoped object. The function can be a member of the scoped object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that would still require a method on EphemeralStorageTabHelper
to set the actual delay so not sure that's worth the extra effort since we always want the short delay in testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
going with this instead #8526 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to look at this in a follow-up so I can get this merged
// after keepalive values should be cleared | ||
ui_test_utils::NavigateToURL(browser(), b_site_ephemeral_storage_url_); | ||
ASSERT_TRUE(WaitForLoadStop(web_contents)); | ||
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(kKeepAliveInterval)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this way you hang the whole process. consider this instead:
base::RunLoop run_loop;
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromSeconds(kKeepAliveInterval));
run_loop.Run();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call, I was digging around trying to remember how to wait and saw other tests using base::PlatformThread::Sleep
so I thought I had misremembered that there was a better way :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why not ScopedMockTimeMessageLoopTaskRunner
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware of its existence, but looks like a good option because it doesn't require waiting at all and also eliminates a potential race condition if the tests are very slow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chromium_src
++
b5c2e09
to
5f7459e
Compare
@@ -273,8 +277,9 @@ class PermissionLifetimeManagerWithOriginMonitorBrowserTest | |||
: public PermissionLifetimeManagerBrowserTest { | |||
public: | |||
PermissionLifetimeManagerWithOriginMonitorBrowserTest() { | |||
scoped_feature_list_.InitAndEnableFeature( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scoped_feature_list_
in this class can be removed.
@@ -53,6 +53,8 @@ class CONTENT_EXPORT TLDEphemeralLifetime | |||
// Add a callback to a callback list to be called on destruction. | |||
void RegisterOnDestroyCallback(OnDestroyCallback callback); | |||
|
|||
const TLDEphemeralLifetimeKey& key() { return key_; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
@@ -100,6 +105,10 @@ class EphemeralStorageBrowserTest : public InProcessBrowserTest { | |||
https_server_.GetURL("b.com", "/ephemeral_storage.html"); | |||
c_site_ephemeral_storage_url_ = | |||
https_server_.GetURL("c.com", "/ephemeral_storage.html"); | |||
|
|||
ephemeral_storage::EphemeralStorageTabHelper:: | |||
SetKeepAliveTimeDelayForTesting( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about creating ScopedEphemeralStorageKeepAliveTimeDelayForTesting
? it can be used as a member in test classes:
class Test : ... {
...
private:
// Maybe the delay can be set to 2, but can be overriden so both variants can work:
ScopedEphemeralStorageKeepAliveTimeDelayForTesting
scoped_ephemeral_storage_keep_alive_;
ScopedEphemeralStorageKeepAliveTimeDelayForTesting
scoped_ephemeral_storage_keep_alive_manual_{2};
};
Bonus: it can reset the value to the default state at test shutdown.
Also you can create a utility function for tests which will run a RunLoop
with PostDelayedTask
using the time delay set by the scoped object. The function can be a member of the scoped object.
would be nice to have a problem description somewhere just for better understanding goals of the change |
|
||
// Navigate away and then navigate back to the original site. | ||
ui_test_utils::NavigateToURL(browser(), b_site_ephemeral_storage_url_); | ||
ASSERT_TRUE(WaitForLoadStop(web_contents)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need these, ui_test_utils::NavigateToURL
blocks until loading stops on its own
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, I added this because I was seeing strange behavior and then forgot to remove it
ClearLocalStorageKeepAlive( | ||
StringToSessionStorageId(key.second, kLocalStorageSuffix)); | ||
|
||
for (auto it = keep_alive_tld_ephemeral_lifetime_list_.begin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather do base::ranges::find()
and then erase: this is 2 times shorter and also safer, because the current loop looks as a common pitfall (without immediate return
). If return
is occasionally refactored/removed, we could be in trouble
@iefremov this issue has a fuller description of why the "keep alive" functionality is needed. brave/brave-browser#14943 |
… the tab is closed
test failures are unrelated known crashes for rewards |
|
||
void EphemeralStorageTabHelper::ClearLocalStorageKeepAlive( | ||
const std::string& id) { | ||
auto it = base::ranges::find_if( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory this is
base::ranges::find(method_data, id, &content::SessionStorageNamespace::id)
but not sure how well it works with scoped_refptr
s
enable ephemeral storage keep alive by default
Resolves brave/brave-browser#15415
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
,npm run lint
,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan: