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