LCOV - code coverage report
Current view: top level - httpd - H2CacheBasedWebSession.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 13 13 100.0 %
Date: 2022-11-19 15:00:39 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2009 The Android Open Source Project
       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             : package com.google.gerrit.httpd;
      16             : 
      17             : import com.google.common.cache.Cache;
      18             : import com.google.gerrit.common.Nullable;
      19             : import com.google.gerrit.extensions.registration.DynamicItem;
      20             : import com.google.gerrit.httpd.WebSessionManager.Val;
      21             : import com.google.gerrit.server.AnonymousUser;
      22             : import com.google.gerrit.server.IdentifiedUser.RequestFactory;
      23             : import com.google.gerrit.server.account.AccountCache;
      24             : import com.google.gerrit.server.cache.CacheModule;
      25             : import com.google.gerrit.server.config.AuthConfig;
      26             : import com.google.inject.Inject;
      27             : import com.google.inject.Module;
      28             : import com.google.inject.Provider;
      29             : import com.google.inject.assistedinject.FactoryModuleBuilder;
      30             : import com.google.inject.name.Named;
      31             : import com.google.inject.servlet.RequestScoped;
      32             : import java.time.Duration;
      33             : import javax.servlet.http.HttpServletRequest;
      34             : import javax.servlet.http.HttpServletResponse;
      35             : 
      36             : @RequestScoped
      37             : public class H2CacheBasedWebSession extends CacheBasedWebSession {
      38             :   public static Module module() {
      39          99 :     return new CacheModule() {
      40             :       @Override
      41             :       protected void configure() {
      42          99 :         persist(WebSessionManager.CACHE_NAME, String.class, Val.class)
      43          99 :             .maximumWeight(1024) // reasonable default for many sites
      44             :             // expire sessions if they are inactive
      45          99 :             .expireAfterWrite(Duration.ofMinutes(CacheBasedWebSession.MAX_AGE_MINUTES));
      46          99 :         install(new FactoryModuleBuilder().build(WebSessionManagerFactory.class));
      47          99 :         DynamicItem.itemOf(binder(), WebSession.class);
      48          99 :         DynamicItem.bind(binder(), WebSession.class)
      49          99 :             .to(H2CacheBasedWebSession.class)
      50          99 :             .in(RequestScoped.class);
      51          99 :       }
      52             :     };
      53             :   }
      54             : 
      55             :   @Inject
      56             :   H2CacheBasedWebSession(
      57             :       HttpServletRequest request,
      58             :       @Nullable HttpServletResponse response,
      59             :       WebSessionManagerFactory managerFactory,
      60             :       @Named(WebSessionManager.CACHE_NAME) Cache<String, Val> cache,
      61             :       AuthConfig authConfig,
      62             :       Provider<AnonymousUser> anonymousProvider,
      63             :       RequestFactory identified,
      64             :       AccountCache byIdCache) {
      65          38 :     super(
      66             :         request,
      67             :         response,
      68          38 :         managerFactory.create(cache),
      69             :         authConfig,
      70             :         anonymousProvider,
      71             :         identified,
      72             :         byIdCache);
      73          38 :   }
      74             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750