xpcom/ds/TimeStamp.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /*
     8  * Implementation of the OS-independent methods of the TimeStamp class
     9  */
    11 #include "mozilla/TimeStamp.h"
    12 #include "prenv.h"
    14 namespace mozilla {
    16 /**
    17  * Wrapper class used to initialize static data used by the TimeStamp class
    18  */
    19 struct TimeStampInitialization {
    20   /**
    21    * First timestamp taken when the class static initializers are run. This
    22    * timestamp is used to sanitize timestamps coming from different sources.
    23    */
    24   TimeStamp mFirstTimeStamp;
    26   /**
    27    * Timestamp representing the time when the process was created. This field
    28    * is populated lazily the first time this information is required and is
    29    * replaced every time the process is restarted.
    30    */
    31   TimeStamp mProcessCreation;
    33   TimeStampInitialization() {
    34     TimeStamp::Startup();
    35     mFirstTimeStamp = TimeStamp::Now();
    36   };
    38   ~TimeStampInitialization() {
    39     TimeStamp::Shutdown();
    40   };
    41 };
    43 static TimeStampInitialization sInitOnce;
    45 TimeStamp
    46 TimeStamp::ProcessCreation(bool& aIsInconsistent)
    47 {
    48   aIsInconsistent = false;
    50   if (sInitOnce.mProcessCreation.IsNull()) {
    51     char *mozAppRestart = PR_GetEnv("MOZ_APP_RESTART");
    52     TimeStamp ts;
    54     /* When calling PR_SetEnv() with an empty value the existing variable may
    55      * be unset or set to the empty string depending on the underlying platform
    56      * thus we have to check if the variable is present and not empty. */
    57     if (mozAppRestart && (strcmp(mozAppRestart, "") != 0)) {
    58       /* Firefox was restarted, use the first time-stamp we've taken as the new
    59        * process startup time. */
    60       ts = sInitOnce.mFirstTimeStamp;
    61     } else {
    62       TimeStamp now = Now();
    63       uint64_t uptime = ComputeProcessUptime();
    65       ts = now - TimeDuration::FromMicroseconds(uptime);
    67       if ((ts > sInitOnce.mFirstTimeStamp) || (uptime == 0)) {
    68         /* If the process creation timestamp was inconsistent replace it with
    69          * the first one instead and notify that a telemetry error was
    70          * detected. */
    71         aIsInconsistent = true;
    72         ts = sInitOnce.mFirstTimeStamp;
    73       }
    74     }
    76     sInitOnce.mProcessCreation = ts;
    77   }
    79   return sInitOnce.mProcessCreation;
    80 }
    82 void
    83 TimeStamp::RecordProcessRestart()
    84 {
    85   sInitOnce.mProcessCreation = TimeStamp();
    86 }
    88 } // namespace mozilla

mercurial