Commit f0073e34 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Task Migration][Extensions] Update ApiResourceManager

api_resource_manager.h mentioned the FILE thread in a comment when
discussing resources on named threads (and theoretically would have
allowed its use). Update the comment to not mention the FILE thread and
add explicit notes that the only allowed threads are the IO and UI
threads, which are all we currently use, along with a note about how the
API could be expanded, if need be. To be safe, also add a static assert
to ensure that resources use no other threads.

Since we currently only need IO and UI threads, this CL doesn't
rearchitect anything unnecessarily.

Bug: 689520
Change-Id: I5d304fd9153865af7c9778d93b34f2e20ddb95a6
Reviewed-on: https://chromium-review.googlesource.com/591688Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491065}
parent 236d3a7e
......@@ -40,6 +40,10 @@ class UDPSocketEventDispatcher;
template <typename T>
struct NamedThreadTraits {
static_assert(T::kThreadId == content::BrowserThread::IO ||
T::kThreadId == content::BrowserThread::UI,
"ApiResources can only belong to the IO or UI thread.");
static bool IsMessageLoopValid() {
return content::BrowserThread::IsMessageLoopValid(T::kThreadId);
}
......@@ -51,7 +55,11 @@ struct NamedThreadTraits {
// An ApiResourceManager manages the lifetime of a set of resources that
// that live on named threads (i.e. BrowserThread::IO) which ApiFunctions use.
// Examples of such resources are sockets or USB connections.
// Examples of such resources are sockets or USB connections. Note: The only
// named threads that are allowed are the IO and UI threads, since all others
// are deprecated. If we ever need a resource on a different background thread,
// we can modify NamedThreadTraits to be more generic and just return a task
// runner.
//
// Users of this class should define kThreadId to be the thread that
// ApiResourceManager to works on. The default is defined in ApiResource.
......@@ -66,7 +74,7 @@ struct NamedThreadTraits {
//
// class Resource {
// public:
// static const BrowserThread::ID kThreadId = BrowserThread::FILE;
// static const BrowserThread::ID kThreadId = BrowserThread::IO;
// private:
// friend class ApiResourceManager<Resource>;
// static const char* service_name() {
......
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