~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/http/user_agent_normalizer.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
 
// Copyright 2013 Google Inc. All Rights Reserved.
2
 
//
3
 
// Licensed under the Apache License, Version 2.0 (the "License");
4
 
// you may not use this file except in compliance with the License.
5
 
// You may obtain a copy of the License at
6
 
//
7
 
//      http://www.apache.org/licenses/LICENSE-2.0
8
 
//
9
 
// Unless required by applicable law or agreed to in writing, software
10
 
// distributed under the License is distributed on an "AS IS" BASIS,
11
 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 
// See the License for the specific language governing permissions and
13
 
// limitations under the License.
14
 
 
15
 
// Author: morlovich@google.com (Maksim Orlovich)
16
 
 
17
 
#ifndef PAGESPEED_KERNEL_HTTP_USER_AGENT_NORMALIZER_H_
18
 
#define PAGESPEED_KERNEL_HTTP_USER_AGENT_NORMALIZER_H_
19
 
 
20
 
#include <vector>
21
 
 
22
 
#include "pagespeed/kernel/base/basictypes.h"
23
 
#include "pagespeed/kernel/base/string.h"
24
 
#include "pagespeed/kernel/util/re2.h"
25
 
 
26
 
namespace net_instaweb {
27
 
 
28
 
// Base class for user agent string normalizer. The idea is that UA strings,
29
 
// sometimes include irrelevant information, so this provides a way of stripping
30
 
// it, to improve cache hit-rates when the normalized UAs are used in cache
31
 
// keys.
32
 
class UserAgentNormalizer {
33
 
 public:
34
 
  UserAgentNormalizer() {}
35
 
  virtual ~UserAgentNormalizer();
36
 
 
37
 
  virtual GoogleString Normalize(const GoogleString& in) const = 0;
38
 
 
39
 
  // Helper that applies all the normalizers in the ua_normalizers list
40
 
  // to ua_in.
41
 
  static GoogleString NormalizeWithAll(
42
 
      const std::vector<const UserAgentNormalizer*>& ua_normalizers,
43
 
      const GoogleString& ua_in);
44
 
 
45
 
 private:
46
 
  DISALLOW_COPY_AND_ASSIGN(UserAgentNormalizer);
47
 
};
48
 
 
49
 
// This normalizes some common UA strings for Android devices
50
 
// by dropping the device & build names from them.
51
 
class AndroidUserAgentNormalizer : public UserAgentNormalizer {
52
 
 public:
53
 
  AndroidUserAgentNormalizer();
54
 
  virtual ~AndroidUserAgentNormalizer();
55
 
 
56
 
  virtual GoogleString Normalize(const GoogleString& in) const;
57
 
 
58
 
 private:
59
 
  RE2 dalvik_ua_;
60
 
  RE2 chrome_android_ua_;
61
 
  RE2 android_browser_ua_;
62
 
};
63
 
 
64
 
// This normalizes UA strings for MSIE, by dropping the long list of
65
 
// installed extensions (like .NET) it likes to include, and just keeping the
66
 
// important info like browser, OS, and chromeframe version.
67
 
class IEUserAgentNormalizer : public UserAgentNormalizer {
68
 
 public:
69
 
  IEUserAgentNormalizer();
70
 
  virtual ~IEUserAgentNormalizer();
71
 
 
72
 
  virtual GoogleString Normalize(const GoogleString& in) const;
73
 
 
74
 
 private:
75
 
  RE2 ie_ua_;
76
 
};
77
 
 
78
 
}  // namespace net_instaweb
79
 
 
80
 
#endif  // PAGESPEED_KERNEL_HTTP_USER_AGENT_NORMALIZER_H_