2
* Copyright 2011 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: jmarantz@google.com (Joshua Marantz)
19
#ifndef NET_INSTAWEB_AUTOMATIC_PUBLIC_STATIC_REWRITER_H_
20
#define NET_INSTAWEB_AUTOMATIC_PUBLIC_STATIC_REWRITER_H_
22
#include "net/instaweb/rewriter/public/rewrite_driver_factory.h"
23
#include "net/instaweb/rewriter/public/rewrite_gflags.h"
24
#include "net/instaweb/util/public/basictypes.h"
25
#include "net/instaweb/util/public/simple_stats.h"
26
#include "net/instaweb/util/public/string_util.h"
28
namespace net_instaweb {
36
class UrlAsyncFetcher;
39
// Implements a baseline RewriteDriverFactory with the simplest possible
40
// options for cache, fetchers, & system interface.
42
// TODO(jmarantz): fill out enough functionality so that this will be
43
// a functional static rewriter that could optimize an HTML file
44
// passed as a command-line parameter or via stdin.
45
class FileRewriter : public RewriteDriverFactory {
47
FileRewriter(const ProcessContext& process_context,
48
const RewriteGflags* gflags,
49
bool echo_errors_to_stdout);
50
virtual ~FileRewriter();
51
virtual Hasher* NewHasher();
52
virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
53
virtual MessageHandler* DefaultHtmlParseMessageHandler();
54
virtual MessageHandler* DefaultMessageHandler();
55
virtual FileSystem* DefaultFileSystem();
56
virtual void SetupCaches(ServerContext* server_context);
57
virtual Statistics* statistics();
58
virtual ServerContext* NewServerContext();
59
virtual ServerContext* NewDecodingServerContext();
60
virtual bool UseBeaconResultsInFilters() const { return false; }
63
const RewriteGflags* gflags_;
64
SimpleStats simple_stats_;
65
bool echo_errors_to_stdout_;
67
DISALLOW_COPY_AND_ASSIGN(FileRewriter);
70
// Encapsulates the instantiation of a FileRewriter & a simple one-shot
71
// interface to rewrite some HTML text.
72
class StaticRewriter {
74
StaticRewriter(const ProcessContext& process_context,
75
int* argc, char*** argv);
76
explicit StaticRewriter(const ProcessContext& process_context);
79
bool ParseText(const StringPiece& text,
80
const StringPiece& url,
81
const StringPiece& id,
82
const StringPiece& output_dir,
85
FileSystem* file_system();
86
MessageHandler* message_handler();
89
RewriteGflags gflags_;
90
FileRewriter file_rewriter_;
91
ServerContext* server_context_;
93
DISALLOW_COPY_AND_ASSIGN(StaticRewriter);
96
} // namespace net_instaweb
98
#endif // NET_INSTAWEB_AUTOMATIC_PUBLIC_STATIC_REWRITER_H_