Page Speed Optimization Libraries  1.2.24.1
net/instaweb/rewriter/public/collect_subresources_filter.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_COLLECT_SUBRESOURCES_FILTER_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_COLLECT_SUBRESOURCES_FILTER_H_
00021 
00022 #include <map>
00023 
00024 #include "net/instaweb/htmlparse/public/html_element.h"
00025 #include "net/instaweb/rewriter/public/rewrite_filter.h"
00026 #include "net/instaweb/util/public/basictypes.h"
00027 #include "net/instaweb/util/public/gtest_prod.h"
00028 #include "net/instaweb/util/public/scoped_ptr.h"
00029 #include "net/instaweb/util/public/string_util.h"
00030 
00031 namespace net_instaweb {
00032 
00033 class AbstractMutex;
00034 class FlushEarlyInfo;
00035 class FlushEarlyResource;
00036 class PropertyCache;
00037 class RewriteDriver;
00038 
00043 class CollectSubresourcesFilter : public RewriteFilter {
00044  public:
00045   explicit CollectSubresourcesFilter(RewriteDriver* rewrite_driver);
00046   virtual ~CollectSubresourcesFilter();
00047 
00048   virtual void StartDocumentImpl();
00049   virtual void StartElementImpl(HtmlElement* element);
00050   virtual void EndElementImpl(HtmlElement* element);
00051 
00052   virtual const char* Name() const { return "CollectSubresourcesFilter"; }
00053   virtual const char* id() const { return "fs"; }
00054 
00055   void AddSubresourcesToFlushEarlyInfo(FlushEarlyInfo* info);
00056 
00057  private:
00058   typedef std::map<int, FlushEarlyResource*> ResourceMap;
00059 
00061   void CreateSubresourceContext(StringPiece url,
00062                                 HtmlElement* elt,
00063                                 HtmlElement::Attribute* attr);
00065   virtual bool UsesPropertyCacheDomCohort() const { return true; }
00066 
00067   class Context;
00068 
00069   bool in_first_head_;
00070   bool seen_first_head_;
00071   int num_resources_;
00072   scoped_ptr<AbstractMutex> mutex_;
00075   ResourceMap subresources_;
00076   PropertyCache* property_cache_;
00077 
00078   FRIEND_TEST(CollectSubresourcesFilterTest, CollectSubresourcesFilter);
00079   FRIEND_TEST(CollectSubresourcesFilterTest, HtmlHasRewrittenUrl);
00080 
00081   DISALLOW_COPY_AND_ASSIGN(CollectSubresourcesFilter);
00082 };
00083 
00084 }  
00085 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_COLLECT_SUBRESOURCES_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines