1 // Copyright 2014 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.
5 #include "ios/web/web_thread_adapter.h"
7 #include "content/public/browser/browser_thread.h"
13 WebThread::ID
WebThreadIDFromBrowserThreadID(
14 content::BrowserThread::ID identifier
) {
16 case content::BrowserThread::UI
:
18 case content::BrowserThread::DB
:
20 case content::BrowserThread::FILE:
21 return WebThread::FILE;
22 case content::BrowserThread::FILE_USER_BLOCKING
:
23 return WebThread::FILE_USER_BLOCKING
;
24 case content::BrowserThread::CACHE
:
25 return WebThread::CACHE
;
26 case content::BrowserThread::IO
:
29 NOTREACHED() << "Unknown content::BrowserThread::ID: " << identifier
;
36 content::BrowserThread::ID
BrowserThreadIDFromWebThreadID(
37 WebThread::ID identifier
) {
40 return content::BrowserThread::UI
;
42 return content::BrowserThread::DB
;
44 return content::BrowserThread::FILE;
45 case WebThread::FILE_USER_BLOCKING
:
46 return content::BrowserThread::FILE_USER_BLOCKING
;
47 case WebThread::CACHE
:
48 return content::BrowserThread::CACHE
;
50 return content::BrowserThread::IO
;
52 NOTREACHED() << "Unknown web::WebThread::ID: " << identifier
;
53 return content::BrowserThread::UI
;
57 #pragma mark - web_thread.h implementation
60 bool WebThread::PostTask(ID identifier
,
61 const tracked_objects::Location
& from_here
,
62 const base::Closure
& task
) {
63 return content::BrowserThread::PostTask(
64 BrowserThreadIDFromWebThreadID(identifier
), from_here
, task
);
68 bool WebThread::PostDelayedTask(ID identifier
,
69 const tracked_objects::Location
& from_here
,
70 const base::Closure
& task
,
71 base::TimeDelta delay
) {
72 return content::BrowserThread::PostDelayedTask(
73 BrowserThreadIDFromWebThreadID(identifier
), from_here
, task
, delay
);
77 bool WebThread::PostNonNestableTask(ID identifier
,
78 const tracked_objects::Location
& from_here
,
79 const base::Closure
& task
) {
80 return content::BrowserThread::PostNonNestableTask(
81 BrowserThreadIDFromWebThreadID(identifier
), from_here
, task
);
85 bool WebThread::PostNonNestableDelayedTask(
87 const tracked_objects::Location
& from_here
,
88 const base::Closure
& task
,
89 base::TimeDelta delay
) {
90 return content::BrowserThread::PostNonNestableDelayedTask(
91 BrowserThreadIDFromWebThreadID(identifier
), from_here
, task
, delay
);
95 bool WebThread::PostTaskAndReply(ID identifier
,
96 const tracked_objects::Location
& from_here
,
97 const base::Closure
& task
,
98 const base::Closure
& reply
) {
99 return content::BrowserThread::PostTaskAndReply(
100 BrowserThreadIDFromWebThreadID(identifier
), from_here
, task
, reply
);
104 bool WebThread::PostBlockingPoolTask(const tracked_objects::Location
& from_here
,
105 const base::Closure
& task
) {
106 return content::BrowserThread::PostBlockingPoolTask(from_here
, task
);
110 bool WebThread::PostBlockingPoolTaskAndReply(
111 const tracked_objects::Location
& from_here
,
112 const base::Closure
& task
,
113 const base::Closure
& reply
) {
114 return content::BrowserThread::PostBlockingPoolTaskAndReply(from_here
, task
,
119 bool WebThread::PostBlockingPoolSequencedTask(
120 const std::string
& sequence_token_name
,
121 const tracked_objects::Location
& from_here
,
122 const base::Closure
& task
) {
123 return content::BrowserThread::PostBlockingPoolSequencedTask(
124 sequence_token_name
, from_here
, task
);
128 base::SequencedWorkerPool
* WebThread::GetBlockingPool() {
129 return content::BrowserThread::GetBlockingPool();
133 base::MessageLoop
* WebThread::UnsafeGetMessageLoopForThread(ID identifier
) {
134 return content::BrowserThread::UnsafeGetMessageLoopForThread(
135 BrowserThreadIDFromWebThreadID(identifier
));
139 bool WebThread::IsThreadInitialized(ID identifier
) {
140 return content::BrowserThread::IsThreadInitialized(
141 BrowserThreadIDFromWebThreadID(identifier
));
145 bool WebThread::CurrentlyOn(ID identifier
) {
146 return content::BrowserThread::CurrentlyOn(
147 BrowserThreadIDFromWebThreadID(identifier
));
151 bool WebThread::IsMessageLoopValid(ID identifier
) {
152 return content::BrowserThread::IsMessageLoopValid(
153 BrowserThreadIDFromWebThreadID(identifier
));
157 bool WebThread::GetCurrentThreadIdentifier(ID
* identifier
) {
158 content::BrowserThread::ID content_identifier
;
160 content::BrowserThread::GetCurrentThreadIdentifier(&content_identifier
);
162 *identifier
= WebThreadIDFromBrowserThreadID(content_identifier
);
167 scoped_refptr
<base::MessageLoopProxy
> WebThread::GetMessageLoopProxyForThread(
169 return content::BrowserThread::GetMessageLoopProxyForThread(
170 BrowserThreadIDFromWebThreadID(identifier
));
174 std::string
WebThread::GetDCheckCurrentlyOnErrorMessage(ID expected
) {
175 return content::BrowserThread::GetDCheckCurrentlyOnErrorMessage(
176 BrowserThreadIDFromWebThreadID(expected
));