OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/browser/font_list_async.h" | 5 #include "content/public/browser/font_list_async.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "content/common/font_list.h" | 9 #include "content/common/font_list.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Just executes the given callback with the parameter. | 16 // Just executes the given callback with the parameter. |
17 void ReturnFontListToOriginalThread( | 17 void ReturnFontListToOriginalThread( |
18 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback, | 18 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback, |
19 scoped_ptr<base::ListValue> result) { | 19 scoped_ptr<base::ListValue> result) { |
20 callback.Run(result.Pass()); | 20 callback.Run(result.Pass()); |
21 } | 21 } |
22 | 22 |
23 void GetFontListOnFileThread( | 23 void GetFontListInBlockingPool( |
24 BrowserThread::ID calling_thread_id, | 24 BrowserThread::ID calling_thread_id, |
25 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback) { | 25 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback) { |
26 scoped_ptr<base::ListValue> result(GetFontList_SlowBlocking()); | 26 scoped_ptr<base::ListValue> result(GetFontList_SlowBlocking()); |
27 BrowserThread::PostTask(calling_thread_id, FROM_HERE, | 27 BrowserThread::PostTask(calling_thread_id, FROM_HERE, |
28 base::Bind(&ReturnFontListToOriginalThread, callback, | 28 base::Bind(&ReturnFontListToOriginalThread, callback, |
29 base::Passed(&result))); | 29 base::Passed(&result))); |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 void GetFontListAsync( | 34 void GetFontListAsync( |
35 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback) { | 35 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback) { |
36 BrowserThread::ID id; | 36 BrowserThread::ID id; |
37 bool well_known_thread = BrowserThread::GetCurrentThreadIdentifier(&id); | 37 bool well_known_thread = BrowserThread::GetCurrentThreadIdentifier(&id); |
38 DCHECK(well_known_thread) | 38 DCHECK(well_known_thread) |
39 << "Can only call GetFontList from a well-known thread."; | 39 << "Can only call GetFontList from a well-known thread."; |
40 | 40 |
41 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 41 BrowserThread::PostBlockingPoolTask(FROM_HERE, |
42 base::Bind(&GetFontListOnFileThread, id, callback)); | 42 base::Bind(&GetFontListInBlockingPool, id, callback)); |
43 } | 43 } |
44 | 44 |
45 } // namespace content | 45 } // namespace content |
OLD | NEW |