1
// Copyright 2013 Google Inc. All Rights Reserved.
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
7
// http://www.apache.org/licenses/LICENSE-2.0
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.
15
// Author: morlovich@google.com (Maksim Orlovich)
17
#ifndef PAGESPEED_KERNEL_HTTP_USER_AGENT_NORMALIZER_H_
18
#define PAGESPEED_KERNEL_HTTP_USER_AGENT_NORMALIZER_H_
22
#include "pagespeed/kernel/base/basictypes.h"
23
#include "pagespeed/kernel/base/string.h"
24
#include "pagespeed/kernel/util/re2.h"
26
namespace net_instaweb {
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
32
class UserAgentNormalizer {
34
UserAgentNormalizer() {}
35
virtual ~UserAgentNormalizer();
37
virtual GoogleString Normalize(const GoogleString& in) const = 0;
39
// Helper that applies all the normalizers in the ua_normalizers list
41
static GoogleString NormalizeWithAll(
42
const std::vector<const UserAgentNormalizer*>& ua_normalizers,
43
const GoogleString& ua_in);
46
DISALLOW_COPY_AND_ASSIGN(UserAgentNormalizer);
49
// This normalizes some common UA strings for Android devices
50
// by dropping the device & build names from them.
51
class AndroidUserAgentNormalizer : public UserAgentNormalizer {
53
AndroidUserAgentNormalizer();
54
virtual ~AndroidUserAgentNormalizer();
56
virtual GoogleString Normalize(const GoogleString& in) const;
60
RE2 chrome_android_ua_;
61
RE2 android_browser_ua_;
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 {
69
IEUserAgentNormalizer();
70
virtual ~IEUserAgentNormalizer();
72
virtual GoogleString Normalize(const GoogleString& in) const;
78
} // namespace net_instaweb
80
#endif // PAGESPEED_KERNEL_HTTP_USER_AGENT_NORMALIZER_H_