コード例 #1
0
  /*
   * Takes the initial client cookie value, if any (null otherwise), as well
   * as the page load timestamp and creates initial states.
   */
  protected void initCookieStates(String plainCookieId, String etagCookieId) {
    CookieStates states = getCookieStates();
    CookieState plainState;
    ZombieCookie cookie = null;

    if (plainCookieId == null) {
      // may be overridden to UNSUPPORTED after javascript info received
      plainState = NEW;
    } else if ((cookie = lookupZombieCookie(plainCookieId)) != null) {
      if (cookie.hasParent()) {
        cookie = cookie.oldestRelative();
        plainState = REPLACED_BY_OLDER_PLAIN_COOKIE;
      } else {
        plainState = EXISTING;
      }
    } else {
      plainState = RESET;
    }

    if (cookie == null) {
      cookie = createZombieCookie();
    }

    setAndSaveZombieCookie(cookie);
    states.setPlainState(plainState);
    updateCookieStates(ETAG, etagCookieId);
  }
コード例 #2
0
  private void setStatesAndBindCookies(CookieType candidateType, ZombieCookie candidateCookie) {
    CookieStates states = getCookieStates();
    ZombieCookie currentCookie = getZombieCookie();

    if (currentCookie.hasParent()) {
      //  The current selected zombie cookie, in theory, could have a
      //  new parent inserted from a seperate simultaneous page load
      //  in a different HTTP session.  We don't have a seperate state
      //  name for this, but in practice we never see it either.
      currentCookie = currentCookie.oldestRelative();
      log.error("found unexpected parent cookie={}", currentCookie.getId());
    }

    boolean usingCandidateParent = false;
    if (candidateCookie.hasParent()) {
      usingCandidateParent = true;
      candidateCookie = candidateCookie.oldestRelative();
    }

    if (candidateCookie.isOlder(currentCookie)) {
      states.set(
          candidateType, usingCandidateParent ? replacedFromOlderState(candidateType) : EXISTING);
      cascadeNewBestCookie(candidateType);
    } else {
      // Pick a replacementent state for the candidate cookie
      setHowCookieWasReplaced(candidateType);
    }

    // If the incomming candidate cookie had a parent equal to the current
    // cookie, we don't have to set a new value.
    if (!currentCookie.getId().equals(candidateCookie.getId())) {
      setAndSaveZombieCookie(currentCookie.linkTo(candidateCookie));
    }
  }