Commit ecad200a authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Creates WebSubThread to mirror BrowserProcessSubThread.

Moves IO thread-specific initialization into WebSubThread.

BUG=826465

Change-Id: I5527dafdf75c29fbc8478f7500c20a96410ad008
Reviewed-on: https://chromium-review.googlesource.com/c/1335961Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608898}
parent 9e21065a
......@@ -71,6 +71,8 @@ source_set("web") {
"url_util.cc",
"web_client.mm",
"web_kit_constants.cc",
"web_sub_thread.cc",
"web_sub_thread.h",
"web_thread_impl.cc",
"web_thread_impl.h",
"web_view_creation_util.mm",
......
......@@ -21,6 +21,7 @@ class CookieNotificationBridge;
class ServiceManagerContext;
class WebMainParts;
class WebThreadImpl;
class WebSubThread;
// Implements the main web loop stages called from WebMainRunner.
// See comments in web_main_parts.h for additional info.
......@@ -83,7 +84,7 @@ class WebMainLoop {
std::unique_ptr<WebThreadImpl> main_thread_;
// Members initialized in |RunMainMessageLoopParts()| ------------------------
std::unique_ptr<WebThreadImpl> io_thread_;
std::unique_ptr<WebSubThread> io_thread_;
// Members initialized in |WebThreadsStarted()| --------------------------
std::unique_ptr<CookieNotificationBridge> cookie_notification_bridge_;
......
......@@ -27,6 +27,7 @@
#import "ios/web/public/web_client.h"
#include "ios/web/public/web_task_traits.h"
#include "ios/web/service_manager_context.h"
#include "ios/web/web_sub_thread.h"
#include "ios/web/web_thread_impl.h"
#include "ios/web/webui/url_data_manager_ios.h"
......@@ -128,7 +129,7 @@ int WebMainLoop::CreateThreads(
base::Thread::Options io_message_loop_options;
io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO;
io_thread_ = std::make_unique<WebThreadImpl>(WebThread::IO);
io_thread_ = std::make_unique<WebSubThread>(WebThread::IO);
io_thread_->StartWithOptions(io_message_loop_options);
// Only start IO thread above as this is the only WebThread besides UI (which
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/web/web_sub_thread.h"
#include "base/threading/thread_restrictions.h"
#include "ios/web/public/web_thread.h"
#include "ios/web/web_thread_impl.h"
#include "net/url_request/url_fetcher.h"
namespace web {
WebSubThread::WebSubThread(WebThread::ID identifier)
: WebThreadImpl(identifier) {}
WebSubThread::WebSubThread(WebThread::ID identifier,
base::MessageLoop* message_loop)
: WebThreadImpl(identifier, message_loop) {}
WebSubThread::~WebSubThread() {
Stop();
}
void WebSubThread::Init() {
WebThreadImpl::Init();
if (WebThread::CurrentlyOn(WebThread::IO)) {
// Though this thread is called the "IO" thread, it actually just routes
// messages around; it shouldn't be allowed to perform any blocking disk
// I/O.
base::DisallowUnresponsiveTasks();
}
}
void WebSubThread::CleanUp() {
if (WebThread::CurrentlyOn(WebThread::IO))
IOThreadPreCleanUp();
WebThreadImpl::CleanUp();
}
void WebSubThread::IOThreadPreCleanUp() {
// Kill all things that might be holding onto
// net::URLRequest/net::URLRequestContexts.
// Destroy all URLRequests started by URLFetchers.
net::URLFetcher::CancelAll();
}
} // namespace web
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_WEB_SUB_THREAD_H_
#define IOS_WEB_WEB_SUB_THREAD_H_
#include "base/macros.h"
#include "ios/web/web_thread_impl.h"
namespace web {
// This simple thread object is used for the specialized threads that are spun
// up during startup.
class WebSubThread : public WebThreadImpl {
public:
explicit WebSubThread(WebThread::ID identifier);
WebSubThread(WebThread::ID identifier, base::MessageLoop* message_loop);
~WebSubThread() override;
protected:
void Init() override;
void CleanUp() override;
private:
// These methods encapsulate cleanup that needs to happen on the IO thread
// before the embedder's |CleanUp()| function is called.
void IOThreadPreCleanUp();
DISALLOW_COPY_AND_ASSIGN(WebSubThread);
};
} // namespace web
#endif // IOS_WEB_WEB_SUB_THREAD_H_
......@@ -17,10 +17,8 @@
#include "base/single_thread_task_runner.h"
#include "base/task/post_task.h"
#include "base/task/task_executor.h"
#include "base/threading/thread_restrictions.h"
#include "ios/web/public/web_task_traits.h"
#include "ios/web/public/web_thread_delegate.h"
#include "net/url_request/url_fetcher.h"
namespace web {
......@@ -223,11 +221,6 @@ void WebThreadImpl::Init() {
base::subtle::NoBarrier_Load(&globals.io_thread_delegate);
if (delegate)
reinterpret_cast<WebThreadDelegate*>(delegate)->Init();
// Though this thread is called the "IO" thread, it actually just routes
// messages around; it shouldn't be allowed to perform any blocking disk
// I/O.
base::DisallowUnresponsiveTasks();
}
}
......@@ -262,8 +255,6 @@ void WebThreadImpl::Run(base::RunLoop* run_loop) {
void WebThreadImpl::CleanUp() {
if (identifier_ == WebThread::IO) {
IOThreadPreCleanUp();
WebThreadGlobals& globals = g_globals.Get();
WebThreadDelegateAtomicPtr delegate =
base::subtle::NoBarrier_Load(&globals.io_thread_delegate);
......@@ -281,14 +272,6 @@ void WebThreadImpl::Initialize() {
globals.threads[identifier_] = this;
}
void WebThreadImpl::IOThreadPreCleanUp() {
// Kill all things that might be holding onto
// net::URLRequest/net::URLRequestContexts.
// Destroy all URLRequests started by URLFetchers.
net::URLFetcher::CancelAll();
}
WebThreadImpl::~WebThreadImpl() {
// All Thread subclasses must call Stop() in the destructor. This is
// doubly important here as various bits of code check they are on
......
......@@ -51,10 +51,6 @@ class WebThreadImpl : public WebThread, public base::Thread {
// Common initialization code for the constructors.
void Initialize();
// Performs cleanup that needs to happen on the IO thread before calling the
// embedder's CleanUp function.
void IOThreadPreCleanUp();
// For testing.
friend class TestWebThreadBundle;
friend class TestWebThreadBundleImpl;
......
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