Page Speed Optimization Libraries  1.2.24.1
net/instaweb/rewriter/public/data_url_input_resource.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 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 
00022 
00023 #include "base/logging.h"
00024 #include "net/instaweb/rewriter/public/resource.h"
00025 #include "net/instaweb/rewriter/public/server_context.h"
00026 #include "net/instaweb/util/public/basictypes.h"
00027 #include "net/instaweb/util/public/data_url.h"
00028 #include "net/instaweb/util/public/scoped_ptr.h"
00029 #include "net/instaweb/util/public/string.h"
00030 #include "net/instaweb/util/public/string_util.h"
00031 
00032 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
00033 #define NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
00034 
00035 namespace net_instaweb {
00036 
00037 class ContentType;
00038 class InputInfo;
00039 class MessageHandler;
00040 class RewriteOptions;
00041 enum Encoding;
00042 
00043 class DataUrlInputResource : public Resource {
00044  public:
00046   static ResourcePtr Make(const StringPiece& url,
00047                           ServerContext* resource_manager) {
00048     ResourcePtr resource;
00049     const ContentType* type;
00050     Encoding encoding;
00051     StringPiece encoded_contents;
00055     GoogleString* url_copy = new GoogleString();
00056     url.CopyToString(url_copy);
00057     if (ParseDataUrl(*url_copy, &type, &encoding, &encoded_contents)) {
00058       resource.reset(new DataUrlInputResource(url_copy, encoding, type,
00059                                               encoded_contents,
00060                                               resource_manager));
00061     }
00062     return resource;
00063   }
00064 
00065   virtual ~DataUrlInputResource();
00066 
00067   virtual bool IsValidAndCacheable() const;
00068 
00070   virtual void FillInPartitionInputInfo(HashHint include_content_hash,
00071                                         InputInfo* input);
00072 
00073   virtual GoogleString url() const { return *url_.get(); }
00074   virtual const RewriteOptions* rewrite_options() const {
00075     LOG(DFATAL) << "Unexpected call to DataUrlInputResource::rewrite_options()";
00076     return NULL;
00077   }
00078 
00079  protected:
00080   virtual bool Load(MessageHandler* message_handler);
00081   virtual bool IsCacheable() const;
00082 
00083  private:
00084   DataUrlInputResource(const GoogleString* url,
00085                        Encoding encoding,
00086                        const ContentType* type,
00087                        const StringPiece& encoded_contents,
00088                        ServerContext* server_context)
00089       : Resource(server_context, type),
00090         url_(url),
00091         encoding_(encoding),
00092         encoded_contents_(encoded_contents) {
00094     Load(server_context->message_handler());
00095   }
00096 
00097   scoped_ptr<const GoogleString> url_;
00098   const Encoding encoding_;
00099   const StringPiece encoded_contents_; 
00100   GoogleString decoded_contents_;
00101 
00102   DISALLOW_COPY_AND_ASSIGN(DataUrlInputResource);
00103 };
00104 
00105 }  
00106 
00107 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines