DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (d1ed7de67f5a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_DataStoreService_h
#define mozilla_dom_DataStoreService_h

#include "mozilla/dom/PContent.h"
#include "nsClassHashtable.h"
#include "nsIDataStoreService.h"
#include "nsIObserver.h"
#include "nsRefPtrHashtable.h"

class nsIPrincipal;
class nsIUUIDGenerator;
class nsPIDOMWindow;

namespace mozilla {
namespace dom {

class DataStoreInfo;
class FirstRevisionIdCallback;
class PendingRequest;
class Promise;
class RetrieveRevisionsCounter;
class RevisionAddedEnableStoreCallback;

class DataStoreService MOZ_FINAL : public nsIDataStoreService
                                 , public nsIObserver
{
  friend class ContentChild;
  friend class FirstRevisionIdCallback;
  friend class RetrieveRevisionsCounter;
  friend class RevisionAddedEnableStoreCallback;

public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSIOBSERVER
  NS_DECL_NSIDATASTORESERVICE

  // Returns the DataStoreService singleton. Only to be called from main
  // thread.
  static already_AddRefed<DataStoreService> GetOrCreate();

  static already_AddRefed<DataStoreService> Get();

  static void Shutdown();

  static bool CheckPermission(nsIPrincipal* principal);

  nsresult GenerateUUID(nsAString& aID);

  nsresult GetDataStoresFromIPC(const nsAString& aName,
                                const nsAString& aOwner,
                                nsIPrincipal* aPrincipal,
                                nsTArray<DataStoreSetting>* aValue);

private:
  DataStoreService();
  ~DataStoreService();

  nsresult Init();

  typedef nsClassHashtable<nsUint32HashKey, DataStoreInfo> HashApp;

  nsresult AddPermissions(uint32_t aAppId, const nsAString& aName,
                          const nsAString& aOriginURL,
                          const nsAString& aManifestURL,
                          bool aReadOnly);

  nsresult AddAccessPermissions(uint32_t aAppId, const nsAString& aName,
                                const nsAString& aOriginURL,
                                const nsAString& aManifestURL,
                                bool aReadOnly);

  nsresult CreateFirstRevisionId(uint32_t aAppId, const nsAString& aName,
                                 const nsAString& aManifestURL);

  void GetDataStoresCreate(nsPIDOMWindow* aWindow, Promise* aPromise,
                           const nsTArray<DataStoreInfo>& aStores);

  void GetDataStoresResolve(nsPIDOMWindow* aWindow, Promise* aPromise,
                            const nsTArray<DataStoreInfo>& aStores);

  nsresult GetDataStoreInfos(const nsAString& aName, const nsAString& aOwner,
                             uint32_t aAppId, nsIPrincipal* aPrincipal,
                             nsTArray<DataStoreInfo>& aStores);

  void DeleteDataStores(uint32_t aAppId);

  nsresult EnableDataStore(uint32_t aAppId, const nsAString& aName,
                           const nsAString& aManifestURL);

  already_AddRefed<RetrieveRevisionsCounter> GetCounter(uint32_t aId) const;

  void RemoveCounter(uint32_t aId);

  nsClassHashtable<nsStringHashKey, HashApp> mStores;
  nsClassHashtable<nsStringHashKey, HashApp> mAccessStores;

  typedef nsTArray<PendingRequest> PendingRequests;
  nsClassHashtable<nsStringHashKey, PendingRequests> mPendingRequests;

  nsRefPtrHashtable<nsUint32HashKey, RetrieveRevisionsCounter> mPendingCounters;

  nsCOMPtr<nsIUUIDGenerator> mUUIDGenerator;
};

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_DataStoreService_h