void
SocketMessageWatcher::StopWatching()
{
  mWatcher.StopWatchingFileDescriptor();

  // remove this watcher and its result handler from hash table
  sWatcherHashtable.Remove(mRes);
}
Example #2
0
void
nsPreflightCache::RemoveEntries(nsIURI* aURI, nsIPrincipal* aPrincipal)
{
  CacheEntry* entry;
  nsCString key;
  if (GetCacheKey(aURI, aPrincipal, true, key) &&
      mTable.Get(key, &entry)) {
    PR_REMOVE_LINK(entry);
    mTable.Remove(key);
  }

  if (GetCacheKey(aURI, aPrincipal, false, key) &&
      mTable.Get(key, &entry)) {
    PR_REMOVE_LINK(entry);
    mTable.Remove(key);
  }
}
void
nsLayoutHistoryState::ResetScrollState()
{
    for (auto iter = mStates.Iter(); !iter.Done(); iter.Next()) {
        nsPresState* state = iter.UserData();
        if (state) {
            state->SetScrollState(nsPoint(0, 0));
        }
    }
}
void
VLPrefixSet::Merge(PrefixStringMap& aPrefixMap) {
  for (auto iter = mMap.ConstIter(); !iter.Done(); iter.Next()) {
    nsCString* prefixString = aPrefixMap.LookupOrAdd(iter.Key());
    PrefixString* str = iter.Data();

    if (str->get()) {
      prefixString->Append(str->get(), str->remaining());
    }
  }
}
void
SocketMessageWatcher::Watch()
{
  // add this watcher and its result handler to hash table
  sWatcherHashtable.Put(mRes, new SocketMessageWatcherWrapper(this));

  MessageLoopForIO::current()->WatchFileDescriptor(
    mFd,
    true,
    MessageLoopForIO::WATCH_READ,
    &mWatcher,
    this);
}
nsPresState*
nsLayoutHistoryState::GetState(const nsCString& aKey)
{
    nsPresState* state = nullptr;
    bool entryExists = mStates.Get(aKey, &state);

    if (entryExists && mScrollPositionOnly) {
        // Ensure any state that shouldn't be restored is removed
        state->ClearNonScrollState();
    }

    return state;
}
NS_IMETHODIMP
DeleteSocketMessageWatcherTask::Run()
{
  // look up hash table for the watcher corresponding to |mRes|
  SocketMessageWatcherWrapper* wrapper = sWatcherHashtable.Get(mRes);
  if (!wrapper) {
    return NS_OK;
  }

  // stop the watcher if it exists
  SocketMessageWatcher* watcher = wrapper->GetSocketMessageWatcher();
  watcher->StopWatching();
  watcher->Proceed(STATUS_DONE);
  return NS_OK;
}
void
nsPreflightCache::Clear()
{
    mList.clear();
    mTable.Clear();
}
nsPreflightCache::CacheEntry*
nsPreflightCache::GetEntry(nsIURI* aURI,
                           nsIPrincipal* aPrincipal,
                           bool aWithCredentials,
                           bool aCreate)
{
    nsCString key;
    if (!GetCacheKey(aURI, aPrincipal, aWithCredentials, key)) {
        NS_WARNING("Invalid cache key!");
        return nullptr;
    }

    CacheEntry* entry;

    if (mTable.Get(key, &entry)) {
        // Entry already existed so just return it. Also update the LRU list.

        // Move to the head of the list.
        entry->removeFrom(mList);
        mList.insertFront(entry);

        return entry;
    }

    if (!aCreate) {
        return nullptr;
    }

    // This is a new entry, allocate and insert into the table now so that any
    // failures don't cause items to be removed from a full cache.
    entry = new CacheEntry(key);
    if (!entry) {
        NS_WARNING("Failed to allocate new cache entry!");
        return nullptr;
    }

    NS_ASSERTION(mTable.Count() <= PREFLIGHT_CACHE_SIZE,
                 "Something is borked, too many entries in the cache!");

    // Now enforce the max count.
    if (mTable.Count() == PREFLIGHT_CACHE_SIZE) {
        // Try to kick out all the expired entries.
        TimeStamp now = TimeStamp::NowLoRes();
        mTable.Enumerate(RemoveExpiredEntries, &now);

        // If that didn't remove anything then kick out the least recently used
        // entry.
        if (mTable.Count() == PREFLIGHT_CACHE_SIZE) {
            CacheEntry* lruEntry = static_cast<CacheEntry*>(mList.popLast());
            MOZ_ASSERT(lruEntry);

            // This will delete 'lruEntry'.
            mTable.Remove(lruEntry->mKey);

            NS_ASSERTION(mTable.Count() == PREFLIGHT_CACHE_SIZE - 1,
                         "Somehow tried to remove an entry that was never added!");
        }
    }

    mTable.Put(key, entry);
    mList.insertFront(entry);

    return entry;
}
void
nsPreflightCache::Clear()
{
  PR_INIT_CLIST(&mList);
  mTable.Clear();
}
bool
nsLayoutHistoryState::HasStates() const
{
    return mStates.Count() != 0;
}
void
nsLayoutHistoryState::RemoveState(const nsCString& aKey)
{
    mStates.Remove(aKey);
}
void
nsLayoutHistoryState::AddState(const nsCString& aStateKey, nsPresState* aState)
{
    mStates.Put(aStateKey, aState);
}