diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 16:09:43 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 16:09:43 +0000 |
commit | 90ca36995f2484d10a68115b798c10f51d70fca4 (patch) | |
tree | d69bfe14150a811ae5260b95127ab5c3a28f005a /webkit/glue/devtools | |
parent | c38aeeeb04c53a4d1c53673ec5575562d3bfe313 (diff) | |
download | chromium_src-90ca36995f2484d10a68115b798c10f51d70fca4.zip chromium_src-90ca36995f2484d10a68115b798c10f51d70fca4.tar.gz chromium_src-90ca36995f2484d10a68115b798c10f51d70fca4.tar.bz2 |
DevTools: Cache resources before attach, hide agents behind the flag.
Review URL: http://codereview.chromium.org/65010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13423 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/devtools')
-rw-r--r-- | webkit/glue/devtools/js/net_agent.js | 19 | ||||
-rw-r--r-- | webkit/glue/devtools/net_agent.h | 3 | ||||
-rw-r--r-- | webkit/glue/devtools/net_agent_impl.cc | 84 | ||||
-rw-r--r-- | webkit/glue/devtools/net_agent_impl.h | 23 |
4 files changed, 79 insertions, 50 deletions
diff --git a/webkit/glue/devtools/js/net_agent.js b/webkit/glue/devtools/js/net_agent.js index 00b511c..64ef4a6 100644 --- a/webkit/glue/devtools/js/net_agent.js +++ b/webkit/glue/devtools/js/net_agent.js @@ -21,8 +21,6 @@ devtools.NetAgent = function() { goog.bind(this.didReceiveResponse, this); RemoteNetAgent.DidFinishLoading = goog.bind(this.didFinishLoading, this); - RemoteNetAgent.DidFailLoading = - goog.bind(this.didFailLoading, this); }; @@ -138,20 +136,5 @@ devtools.NetAgent.prototype.didFinishLoading = function(identifier, value) { } resource.endTime = value.endTime; resource.finished = true; - resource.failed = false; -}; - - -/** - * @see NetAgentDelegate. - * {@inheritDoc}. - */ -devtools.NetAgent.prototype.didFailLoading = function(identifier, value) { - var resource = this.resources_[identifier]; - if (!resource) { - return; - } - resource.endTime = value.endTime; - resource.finished = false; - resource.failed = true; + resource.failed = !!value.errorCode; }; diff --git a/webkit/glue/devtools/net_agent.h b/webkit/glue/devtools/net_agent.h index 87459f0..38db57d 100644 --- a/webkit/glue/devtools/net_agent.h +++ b/webkit/glue/devtools/net_agent.h @@ -31,9 +31,6 @@ DEFINE_RPC_CLASS(NetAgent, NET_AGENT_STRUCT) errors */ \ METHOD2(DidFinishLoading, int /* identifier */, Value /* response */) \ \ - /* Notifies the delegate that resource loading has failed. */ \ - METHOD2(DidFailLoading, int /* identifier */, Value /* response */) \ - \ /* Response to the async call. */ \ METHOD2(GetResourceContentResult, int /* call_id */, std::string /* content */) diff --git a/webkit/glue/devtools/net_agent_impl.cc b/webkit/glue/devtools/net_agent_impl.cc index a34667f..5aba9bb 100644 --- a/webkit/glue/devtools/net_agent_impl.cc +++ b/webkit/glue/devtools/net_agent_impl.cc @@ -33,28 +33,47 @@ using namespace WebCore; NetAgentImpl::NetAgentImpl(NetAgentDelegate* delegate) : delegate_(delegate), document_(NULL), - last_cached_identifier_(-2) { + main_loader_(NULL), + last_cached_identifier_(-2), + attached_(false) { } NetAgentImpl::~NetAgentImpl() { SetDocument(NULL); - for (CachedResources::iterator it = pending_resources_.begin(); - it != pending_resources_.end(); ++it) { - delete it->second; - } + DidCommitMainResourceLoad(); + deleteAllValues(pending_resources_); pending_resources_.clear(); } void NetAgentImpl::SetDocument(Document* doc) { -// loaders_.clear(); document_ = doc; } +void NetAgentImpl::Attach() { + for (FinishedResources::iterator it = finished_resources_.begin(); + it != finished_resources_.end(); ++it) { + delegate_->DidFinishLoading(it->first, *it->second); + } + attached_ = true; +} + +void NetAgentImpl::Detach() { + attached_ = false; +} + +void NetAgentImpl::DidCommitMainResourceLoad() { + for (FinishedResources::iterator it = finished_resources_.begin(); + it != finished_resources_.end(); ++it) { + delete it->second; + } + finished_resources_.clear(); + main_loader_ = NULL; +} + void NetAgentImpl::AssignIdentifierToRequest( DocumentLoader* loader, int identifier, const ResourceRequest& request) { - loaders_.set(identifier, loader); } void NetAgentImpl::WillSendRequest( @@ -72,18 +91,22 @@ void NetAgentImpl::WillSendRequest( webkit_glue::StringToStdString(url.lastPathComponent())); resource->Set(L"requestHeaders", BuildValueForHeaders(request.httpHeaderFields())); - delegate_->WillSendRequest(identifier, *resource); pending_resources_.set(identifier, resource); + + if (attached_) { + delegate_->WillSendRequest(identifier, *resource); + } } void NetAgentImpl::DidReceiveResponse( DocumentLoader* loader, int identifier, const ResourceResponse &response) { - KURL url = response.url(); if (!pending_resources_.contains(identifier)) { return; } + + KURL url = response.url(); DictionaryValue* resource = pending_resources_.get(identifier); resource->SetReal(L"responseReceivedTime", WTF::currentTime()); resource->SetString(L"url", @@ -98,7 +121,9 @@ void NetAgentImpl::DidReceiveResponse( resource->Set(L"responseHeaders", BuildValueForHeaders(response.httpHeaderFields())); - delegate_->DidReceiveResponse(identifier, *resource); + if (attached_) { + delegate_->DidReceiveResponse(identifier, *resource); + } } void NetAgentImpl::DidReceiveContentLength( @@ -113,11 +138,31 @@ void NetAgentImpl::DidFinishLoading( if (!pending_resources_.contains(identifier)) { return; } + + // This is the first command being dispatched after + // DidCommitMainResourceLoad, we know that the first resource to be reported + // as loaded is main resource. + if (!main_loader_.get()) { + main_loader_ = loader; + } + DictionaryValue* resource = pending_resources_.get(identifier); resource->SetReal(L"endTime", WTF::currentTime()); - delegate_->DidFinishLoading(identifier, *resource); + pending_resources_.remove(identifier); - delete resource; + finished_resources_.append(std::make_pair(identifier, resource)); + + // Start removing resources from the cache once there are too many of them. + if (finished_resources_.size() > 200) { + for (int i = 0; i < 50; ++i) { + delete finished_resources_[i].second; + } + finished_resources_.remove(0, 50); + } + + if (attached_) { + delegate_->DidFinishLoading(identifier, *resource); + } } void NetAgentImpl::DidFailLoading( @@ -128,13 +173,10 @@ void NetAgentImpl::DidFailLoading( return; } DictionaryValue* resource = pending_resources_.get(identifier); - resource->SetReal(L"endTime", WTF::currentTime()); resource->SetInteger(L"errorCode", error.errorCode()); resource->SetString(L"localizedDescription", webkit_glue::StringToStdString(error.localizedDescription())); - delegate_->DidFailLoading(identifier, *resource); - pending_resources_.remove(identifier); - delete resource; + DidFinishLoading(loader, identifier); } void NetAgentImpl::DidLoadResourceFromMemoryCache( @@ -143,7 +185,6 @@ void NetAgentImpl::DidLoadResourceFromMemoryCache( const ResourceResponse& response, int length) { int identifier = last_cached_identifier_--; - loaders_.set(identifier, loader); } void NetAgentImpl::GetResourceContent( @@ -153,16 +194,11 @@ void NetAgentImpl::GetResourceContent( if (!document_) { return; } - CachedLoaders::iterator it = loaders_.find(identifier); - if (it == loaders_.end() || !it->second) { - return; - } - RefPtr<DocumentLoader> loader = it->second; String source; - if (url == loader->requestURL()) { - RefPtr<SharedBuffer> buffer = loader->mainResourceData(); + if (main_loader_.get() && main_loader_->requestURL() == url) { + RefPtr<SharedBuffer> buffer = main_loader_->mainResourceData(); String text_encoding_name = document_->inputEncoding(); if (buffer) { WebCore::TextEncoding encoding(text_encoding_name); diff --git a/webkit/glue/devtools/net_agent_impl.h b/webkit/glue/devtools/net_agent_impl.h index 94f5e20..893c4b5 100644 --- a/webkit/glue/devtools/net_agent_impl.h +++ b/webkit/glue/devtools/net_agent_impl.h @@ -5,9 +5,12 @@ #ifndef WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_ #define WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_ +#include <utility> + #include <wtf/HashMap.h> #include <wtf/RefCounted.h> #include <wtf/RefPtr.h> +#include <wtf/Vector.h> #include "webkit/glue/devtools/net_agent.h" @@ -35,6 +38,15 @@ class NetAgentImpl : public NetAgent { // Initializes net agent with the given document. void SetDocument(WebCore::Document* document); + // Tells agent it has attached client. + void Attach(); + + // Tells agent it has no attached client. + void Detach(); + + // Tells agent that new load has been committed. + void DidCommitMainResourceLoad(); + // NetAgent implementation. void GetResourceContent(int call_id, int identifier, const WebCore::String& request_url); @@ -73,13 +85,14 @@ class NetAgentImpl : public NetAgent { NetAgentDelegate* delegate_; WebCore::Document* document_; + RefPtr<WebCore::DocumentLoader> main_loader_; typedef HashMap<int, DictionaryValue*, DefaultHash<int>::Hash, - WTF::UnsignedWithZeroKeyHashTraits<int> > CachedResources; - typedef HashMap<int, RefPtr<WebCore::DocumentLoader>, DefaultHash<int>::Hash, - WTF::UnsignedWithZeroKeyHashTraits<int> > CachedLoaders; - CachedResources pending_resources_; - CachedLoaders loaders_; + WTF::UnsignedWithZeroKeyHashTraits<int> > ResourcesMap; + typedef Vector<std::pair<int, DictionaryValue*> > FinishedResources; + ResourcesMap pending_resources_; + FinishedResources finished_resources_; int last_cached_identifier_; + bool attached_; DISALLOW_COPY_AND_ASSIGN(NetAgentImpl); }; |