Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Unified Diff: ios/web/public/test/http_server.mm

Issue 2794933002: Relax DCHECKs regarding Threads and RefCounts in iOS' HttpServer. (Closed)
Patch Set: Fix broken ios_chrome_web_egtests. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/public/test/http_server.mm
diff --git a/ios/web/public/test/http_server.mm b/ios/web/public/test/http_server.mm
index c5217160571ec5b3fd3ce695aa0c8500d613e35a..b5789f4a0328fe83c85133b2ab5a7b418e9188e7 100644
--- a/ios/web/public/test/http_server.mm
+++ b/ios/web/public/test/http_server.mm
@@ -9,6 +9,7 @@
#include <string>
#include "base/logging.h"
+#include "base/memory/ref_counted.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/third_party/gcdwebserver/src/GCDWebServer/Core/GCDWebServer.h"
@@ -80,6 +81,11 @@ void HttpServer::InitHttpServer() {
// Note: This block is called from an arbitrary GCD thread.
id process_request =
^GCDWebServerResponse*(GCDWebServerDataRequest* request) {
+ // Relax the cross-thread access restriction to non-thread-safe RefCount.
+ // TODO(crbug.com/707010): Remove ScopedAllowCrossThreadRefCountAccess.
+ base::ScopedAllowCrossThreadRefCountAccess
+ allow_cross_thread_ref_count_access;
+
ResponseProvider::Request provider_request =
ResponseProviderRequestFromGCDWebServerRequest(request);
scoped_refptr<RefCountedResponseProviderWrapper>
@@ -183,6 +189,10 @@ scoped_refptr<RefCountedResponseProviderWrapper>
HttpServer::GetResponseProviderForRequest(
const web::ResponseProvider::Request& request) {
base::AutoLock autolock(provider_list_lock_);
+ // Relax the cross-thread access restriction to non-thread-safe RefCount.
+ // The lock above protects non-thread-safe RefCount in HTTPServer.
+ base::ScopedAllowCrossThreadRefCountAccess
+ allow_cross_thread_ref_count_access;
scoped_refptr<RefCountedResponseProviderWrapper> result;
for (const auto& ref_counted_response_provider : providers_) {
ResponseProvider* response_provider =
@@ -202,6 +212,10 @@ void HttpServer::AddResponseProvider(
DCHECK(IsRunning()) << "Can add a response provider only when the server is "
<< "running.";
base::AutoLock autolock(provider_list_lock_);
+ // Relax the cross-thread access restriction to non-thread-safe RefCount.
+ // The lock above protects non-thread-safe RefCount in HTTPServer.
+ base::ScopedAllowCrossThreadRefCountAccess
+ allow_cross_thread_ref_count_access;
scoped_refptr<RefCountedResponseProviderWrapper>
ref_counted_response_provider(
new RefCountedResponseProviderWrapper(std::move(response_provider)));
@@ -211,6 +225,10 @@ void HttpServer::AddResponseProvider(
void HttpServer::RemoveResponseProvider(ResponseProvider* response_provider) {
DCHECK([NSThread isMainThread]);
base::AutoLock autolock(provider_list_lock_);
+ // Relax the cross-thread access restriction to non-thread-safe RefCount.
+ // The lock above protects non-thread-safe RefCount in HTTPServer.
+ base::ScopedAllowCrossThreadRefCountAccess
+ allow_cross_thread_ref_count_access;
auto found_iter = providers_.end();
for (auto it = providers_.begin(); it != providers_.end(); ++it) {
if ((*it)->GetResponseProvider() == response_provider) {
@@ -226,6 +244,10 @@ void HttpServer::RemoveResponseProvider(ResponseProvider* response_provider) {
void HttpServer::RemoveAllResponseProviders() {
DCHECK([NSThread isMainThread]);
base::AutoLock autolock(provider_list_lock_);
+ // Relax the cross-thread access restriction to non-thread-safe RefCount.
+ // The lock above protects non-thread-safe RefCount in HTTPServer.
+ base::ScopedAllowCrossThreadRefCountAccess
+ allow_cross_thread_ref_count_access;
providers_.clear();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698