chromium之task
// A task is a generic runnable thingy, usually used for running code on a // different thread or for scheduling future tasks off of the message loop.
Task也是比较重要的一个类,先逐个分析头文件
#include "base/non_thread_safe.h" #include "base/revocable_store.h" #include "base/tracked.h" #include "base/tuple.h"
第一个文件
#include "base/non_thread_safe.h"
参考分析chromium之non_thread_safe,线程安全
下一个文件
#include "base/revocable_store.h"
参考分析chromium之revocable_store,可撤销的容器
下一个文件
#include "base/tracked.h"
参考分析chromium之tracked,记录,分析函数调用等等
下一个文件
#include "base/tuple.h"
参考分析chromium之tuple,通用的模板容器
分析下代码
class Task : public tracked_objects::Tracked { public: Task() {} virtual ~Task() {} // Tasks are automatically deleted after Run is called. virtual void Run() = 0; }; class CancelableTask : public Task { public: // Not all tasks support cancellation. virtual void Cancel() = 0; };
继承Task, 实现Run()函数即可