2
* Copyright 2013 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: slamm@google.com (Stephen Lamm)
19
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_CSS_FINDER_H_
20
#define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_CSS_FINDER_H_
22
#include "net/instaweb/util/public/basictypes.h"
23
#include "net/instaweb/util/public/property_cache.h"
25
namespace net_instaweb {
27
class CriticalCssResult;
32
// Finds critical CSS rules (i.e. CSS needed for the initial page load).
33
class CriticalCssFinder {
35
static const char kCriticalCssValidCount[];
36
static const char kCriticalCssExpiredCount[];
37
static const char kCriticalCssNotFoundCount[];
38
static const char kCriticalCssPropertyName[];
40
CriticalCssFinder(const PropertyCache::Cohort* cohort, Statistics* stats);
41
virtual ~CriticalCssFinder();
43
static void InitStats(Statistics* statistics);
45
// Get critical css result from property cache.
46
// Ownership of the result is passed to the caller.
47
virtual CriticalCssResult* GetCriticalCssFromCache(RewriteDriver* driver);
49
// Compute the critical css for the driver's url.
50
virtual void ComputeCriticalCss(RewriteDriver* driver) = 0;
52
// Copy |critical_css_map| into property cache. Returns true on success.
53
virtual bool UpdateCache(RewriteDriver* driver,
54
const CriticalCssResult& result);
56
// Collects the critical CSS rules from the property cache and updates the
57
// same in the rewrite driver. The ownership of the ruleset stays with the
59
virtual void UpdateCriticalCssInfoInDriver(RewriteDriver* driver);
61
// Gets the critical CSS rules from the driver if they are present. Otherwise
62
// calls UpdateCriticalCssInfoInDriver() to populate the ruleset in the driver
63
// and returns the rules. The ownership of the CriticalCssResult is not
64
// released and it stays with the driver.
65
virtual CriticalCssResult* GetCriticalCss(RewriteDriver* driver);
67
const PropertyCache::Cohort* cohort() const { return cohort_; }
70
const PropertyCache::Cohort* cohort_;
71
TimedVariable* critical_css_valid_count_;
72
TimedVariable* critical_css_expired_count_;
73
TimedVariable* critical_css_not_found_count_;
75
DISALLOW_COPY_AND_ASSIGN(CriticalCssFinder);
78
} // namespace net_instaweb
80
#endif // NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_CSS_FINDER_H_