Posts List

Mac上编译CEF62

CEF是基于chromium的开源项目,让集成chrome的浏览器内核非常方便,而且紧跟升级的节奏,在客户端产品上广泛使用。官网其实已经打了二进制包,可以直接拿来集成。 不过有时候我们还需要自己来打包,最常见的几个原因: 需要集成音视频能力(默 ...

关于向chromium的pak文件扩展字符串的方法

chromium中管理自带的字符串和文件等一般使用pak包格式文件,本文介绍下向chromium的pak文件中添加自己定义的字符串的方法。 分析pak包字符串使用 例如,在chromium中使用pak包ui_strings中的定义的字符串的方式 ...

Chromium 44 编译与调试

本文整理了当前最新的chromium 44开源代码的编译及调试方法,基本上是结合了官网的一些信息,以及实践中的注意点记录。 Widows Windows环境下:参考 http://www.chromium.org/developers/how-tos/build-instructions-windows 环境配置 操作系统要求 win7 64位及以上的系统版本,32位不支持 更改系统区域语言为英语 [控制面板 ...

DataPack in chrome

pak是chrome中跨平台的资源管理文件格式,比如用于多语言,本地文件(html数据)或数据的格式化管理等;对于pak文件处理,chrome提供了C++类和python脚本的方式来处理。 pak文件格式:(Data File Format version 4) uint32 文件版本 uint32 文件 ...

Linked_ptr in chrome

Linked_ptr is a “smart” pointer type with reference tracking. Alternative to linked_ptr is shared_ptr. Every pointer to a particular object is kept on a circular linked list. When the last pointer to an object is destroyed or reassigned, the object is deleted. Used properly, this deletes the object when the last reference goes away. A good use of this class is storing object references in STL containers. You can safely put linked_ptr<> in a vector<>. Other uses may not be as good. There are several caveats Like all reference counting schemes, cycles lead to leaks. Each smart pointer is actually two pointers (8 bytes instead of 4). Every time a pointer is released, the entire list of pointers to that object is traversed. ...

FileStream in chrome

FileStream is a basic interface for reading and writing files synchronously or asynchronously with support for seeking to an offset. Generally speaking, we normally use asynchronous mode on a TYPE_IO Thread, because it’s more effective. Note that even when used asynchronously, only one operation is supported at a time. FileStream class declare classNET_EXPORT FileStream { public: // Creates a |FileStream| with a new |BoundNetLog| (based on |net_log|) // attached. |net_log| may be NULL if no logging is needed. // Uses |task_runner| for asynchronous operations. FileStream(net::NetLog* net_log, const scoped_refptr<base::TaskRunner>& task_runner); // |flags| is a bitfield of base::PlatformFileFlags when the file handle was // opened. FileStream(base::PlatformFile file, int flags, net::NetLog* net_log, const scoped_refptr<base::TaskRunner>& task_runner); // The underlying file is closed automatically. ...

SequencedWorkerPool in chrome

SequencedWorkerPool is a worker thread pool that allow you to post unordered tasks, and it also can enforce ordering between sets of tasks. What’s more, It allows you to specify what should happen to your tasks on shutdown. Ordered Tasks To enforce ordering, get a unique sequence token from the pool and post all tasks you want to order with the token. All tasks with the same token are guaranteed to execute serially, though not necessarily on the same thread. This means that: No two tasks with the same token will run at the same time. Given two tasks T1 and T2 with the same token such that T2 will run after T1, then T2 will start after T1 is destroyed. ...

Network Stack in chrome

The network stack is a mostly single-threaded cross-platform library primarily for resource fetching. Its main interfaces are URLRequest and URLRequestContext. URLRequest, as indicated by its name, represents the request for a URL. URLRequestContext contains all the associated context necessary to fulfill the URL request, such as cookies, host resolver, proxy resolver, cache, etc. Many URLRequest objects may share the same URLRequestContext. Most net objects are not threadsafe, although the disk cache can use a dedicated thread, and several components (host resolution, certificate verification, etc.) may use unjoined worker threads. Since it primarily runs on a single network thread, no operation on the network thread is allowed to block. Therefore we use non-blocking operations with asynchronous callbacks (typically CompletionCallback). ...

ObserverList in chrome

ObserverList<ObserverType> is a container for a list of observers, it is an easy-to-use observer pattern for two related objects. Unlike a normal STL vector or list, this container can be modified during iteration without invalidating the iterator. So, it safely handles the case of an observer removing itself or other observers from the list while observers are being notified. If you want to deal with observer_list in multi-thread, just use ObserverListThreadSafe. ObserverList template <classObserverType, bool check_empty = false> classObserverList : public ObserverListBase<ObserverType> { //... }; #define FOR_EACH_OBSERVER(ObserverType, observer_list, func) \ do { \ if ((observer_list).might_have_observers()) { \ ObserverListBase<ObserverType>::Iterator it(observer_list); \ ObserverType* obs; \ while ((obs = it.GetNext()) != NULL) \ obs->func; \ } \ } while (0) Example #include "base/observer_list. ...

Notification Registrar in chrome

Event register and callback are very common and useful in an app, chrome implements an simple, uncoupled and smart Notification Mechanism. NotificationRegistrar This class is designed to register for notifications and ensures that all registered notifications are unregistered when the class is destroyed. The intended use is that you make a NotificationRegistrar member in your class and use it to register your notifications instead of going through the notification service directly. It will automatically unregister them for you. // callback interface classCONTENT_EXPORT NotificationObserver { public: virtual void Observe(int type, const NotificationSource& source, const NotificationDetails& details) = 0; protected: virtual ~NotificationObserver() {} }; // notification registrar classCONTENT_EXPORT NotificationRegistrar : NON_EXPORTED_BASE(public base::NonThreadSafe) { public: // This class must not be derived from (we don't have a virtual destructor so // it won't work). ...

Synchronization in chrome

In Chrome code, message passing is far more common (via TaskRunner and PostTask) and low-level synchronization primitives like locks, condition variables and waitable_event should be used only when necessary. This article introduce the implement of synchronization mechanism in chrome source code. Some additional motivation: Condition variables are nearly impossible to implement correctly on Windows XP or earlier. Chrome’s implementation is correct, but very slow. Whenever you use a CV you are disproportionately harming our performance on Windows. A lot of times people just want to wait on a boolean. In such cases, if message passing cannot work, please use WaitableEvent instead. Lock The Lock class implements a mutual exclusion lock, or mutex for short. A mutex is used to permit only one thread at a time to have exclusive access to some resource, which is typically some variable or data structure. ...

Lazy Instance in chrome

Lazy instance is an object which is created on the first time it’s accessed. And chrome implements a very powerful LazyInstance template class, which is very fast and thread safe. See detail in ( lazy_instance.h ). Class: LazyInstance<Type, Traits> The LazyInstance<Type, Traits> class manages a single instance of Type, which will be lazily created on the first time it’s accessed. This class is useful for places you would normally use a function-level static, but you need to have guaranteed thread-safety. The Type constructor will only ever be called once, even if two threads are racing to create the object. Get() and Pointer() will always return the same, completely initialized instance. When the instance is constructed, it is registered with AtExitManager. ...

Thread and MessageLoop in chrome

Threads are very useful in application to deal with multi-thread problems, and chrome wrapped a series of excellent classes: base::Thread, MessageLoop and so on. Thread A simple thread abstraction that establishes a MessageLoop on a new thread. The consumer uses the MessageLoop of the thread to cause code to execute on the thread. When this object is destroyed, the thread is terminated. All pending tasks queued on the thread’s message loop will run to completion before the thread is terminated. WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). After the thread is stopped, the destruction sequence is: Thread::CleanUp() MessageLoop::~MessageLoop MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop Thread class classBASE_EXPORT Thread : PlatformThread::Delegate { public: struct Options { Options() : message_loop_type(MessageLoop::TYPE_DEFAULT), stack_size(0) {} Options(MessageLoop::Type type, size_t size) : message_loop_type(type), stack_size(size) {} MessageLoop::Type message_loop_type; size_t stack_size; }; explicit Thread(const char* name); // Destroys the thread, stopping it if necessary. ...

Value and JsonParser in chrome

Class base::Value is a variant type to holder complex data, this article introduce the use of base::Value in chrome source code. base::Value The Value class is the base class for Values. A Value can be instantiated via the Create*Value() factory methods, or by directly creating instances of the subclasses. classBinaryValue; classDictionaryValue; classFundamentalValue; classListValue; classStringValue; classValue; classBASE_EXPORT Value { public: enum Type { TYPE_NULL = 0, TYPE_BOOLEAN, TYPE_INTEGER, TYPE_DOUBLE, TYPE_STRING, TYPE_BINARY, TYPE_DICTIONARY, TYPE_LIST }; static Value* CreateNullValue(); // other types use new FundamentalValue or new StringValue etc. Type GetType() const { return type_; } bool IsType(Type type) const { return type == type_; } virtual bool GetAsBoolean(bool* out_value) const; virtual bool GetAsInteger(int* out_value) const; virtual bool GetAsDouble(double* out_value) const; virtual bool GetAsString(std::string* out_value) const; virtual bool GetAsString(string16* out_value) const; virtual bool GetAsList(ListValue** out_value); virtual bool GetAsDictionary(DictionaryValue** out_value); // Subclasses return their own type directly in their overrides; virtual Value* DeepCopy() const; // Compares if two Value objects have equal contents. ...

WeakPtr in chrome

WeakPtr is normally used to avoid recursive reference, this article introduce the use of WeakPtr and WeakPtrFactory in chrome source code. Weak pointers are pointers to an object that do not affect its lifetime, and which may be invalidated (i.e. reset to NULL) by the object, or its owner, at any time, most commonly when the object is about to be deleted. Weak pointers are useful when an object needs to be accessed safely by one or more objects other than its owner, and those callers can cope with the object vanishing and e.g. tasks posted to it being silently dropped. Reference-counting such an object would complicate the ownership graph and make it harder to reason about the object’s lifetime. ...