chromium cache介绍

本文介绍了Chromium的Cache系统,包括DiskCache的不同类型如blockfile、memory和simple cache。详细讲解了Cache的主要结构,尤其是Simple Cache的组成,如Index文件和Data文件的详细信息,以及文件内部的序列化和格式。同时,提到了如何编译和测试Chromium的net模块。
摘要由CSDN通过智能技术生成

Chromium Cache

官方文档

Chromium Cache 分类

DiskCache

blockfile: mac上的chrome以及ios使用的该类cache

memory: 隐私模式使用该类的cache

simple cache: android linux 以及 mac上的chromium使用这种

下载编译chromium (方便下载,我在gitlab上传了一份)

编译chromium文档 编译

为了方便,我们并不需要编译chromium,chromium项目对于每个模块都有相应的测试单元,我们只需编译net模块的测试单元。

添加我们的测试单元并编译net_unittests

Ubuntu16.04 + 8G内存以上

下载depot_tools

git clone https://gitlab.com/wanghui0705/depot_tools.git

将depot_tools配置到环境变量


下载代码

git clone https://gitlab.com/wanghui0705/chromium.git


切换到src目录 应用以下patch, 创建5个entry, 然后我们根据生成的cache文件来分析

diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index 3fd25fa54cf7..6751f293a6b2 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -4533,6 +4533,40 @@ TEST_F(DiskCacheEntryTest, SimpleCacheTruncateLargeSparseFile) {
   entry->Close();
 }

+TEST_F(DiskCacheEntryTest, SimpleCacheMultiEntryTest) {
+  SetCacheType(net::DISK_CACHE);
+  SetSimpleCacheMode();
+  InitCache();
+  std::vector<std::string> entry_keys = {
+    "first",
+    "second",
+    "third",
+    "forth",
+    "fifth"
+  };
+
+  for(auto key : entry_keys) {
+    disk_cache::Entry* entry;
+    if(CreateEntry(key, &entry) == net::OK) {
+      std::string content_0_data = key + " content_0_data";
+      scoped_refptr<net::IOBuffer> content_0_iobuffer(
+          new net::StringIOBuffer(content_0_data));
+      WriteData(entry, 0, 0, content_0_iobuffer.get(),
+                content_0_data.size(), false);
+      std::string content_1_data = key + " content_1_data";
+      scoped_refptr<net::IOBuffer> content_1_iobuffer(
+          new net::StringIOBuffer(content_1_data));
+      WriteData(entry, 1, 0, content_1_iobuffer.get(),
+                content_1_data.size(), false);
+      entry->Close();
+    }
+  }
+
+  base::RunLoop().Run();
+}
+


1)build/install-build-deps-android.sh

2)gn gen --args='target_os="android"' out/Default

3) ninja -C out/Default net_unittests

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值