Rohit Rao | ecad200 | 2018-11-16 19:42:05 | [diff] [blame^] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ios/web/web_sub_thread.h" |
| 6 | |
| 7 | #include "base/threading/thread_restrictions.h" |
| 8 | #include "ios/web/public/web_thread.h" |
| 9 | #include "ios/web/web_thread_impl.h" |
| 10 | #include "net/url_request/url_fetcher.h" |
| 11 | |
| 12 | namespace web { |
| 13 | |
| 14 | WebSubThread::WebSubThread(WebThread::ID identifier) |
| 15 | : WebThreadImpl(identifier) {} |
| 16 | |
| 17 | WebSubThread::WebSubThread(WebThread::ID identifier, |
| 18 | base::MessageLoop* message_loop) |
| 19 | : WebThreadImpl(identifier, message_loop) {} |
| 20 | |
| 21 | WebSubThread::~WebSubThread() { |
| 22 | Stop(); |
| 23 | } |
| 24 | |
| 25 | void WebSubThread::Init() { |
| 26 | WebThreadImpl::Init(); |
| 27 | |
| 28 | if (WebThread::CurrentlyOn(WebThread::IO)) { |
| 29 | // Though this thread is called the "IO" thread, it actually just routes |
| 30 | // messages around; it shouldn't be allowed to perform any blocking disk |
| 31 | // I/O. |
| 32 | base::DisallowUnresponsiveTasks(); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | void WebSubThread::CleanUp() { |
| 37 | if (WebThread::CurrentlyOn(WebThread::IO)) |
| 38 | IOThreadPreCleanUp(); |
| 39 | |
| 40 | WebThreadImpl::CleanUp(); |
| 41 | } |
| 42 | |
| 43 | void WebSubThread::IOThreadPreCleanUp() { |
| 44 | // Kill all things that might be holding onto |
| 45 | // net::URLRequest/net::URLRequestContexts. |
| 46 | |
| 47 | // Destroy all URLRequests started by URLFetchers. |
| 48 | net::URLFetcher::CancelAll(); |
| 49 | } |
| 50 | |
| 51 | } // namespace web |