~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/css_url_counter.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2012 Google Inc.
3
 
 *
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
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
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.
15
 
 */
16
 
 
17
 
// Author: sligocki@google.com (Shawn Ligocki)
18
 
 
19
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_URL_COUNTER_H_
20
 
#define NET_INSTAWEB_REWRITER_PUBLIC_CSS_URL_COUNTER_H_
21
 
 
22
 
#include "net/instaweb/rewriter/public/css_tag_scanner.h"
23
 
#include "net/instaweb/util/public/basictypes.h"
24
 
#include "net/instaweb/util/public/string.h"
25
 
#include "net/instaweb/util/public/string_util.h"
26
 
 
27
 
namespace net_instaweb {
28
 
 
29
 
class GoogleUrl;
30
 
class MessageHandler;
31
 
 
32
 
// "Transformer" that records the URLs it sees (with counts) instead of
33
 
// applying any transformation.
34
 
class CssUrlCounter : public CssTagScanner::Transformer {
35
 
 public:
36
 
  // base_url and handler must live longer than CssUrlCounter.
37
 
  CssUrlCounter(const GoogleUrl* base_url, MessageHandler* handler)
38
 
      : base_url_(base_url), handler_(handler) {}
39
 
  virtual ~CssUrlCounter();
40
 
 
41
 
  // Record and count URLs in in_text. Does not reset url_counts_, so if you
42
 
  // call this multiple times it will accumulate url_counts_ over all inputs.
43
 
  // Returns False if CssUrlCounter found unparseable URLs.
44
 
  bool Count(const StringPiece& in_text);
45
 
 
46
 
  // Access URL occurrence counts after you've scanned a CSS file.
47
 
  const StringIntMap& url_counts() const { return url_counts_; }
48
 
 
49
 
 private:
50
 
  // CssTagScanner::Transform interface. Called indirectly by Count().
51
 
  virtual TransformStatus Transform(GoogleString* str);
52
 
 
53
 
  // Counts for how many times each URL was found in the CSS file.
54
 
  StringIntMap url_counts_;
55
 
 
56
 
  // Base URL for CSS file, needed to absolutify URLs in Transform.
57
 
  const GoogleUrl* base_url_;
58
 
 
59
 
  MessageHandler* handler_;
60
 
 
61
 
  DISALLOW_COPY_AND_ASSIGN(CssUrlCounter);
62
 
};
63
 
 
64
 
}  // namespace net_instaweb
65
 
 
66
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_CSS_URL_COUNTER_H_