码迷,mamicode.com
首页 > 其他好文 > 详细

chromium网络资源加载分析(三) 主资源加载逻辑分析 之body部分加载---chromium39

时间:2015-01-23 13:22:44      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:chromium   blink   主资源加载   网页body部分加载   

转载:请标注 from你吧吧

该blog我们来看看网页加载过程中,body部分的加载。

首先,先说明一下,无论是head部分还是body部分,最终的加载对象,都是通过HttpStreamParser对象和WebSocketBasicHandshakeStream对象来从网络上加载资源。这段逻辑没有在blog中标明,先声称下。




1. 接着上篇blog。上个blog中有这么一条:

  “ 22. 方法ReadRawDataHelper中又会调用文件中url_request_http_job.cc方法:URLRequestHttpJob::ReadRawData”

 我们接着看方法:url_request_http_job.cc方法:URLRequestHttpJob::ReadRawData

2. 上面提到该方法中有代码:


  int rv = transaction_->Read(
      buf, buf_size,
      base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this)));

这里会调用http_cache_transaction.cc 方法:HttpCache::Transaction::Read(

注:这里会用到cache模式相关知识。我们这里先不做研究。只看chromium默认模式

3. 上面方法会调用同文件方法:HttpCache::Transaction::ReadFromNetwork

    从这里开始,就开始了body部分的下载过程。

   先贴出一段body下载(ipad ua下加载 www.baidu.com)最开始的调用逻辑:

I/chromium( 2598): [http_cache_transaction.cc(820)] HttpCache::Transaction::DoLoop
I/chromium( 2598): [http_cache_transaction.cc(851)] HttpCache::Transaction::DoLoop 6 STATE_NETWORK_READ
I/chromium( 2598): [http_cache_transaction.cc(1271)] HttpCache::Transaction::DoNetworkRead()
I/chromium( 2598): [http_network_transaction.cc(704)] HttpNetworkTransaction::DoLoop STATE_READ_BODY
I/chromium( 2598): [http_network_transaction.cc(711)] HttpNetworkTransaction::DoLoop STATE_READ_BODY_COMPLETE
I/chromium( 2598): [http_cache_transaction.cc(856)] HttpCache::Transaction::DoLoop 7 STATE_NETWORK_READ_COMPLETE
I/chromium( 2598): [http_cache_transaction.cc(997)] HttpCache::Transaction::DoLoop 38 STATE_CACHE_WRITE_DATA
I/chromium( 2598): [http_cache_transaction.cc(1001)] HttpCache::Transaction::DoLoop 39 STATE_CACHE_WRITE_DATA_COMPLETE
I/chromium( 2598): [http_cache_transaction.cc(1878)] HttpCache::Transaction::DoCacheWriteDataComplete
I/chromium( 2598): [http_cache_transaction.cc(1902)] HttpCache::Transaction::DoCacheWriteDataComplete result is 10
I/chromium( 2598): [url_request_job.cc(718)] URLRequestJob::ReadRawDataHelper and OnRawReadComplete
I/chromium( 2598): [url_request_job.cc(732)] URLRequestJob::OnRawReadComplete  bytes_read is 10
I/chromium( 2598): [url_request_job.cc(557)] URLRequestJob::ReadFilteredData 1
I/chromium( 2598): [url_request_job.cc(696)] URLRequestJob::ReadRawDataForFilter stream_buffer_size is 32768
I/chromium( 2598): [url_request_job.cc(704)] URLRequestJob::ReadRawDataHelper
I/chromium( 2598): [url_request_http_job.cc(1257)] URLRequestHttpJob::ReadRawData
I/chromium( 2598): [http_cache_transaction.cc(518)] HttpCache::Transaction::Read
I/chromium( 2598): [http_cache_transaction.cc(2610)] HttpCache::Transaction::ReadFromNetwork
I/chromium( 2598): [http_cache_transaction.cc(820)] HttpCache::Transaction::DoLoop
I/chromium( 2598): [http_cache_transaction.cc(851)] HttpCache::Transaction::DoLoop 6 STATE_NETWORK_READ
I/chromium( 2598): [http_cache_transaction.cc(1271)] HttpCache::Transaction::DoNetworkRead()
I/chromium( 2598): [http_network_transaction.cc(704)] HttpNetworkTransaction::DoLoop STATE_READ_BODY
I/chromium( 2598): [INFO:http_network_transaction.cc(711)] HttpNetworkTransaction::DoLoop STATE_READ_BODY_COMPLETE
I/chromium( 2598): [http_cache_transaction.cc(856)] HttpCache::Transaction::DoLoop 7 STATE_NETWORK_READ_COMPLETE
I/chromium( 2598): [http_cache_transaction.cc(997)] HttpCache::Transaction::DoLoop 38 STATE_CACHE_WRITE_DATA
I/chromium( 2598): [http_cache_transaction.cc(2921)] HttpCache::Transaction::OnIOComplete
I/chromium( 2598): [http_cache_transaction.cc(820)] HttpCache::Transaction::DoLoop
I/chromium( 2598): [http_cache_transaction.cc(1001)] HttpCache::Transaction::DoLoop 39 STATE_CACHE_WRITE_DATA_COMPLETE
I/chromium( 2598): [http_cache_transaction.cc(1878)] HttpCache::Transaction::DoCacheWriteDataComplete
I/chromium( 2598): [http_cache_transaction.cc(1902)] HttpCache::Transaction::DoCacheWriteDataComplete result is 20988
I/chromium( 2598): [url_request_http_job.cc(903)] URLRequestHttpJob::OnReadCompleted
经过上面这段逻辑,body已经被加载下来。

4. 我们接着上面提到的URLRequestHttpJob::OnReadCompleted方法去看。该方法中有代码:NotifyReadComplete(result);

5. 上面提到代码是文件:url_request_job.cc中方法:URLRequestJob::NotifyReadComplete

    该方法会调用同文件方法:URLRequestJob::OnRawReadComplete

    之后,又调用同文件方法:URLRequestJob::ReadFilteredData

   接着调用url_request.cc方法:URLRequest::NotifyReadCompleted

6. 在方法:URLRequest::NotifyReadCompleted有代码:

  if (delegate_)
    delegate_->OnReadCompleted(this, bytes_read);

 这里delegate_是content目录下的ResourceLoader对象。

  我们来看content目录下文件:resouce_loader.cc 的方法:ResourceLoader::OnReadCompleted

  该方法会调用同文件中方法:ResourceLoader::CompleteRead

  该方法中有代码:

if (!handler_->OnReadCompleted(bytes_read, &defer)) {

7. 上面提到代码是调用文件:buffered_resource_handler.cc中方法:BufferedResourceHandler::OnReadCompleted

    该方法中有代码:return next_handler_->OnReadCompleted(bytes_read, defer);
    这里会调用文件:async_resource_handler.cc中方法:AsyncResourceHandler::OnReadCompleted

    该方法中有代码:

  

  filter->Send(new ResourceMsg_DataReceived(
      GetRequestID(), data_offset, bytes_read, encoded_data_length));

这里进行IPC通讯。该消息的处理是在文件:content目录下文件resource_dispatcher:ResourceDispatcher::OnReceivedData

 该方法中有代码:

 

        request_info->peer->OnReceivedData(
            data_ptr, data_length, encoded_data_length);

8. 上面提到的代码调用的是 content目录下文件:web_url_loader_impl.cc中方法:

     WebURLLoaderImpl::Context::OnReceivedData

    该方法中有代码: client_->didReceiveData(loader_, data, data_length, encoded_data_length);

9. 上面方法调用的是文件:thirdparty/WebKIt下文件ResourceLoader.cpp中方法:ResourceLoader::didReceiveData

     该方法中有代码: m_resource->appendData(data, length);

10. 上面提到的代码执行的thirdparty/WebKIt下文件RawResource.cpp中方法:RawResource::appendData

      该方法中有代码:

    

    while (RawResourceClient* c = w.next())
        c->dataReceived(this, data, length);

这里执行的是DocumentLoader.cpp中方法:DocumentLoader::dataReceived

该方法中又会调用同文件中方法:DocumentLoader::commitData


11. 我们接着看6中提到的

      content目录下文件:resouce_loader.cc 的方法:ResourceLoader::OnReadCompleted

     该方法在执行CompleteRead(bytes_read);代码之后会调用:同文件方法:ResourceLoader::StartReading

12. 我们来看方法:ResourceLoader::StartReading

      该方法中先调用同文件方法:ResourceLoader::ReadMore

      然后执行代码:OnReadCompleted(request_.get(), bytes_read);

     我们先来看看ResourceLoader::ReadMore

13. 方法:ResourceLoader::ReadMore中有代码:request_->Read(buf.get(), buf_size, bytes_read);

     该代码是执行的是文件url_request.cc中方法:URLRequest::Read

      该方法中有代码:bool rv = job_->Read(dest, dest_size, bytes_read);

14. 上面提到的代码是文件:url_request_job.cc中方法:URLRequestJob::Read

       该方法又会调用同文件中方法:URLRequestJob::ReadFilteredData(

15. 我们再返回来看12中提到的”OnReadCompleted(request_.get(), bytes_read);

       该代码是文件resource_loader.cc中方法:ResourceLoader::OnReadCompleted

     该方法会调用同文件种方法:ResourceLoader::CompleteRead

     该方法会调用:AsyncResourceHandler::OnReadCompleted方法。

    到这里再次重复 前面7及之后的逻辑,直到14中的URLRequestJob::ReadFilteredData(


16. 此时,之前从网络上加载的资源已经完全交给DocumentLoader。此时,需要再次从网络上加载资源。

    故:URLRequestJob::ReadFilteredData(方法会调用同文件中方法:

   URLRequestJob::ReadRawDataForFilter

17. 上面的方法会调用同文件中方法:URLRequestJob::ReadRawDataHelper

18. 上面方法会调用文件:url_request_http_job.cc中方法:URLRequestHttpJob::ReadRawData

      这块逻辑的调用如下:

I/chromium( 2598): [url_request_job.cc(704)] URLRequestJob::ReadRawDataHelper
I/chromium( 2598): [url_request_http_job.cc(1257)] URLRequestHttpJob::ReadRawData
I/chromium( 2598): [http_cache_transaction.cc(518)] HttpCache::Transaction::Read
I/chromium( 2598): [http_cache_transaction.cc(2610)] HttpCache::Transaction::ReadFromNetwork
I/chromium( 2598): [http_cache_transaction.cc(820)] HttpCache::Transaction::DoLoop
I/chromium( 2598): [http_cache_transaction.cc(851)] HttpCache::Transaction::DoLoop 6 STATE_NETWORK_READ
I/chromium( 2598): [http_cache_transaction.cc(1271)] HttpCache::Transaction::DoNetworkRead()
I/chromium( 2598): [http_network_transaction.cc(704)] HttpNetworkTransaction::DoLoop STATE_READ_BODY
I/chromium( 2598): [http_network_transaction.cc(711)] HttpNetworkTransaction::DoLoop STATE_READ_BODY_COMPLETE
I/chromium( 2598): [http_cache_transaction.cc(856)] HttpCache::Transaction::DoLoop 7 STATE_NETWORK_READ_COMPLETE
I/chromium( 2598): [http_cache_transaction.cc(997)]  HttpCache::Transaction::DoLoop 38 STATE_CACHE_WRITE_DATA
I/chromium( 2598): [http_cache_transaction.cc(1001)] HttpCache::Transaction::DoLoop 39 STATE_CACHE_WRITE_DATA_COMPLETE
I/chromium( 2598): [http_cache_transaction.cc(1878)] HttpCache::Transaction::DoCacheWriteDataComplete
I/chromium( 2598): [http_cache_transaction.cc(1902)] HttpCache::Transaction::DoCacheWriteDataComplete result is 0
I/chromium( 2598): [http_cache_transaction.cc(1918)] HttpCache::Transaction::DoCacheWriteDataComplete 3
I/chromium( 2598): [http_cache_transaction.cc(2695)] HttpCache::Transaction::DoneWritingToEntry
I/chromium( 2598): [http_cache.cc(890)] HttpCache::DoneWritingToEntry
I/chromium( 2598): [http_cache_transaction.cc(2695)] HttpCache::Transaction::DoneWritingToEntry
I/chromium( 2598): [url_request_job.cc(718)] URLRequestJob::ReadRawDataHelper and OnRawReadComplete
I/chromium( 2598): [url_request_job.cc(732)] URLRequestJob::OnRawReadComplete  bytes_read is 0
I/chromium( 2598): [resource_loader.cc(579)] ResourceLoader::StartReading 1
I/chromium( 2598): [resource_loader.cc(356)] ResourceLoader::OnReadCompleted bytes_read is 0
I/chromium( 2598): [resource_loader.cc(636)] ResourceLoader::CompleteRead
I/chromium( 2598): [buffered_resource_handler.cc(172)] BufferedResourceHandler::OnReadCompleted
I/chromium( 2598): [buffered_resource_handler.cc(174)] BufferedResourceHandler::OnReadCompleted 1
I/chromium( 2598): [async_resource_handler.cc(254)]  AsyncResourceHandler::OnReadCompleted and bytes_read is 0
I/chromium( 2598): [url_request_job.cc(53)] URLRequestJob::Kill() and job is 0x00498848


19. 此时主资源的加载到此结束。

     再来看看thirdparty/WebKit下的文件DocumentLoader.cpp中方法:

 DocumentLoader::startLoadingMainResource()

   我们之前分析的都是:该方法中的代码:

    m_mainResource = m_fetcher->fetchMainResource(cachedResourceRequest, m_substituteData);

   该方法中,之后有代码:m_mainResource->addClient(this);

20. 上代码执行的是文件Resource.cpp中方法:Resource::addClient

21. 上方法会调用同文件中方法:Resource::didAddClient

22. 上方法会调用DocumentLoader.cpp中方法:DocumentLoader::notifyFinished

23. 上方法会调用同文件中方法:DocumentLoader::finishedLoading

        该方法会调用同文件中方法:DocumentLoader::commitIfReady()

24. 上面方法会调用文件FrameLoader.cpp中方法:FrameLoader::commitProvisionalLoad()

      这里会进行DoucumentLoader对象的第二次的状态转换:

     m_documentLoader = m_provisionalDocumentLoader.release();


    到此为止,Blink内核对主资源的加载就此结束。

   

chromium网络资源加载分析(三) 主资源加载逻辑分析 之body部分加载---chromium39

标签:chromium   blink   主资源加载   网页body部分加载   

原文地址:http://blog.csdn.net/u011882998/article/details/43022777

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!