Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
data_url_input_resource.h
Go to the documentation of this file.
1 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
2 #define NET_INSTAWEB_REWRITER_PUBLIC_DATA_URL_INPUT_RESOURCE_H_
3 
4 /*
5  * Copyright 2010 Google Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http:///www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
25 
26 #include "net/instaweb/http/public/request_context.h"
28 #include "pagespeed/kernel/base/basictypes.h"
29 #include "pagespeed/kernel/base/scoped_ptr.h"
30 #include "pagespeed/kernel/base/string.h"
31 #include "pagespeed/kernel/base/string_util.h"
32 #include "pagespeed/kernel/http/data_url.h"
33 
34 namespace net_instaweb {
35 
36 class InputInfo;
37 class RewriteDriver;
38 struct ContentType;
39 
40 enum Encoding;
41 
43  public:
45  static ResourcePtr Make(const StringPiece& url, const RewriteDriver* driver) {
46  ResourcePtr resource;
47  const ContentType* type;
48  Encoding encoding;
49  StringPiece encoded_contents;
53  GoogleString* url_copy = new GoogleString();
54  url.CopyToString(url_copy);
55  if (ParseDataUrl(*url_copy, &type, &encoding, &encoded_contents)) {
56  resource.reset(new DataUrlInputResource(url_copy, encoding, type,
57  encoded_contents, driver));
58  }
59  return resource;
60  }
61 
62  virtual ~DataUrlInputResource();
63 
64  virtual bool IsValidAndCacheable() const;
65 
67  virtual void FillInPartitionInputInfo(HashHint include_content_hash,
68  InputInfo* input);
69 
70  virtual GoogleString url() const { return *url_.get(); }
71 
72  virtual bool UseHttpCache() const { return false; }
73 
74  protected:
75  virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy,
76  const RequestContextPtr& request_context,
77  AsyncCallback* callback);
78 
79  private:
80  DataUrlInputResource(const GoogleString* url,
81  Encoding encoding,
82  const ContentType* type,
83  const StringPiece& encoded_contents,
84  const RewriteDriver* driver);
85 
86  scoped_ptr<const GoogleString> url_;
87  const Encoding encoding_;
88  const StringPiece encoded_contents_;
89  GoogleString decoded_contents_;
90 
91  DISALLOW_COPY_AND_ASSIGN(DataUrlInputResource);
92 };
93 
94 }
95 
96 #endif
virtual GoogleString url() const
Gets the absolute URL of the resource.
Definition: data_url_input_resource.h:70
Definition: data_url_input_resource.h:42
Definition: resource.h:56
NotCacheablePolicy
Definition: resource.h:67
static ResourcePtr Make(const StringPiece &url, const RewriteDriver *driver)
We expose a factory; parse failure returns NULL.
Definition: data_url_input_resource.h:45
Definition: rewrite_driver.h:98
virtual bool UseHttpCache() const
Definition: data_url_input_resource.h:72
virtual void FillInPartitionInputInfo(HashHint include_content_hash, InputInfo *input)
Set OutputPartition's input info used for expiration validation.
virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy, const RequestContextPtr &request_context, AsyncCallback *callback)
virtual bool IsValidAndCacheable() const