Skip to content

Commit

Permalink
Switch to storageManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Abimael Martinez committed Jun 11, 2020
1 parent 918e9f4 commit 187e09c
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions modules/nextrollIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

import {submodule} from '../src/hook';
import * as utils from '../src/utils'
import * as utils from '../src/utils';
import { getStorageManager } from '../src/storageManager.js';
const storage = getStorageManager();

const NEXTROLL_ID_LS_KEY = "nextroll_id_ls_key";
const NEXTROLL_ID_TEST_KEY = NEXTROLL_ID_LS_KEY + "_test";
Expand Down Expand Up @@ -38,28 +40,17 @@ function isValidUA() {
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1))
}

function hasLocalStorage() {
const test_key = NEXTROLL_ID_TEST_KEY;
try {
localStorage.setItem(test_key, test_key);
localStorage.removeItem(test_key);
return true;
} catch(e) {
return false;
}
}

function removeAttemptTimestamp() {
if (hasLocalStorage()) {
localStorage.removeItem(NEXTROLL_ID_DATE_KEY);
if (storage.hasLocalStorage()) {
storage.removeDataFromLocalStorage(NEXTROLL_ID_DATE_KEY);
}
}

// Sets unsuccesful attempt timestamp
// Note: assumes window has localstorage enabled.
function setAttemptTimestamp() {
const date = (new Date()).getTime();
localStorage.setItem(NEXTROLL_ID_DATE_KEY, date);
storage.setDataInLocalStorage(NEXTROLL_ID_DATE_KEY, date);
}

function getXIDCallback(cb) {
Expand All @@ -70,7 +61,7 @@ function getXIDCallback(cb) {
return;
}
// No valid id, and no localstorage
if (!hasLocalStorage()) {
if (!storage.hasLocalStorage()) {
cb(DEFAULT_MISSING_VALUE);
return;
}
Expand All @@ -86,12 +77,12 @@ function shouldAttemptRetrieval(attemptFrequencyMS) {
attemptFrequencyMS = DEFAULT_ATTEMPT_FREQUENCY_MS;
}

if (!hasLocalStorage()) {
if (!storage.hasLocalStorage()) {
// It means we're using prebid cache for unsuccesful attempts.
return true;
}

const storedDate = localStorage.getItem(NEXTROLL_ID_DATE_KEY);
const storedDate = storage.getDataFromLocalStorage(NEXTROLL_ID_DATE_KEY);
if (storedDate === null) {
return true;
}
Expand Down

0 comments on commit 187e09c

Please sign in to comment.