1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
// Copyright 2014 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_thread_adapter.h"
#include "content/public/browser/browser_thread.h"
namespace web {
namespace {
WebThread::ID WebThreadIDFromBrowserThreadID(
content::BrowserThread::ID identifier) {
switch (identifier) {
case content::BrowserThread::UI:
return WebThread::UI;
case content::BrowserThread::DB:
return WebThread::DB;
case content::BrowserThread::FILE:
return WebThread::FILE;
case content::BrowserThread::FILE_USER_BLOCKING:
return WebThread::FILE_USER_BLOCKING;
case content::BrowserThread::CACHE:
return WebThread::CACHE;
case content::BrowserThread::IO:
return WebThread::IO;
default:
NOTREACHED() << "Unknown content::BrowserThread::ID: " << identifier;
return WebThread::UI;
}
}
} // namespace
content::BrowserThread::ID BrowserThreadIDFromWebThreadID(
WebThread::ID identifier) {
switch (identifier) {
case WebThread::UI:
return content::BrowserThread::UI;
case WebThread::DB:
return content::BrowserThread::DB;
case WebThread::FILE:
return content::BrowserThread::FILE;
case WebThread::FILE_USER_BLOCKING:
return content::BrowserThread::FILE_USER_BLOCKING;
case WebThread::CACHE:
return content::BrowserThread::CACHE;
case WebThread::IO:
return content::BrowserThread::IO;
default:
NOTREACHED() << "Unknown web::WebThread::ID: " << identifier;
return content::BrowserThread::UI;
}
}
#pragma mark - web_thread.h implementation
// static
bool WebThread::PostTask(ID identifier,
const tracked_objects::Location& from_here,
const base::Closure& task) {
return content::BrowserThread::PostTask(
BrowserThreadIDFromWebThreadID(identifier), from_here, task);
}
// static
bool WebThread::PostDelayedTask(ID identifier,
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
return content::BrowserThread::PostDelayedTask(
BrowserThreadIDFromWebThreadID(identifier), from_here, task, delay);
}
// static
bool WebThread::PostNonNestableTask(ID identifier,
const tracked_objects::Location& from_here,
const base::Closure& task) {
return content::BrowserThread::PostNonNestableTask(
BrowserThreadIDFromWebThreadID(identifier), from_here, task);
}
// static
bool WebThread::PostNonNestableDelayedTask(
ID identifier,
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
return content::BrowserThread::PostNonNestableDelayedTask(
BrowserThreadIDFromWebThreadID(identifier), from_here, task, delay);
}
// static
bool WebThread::PostTaskAndReply(ID identifier,
const tracked_objects::Location& from_here,
const base::Closure& task,
const base::Closure& reply) {
return content::BrowserThread::PostTaskAndReply(
BrowserThreadIDFromWebThreadID(identifier), from_here, task, reply);
}
// static
bool WebThread::PostBlockingPoolTask(const tracked_objects::Location& from_here,
const base::Closure& task) {
return content::BrowserThread::PostBlockingPoolTask(from_here, task);
}
// static
bool WebThread::PostBlockingPoolTaskAndReply(
const tracked_objects::Location& from_here,
const base::Closure& task,
const base::Closure& reply) {
return content::BrowserThread::PostBlockingPoolTaskAndReply(from_here, task,
reply);
}
// static
bool WebThread::PostBlockingPoolSequencedTask(
const std::string& sequence_token_name,
const tracked_objects::Location& from_here,
const base::Closure& task) {
return content::BrowserThread::PostBlockingPoolSequencedTask(
sequence_token_name, from_here, task);
}
// static
base::SequencedWorkerPool* WebThread::GetBlockingPool() {
return content::BrowserThread::GetBlockingPool();
}
// static
base::MessageLoop* WebThread::UnsafeGetMessageLoopForThread(ID identifier) {
return content::BrowserThread::UnsafeGetMessageLoopForThread(
BrowserThreadIDFromWebThreadID(identifier));
}
// static
bool WebThread::IsThreadInitialized(ID identifier) {
return content::BrowserThread::IsThreadInitialized(
BrowserThreadIDFromWebThreadID(identifier));
}
// static
bool WebThread::CurrentlyOn(ID identifier) {
return content::BrowserThread::CurrentlyOn(
BrowserThreadIDFromWebThreadID(identifier));
}
// static
bool WebThread::IsMessageLoopValid(ID identifier) {
return content::BrowserThread::IsMessageLoopValid(
BrowserThreadIDFromWebThreadID(identifier));
}
// static
bool WebThread::GetCurrentThreadIdentifier(ID* identifier) {
content::BrowserThread::ID content_identifier;
bool result =
content::BrowserThread::GetCurrentThreadIdentifier(&content_identifier);
if (result)
*identifier = WebThreadIDFromBrowserThreadID(content_identifier);
return result;
}
// static
scoped_refptr<base::SingleThreadTaskRunner> WebThread::GetTaskRunnerForThread(
ID identifier) {
return content::BrowserThread::GetMessageLoopProxyForThread(
BrowserThreadIDFromWebThreadID(identifier));
}
// static
std::string WebThread::GetDCheckCurrentlyOnErrorMessage(ID expected) {
return content::BrowserThread::GetDCheckCurrentlyOnErrorMessage(
BrowserThreadIDFromWebThreadID(expected));
}
} // namespace web
|