Commit 344c3311 authored by Alex Moshchuk's avatar Alex Moshchuk Committed by Commit Bot

Remove ChildProcessSecurityPolicyImpl::HasSecurityState().

All uses of this function have already been converted to use
ChildProcessSecurityPolicyImpl::Handle instead.

Bug: 943887
Change-Id: I8daa6b35f978c9b31fe751c7d1f6b7f82fa10e70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2047512Reviewed-by: default avatarŁukasz Anforowicz <lukasza@chromium.org>
Commit-Queue: Alex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740513}
parent 683e3d2b
......@@ -748,7 +748,6 @@ TEST_F(AppCacheHostTest, SelectCacheAfterProcessCleanup) {
EXPECT_TRUE(
security_policy->CanAccessDataForOrigin(kProcessIdForTest, kDocumentURL));
EXPECT_TRUE(security_policy->HasSecurityState(kProcessIdForTest));
// Destroy the WebContents so the process gets cleaned up.
web_contents_.reset();
......@@ -801,7 +800,6 @@ TEST_F(AppCacheHostTest, ForeignEntryAfterProcessCleanup) {
EXPECT_TRUE(
security_policy->CanAccessDataForOrigin(kProcessIdForTest, kDocumentURL));
EXPECT_TRUE(security_policy->HasSecurityState(kProcessIdForTest));
// Destroy the WebContents so the process gets cleaned up.
web_contents_.reset();
......
......@@ -2001,11 +2001,6 @@ void ChildProcessSecurityPolicyImpl::RemoveIsolatedOriginForTesting(
isolated_origins_.erase(key);
}
bool ChildProcessSecurityPolicyImpl::HasSecurityState(int child_id) {
base::AutoLock lock(lock_);
return GetSecurityState(child_id) != nullptr;
}
ChildProcessSecurityPolicyImpl::SecurityState*
ChildProcessSecurityPolicyImpl::GetSecurityState(int child_id) {
auto itr = security_state_.find(child_id);
......
......@@ -419,16 +419,6 @@ class CONTENT_EXPORT ChildProcessSecurityPolicyImpl
// renderer-initiated navigations.
bool CanRedirectToURL(const GURL& url);
// Returns true if the policy object has security state information for
// |child_id|. This is essentially a way to determine if the policy object
// is actively tracking permissions for |child_id|. This method can be called
// from the UI & IO threads.
//
// DO NOT ADD NEW CALLERS OF THIS METHOD.
// TODO(933089): Remove this method once a better long term solution is
// implemented for the one caller doing Blob URL revocation.
bool HasSecurityState(int child_id);
// Sets "killed_process_origin_lock" crash key with lock info for the
// process associated with |child_id|.
void LogKilledProcessOriginLock(int child_id);
......
......@@ -2254,121 +2254,6 @@ TEST_F(ChildProcessSecurityPolicyTest,
testing::IsEmpty());
}
// Tests behavior of HasSecurityState() during race conditions that
// can occur during Remove(). It verifies that SecurityState for a child ID is
// preserved after a Remove() call until the task, that Remove() has posted to
// the IO thread, has run.
//
// We use a combination of waitable events and extra tasks posted to the
// threads to capture permission state from the UI & IO threads during the
// removal process. It is intended to simulate pending tasks that could be
// run on each thread during removal.
TEST_F(ChildProcessSecurityPolicyTest, HasSecurityState) {
ChildProcessSecurityPolicyImpl* p =
ChildProcessSecurityPolicyImpl::GetInstance();
GURL url("file:///etc/passwd");
EXPECT_FALSE(p->HasSecurityState(kRendererID));
p->Add(kRendererID, browser_context());
base::WaitableEvent ready_for_remove_event;
base::WaitableEvent remove_called_event;
base::WaitableEvent pending_remove_complete_event;
// Keep track of the return value for HasSecurityState() at various
// points in time during the test.
bool io_before_remove = false;
bool io_while_io_task_pending = false;
bool io_after_io_task_completed = false;
bool ui_before_remove = false;
bool ui_while_io_task_pending = false;
bool ui_after_io_task_completed = false;
// Post a task that will run on the IO thread before the task that
// Remove() will post to the IO thread.
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::BindLambdaForTesting([&]() {
// Capture state on the IO thread before Remove() is called.
io_before_remove = p->HasSecurityState(kRendererID);
// Tell the UI thread we are ready for Remove() to be called.
ready_for_remove_event.Signal();
// Wait for Remove() to be called on the UI thread.
remove_called_event.Wait();
// Capture state after Remove() is called, but before its
// task on the IO thread runs.
io_while_io_task_pending = p->HasSecurityState(kRendererID);
}));
ready_for_remove_event.Wait();
ui_before_remove = p->HasSecurityState(kRendererID);
p->Remove(kRendererID);
// Post a task to run after the task Remove() posted on the IO thread.
base::PostTask(
FROM_HERE, {BrowserThread::IO}, base::BindLambdaForTesting([&]() {
io_after_io_task_completed = p->HasSecurityState(kRendererID);
// Tell the UI thread that the task from Remove()
// has completed on the IO thread.
pending_remove_complete_event.Signal();
}));
// Capture state after Remove() has been called, but before its IO thread
// task has run. We know the IO thread task hasn't run yet because the
// task we posted before the Remove() call is waiting for us to signal
// |remove_called_event|.
ui_while_io_task_pending = p->HasSecurityState(kRendererID);
// Unblock the IO thread so the pending remove events can run.
remove_called_event.Signal();
pending_remove_complete_event.Wait();
// Capture state after IO thread task has run.
ui_after_io_task_completed = p->HasSecurityState(kRendererID);
// Run pending UI thread tasks.
base::RunLoop run_loop;
run_loop.RunUntilIdle();
bool ui_after_remove_complete = p->HasSecurityState(kRendererID);
bool io_after_remove_complete = false;
base::WaitableEvent after_remove_complete_event;
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::BindLambdaForTesting([&]() {
io_after_remove_complete = p->HasSecurityState(kRendererID);
// Tell the UI thread that this task has
// has completed on the IO thread.
after_remove_complete_event.Signal();
}));
// Wait for the task we just posted to the IO thread to complete.
after_remove_complete_event.Wait();
// Verify expected states at various parts of the removal.
// Note: IO thread is expected to keep pre-Remove() permissions until
// the task Remove() posted runs on the IO thread.
EXPECT_TRUE(io_before_remove);
EXPECT_TRUE(io_while_io_task_pending);
EXPECT_FALSE(io_after_io_task_completed);
EXPECT_TRUE(ui_before_remove);
EXPECT_FALSE(ui_while_io_task_pending);
EXPECT_FALSE(ui_after_io_task_completed);
EXPECT_FALSE(ui_after_remove_complete);
EXPECT_FALSE(io_after_remove_complete);
}
TEST_F(ChildProcessSecurityPolicyTest, IsolatedOriginPattern) {
const base::StringPiece etld1_wild("https://[*.]foo.com");
url::Origin etld1_wild_origin = url::Origin::Create(GURL("https://foo.com"));
......
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