forked from mirrors/gecko-dev
		
	 01583602a9
			
		
	
	
		01583602a9
		
	
	
	
	
		
			
			The bulk of this commit was generated with a script, executed at the top
level of a typical source code checkout.  The only non-machine-generated
part was modifying MFBT's moz.build to reflect the new naming.
CLOSED TREE makes big refactorings like this a piece of cake.
 # The main substitution.
find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \
    xargs perl -p -i -e '
 s/nsRefPtr\.h/RefPtr\.h/g; # handle includes
 s/nsRefPtr ?</RefPtr</g;   # handle declarations and variables
'
 # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h.
perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h
 # Handle nsRefPtr.h itself, a couple places that define constructors
 # from nsRefPtr, and code generators specially.  We do this here, rather
 # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename
 # things like nsRefPtrHashtable.
perl -p -i -e 's/nsRefPtr/RefPtr/g' \
     mfbt/nsRefPtr.h \
     xpcom/glue/nsCOMPtr.h \
     xpcom/base/OwningNonNull.h \
     ipc/ipdl/ipdl/lower.py \
     ipc/ipdl/ipdl/builtin.py \
     dom/bindings/Codegen.py \
     python/lldbutils/lldbutils/utils.py
 # In our indiscriminate substitution above, we renamed
 # nsRefPtrGetterAddRefs, the class behind getter_AddRefs.  Fix that up.
find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \
    xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g'
if [ -d .git ]; then
    git mv mfbt/nsRefPtr.h mfbt/RefPtr.h
else
    hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h
fi
--HG--
rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
		
	
			
		
			
				
	
	
		
			143 lines
		
	
	
	
		
			4.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			143 lines
		
	
	
	
		
			4.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 | |
| /* 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 LookupCache_h__
 | |
| #define LookupCache_h__
 | |
| 
 | |
| #include "Entries.h"
 | |
| #include "nsString.h"
 | |
| #include "nsTArray.h"
 | |
| #include "nsCOMPtr.h"
 | |
| #include "nsIFile.h"
 | |
| #include "nsIFileStreams.h"
 | |
| #include "mozilla/RefPtr.h"
 | |
| #include "nsUrlClassifierPrefixSet.h"
 | |
| #include "mozilla/Logging.h"
 | |
| 
 | |
| namespace mozilla {
 | |
| namespace safebrowsing {
 | |
| 
 | |
| #define MAX_HOST_COMPONENTS 5
 | |
| #define MAX_PATH_COMPONENTS 4
 | |
| 
 | |
| class LookupResult {
 | |
| public:
 | |
|   LookupResult() : mComplete(false), mNoise(false), mFresh(false), mProtocolConfirmed(false) {}
 | |
| 
 | |
|   // The fragment that matched in the LookupCache
 | |
|   union {
 | |
|     Prefix prefix;
 | |
|     Completion complete;
 | |
|   } hash;
 | |
| 
 | |
|   const Prefix &PrefixHash() { return hash.prefix; }
 | |
|   const Completion &CompleteHash() { return hash.complete; }
 | |
| 
 | |
|   bool Confirmed() const { return (mComplete && mFresh) || mProtocolConfirmed; }
 | |
|   bool Complete() const { return mComplete; }
 | |
| 
 | |
|   // True if we have a complete match for this hash in the table.
 | |
|   bool mComplete;
 | |
| 
 | |
|   // True if this is a noise entry, i.e. an extra entry
 | |
|   // that is inserted to mask the true URL we are requesting
 | |
|   bool mNoise;
 | |
| 
 | |
|   // True if we've updated this table recently-enough.
 | |
|   bool mFresh;
 | |
| 
 | |
|   bool mProtocolConfirmed;
 | |
| 
 | |
|   nsCString mTableName;
 | |
| };
 | |
| 
 | |
| typedef nsTArray<LookupResult> LookupResultArray;
 | |
| 
 | |
| struct CacheResult {
 | |
|   AddComplete entry;
 | |
|   nsCString table;
 | |
| };
 | |
| typedef nsTArray<CacheResult> CacheResultArray;
 | |
| 
 | |
| class LookupCache {
 | |
| public:
 | |
|   // Check for a canonicalized IP address.
 | |
|   static bool IsCanonicalizedIP(const nsACString& aHost);
 | |
| 
 | |
|   // take a lookup string (www.hostname.com/path/to/resource.html) and
 | |
|   // expand it into the set of fragments that should be searched for in an
 | |
|   // entry
 | |
|   static nsresult GetLookupFragments(const nsACString& aSpec,
 | |
|                                      nsTArray<nsCString>* aFragments);
 | |
|   // Similar to GetKey(), but if the domain contains three or more components,
 | |
|   // two keys will be returned:
 | |
|   //  hostname.com/foo/bar -> [hostname.com]
 | |
|   //  mail.hostname.com/foo/bar -> [hostname.com, mail.hostname.com]
 | |
|   //  www.mail.hostname.com/foo/bar -> [hostname.com, mail.hostname.com]
 | |
|   static nsresult GetHostKeys(const nsACString& aSpec,
 | |
|                               nsTArray<nsCString>* aHostKeys);
 | |
|   // Get the database key for a given URI.  This is the top three
 | |
|   // domain components if they exist, otherwise the top two.
 | |
|   //  hostname.com/foo/bar -> hostname.com
 | |
|   //  mail.hostname.com/foo/bar -> mail.hostname.com
 | |
|   //  www.mail.hostname.com/foo/bar -> mail.hostname.com
 | |
|   static nsresult GetKey(const nsACString& aSpec, Completion* aHash,
 | |
|                          nsCOMPtr<nsICryptoHash>& aCryptoHash);
 | |
| 
 | |
|   LookupCache(const nsACString& aTableName, nsIFile* aStoreFile);
 | |
|   ~LookupCache();
 | |
| 
 | |
|   const nsCString &TableName() const { return mTableName; }
 | |
| 
 | |
|   nsresult Init();
 | |
|   nsresult Open();
 | |
|   // The directory handle where we operate will
 | |
|   // be moved away when a backup is made.
 | |
|   nsresult UpdateDirHandle(nsIFile* aStoreDirectory);
 | |
|   // This will Clear() the passed arrays when done.
 | |
|   nsresult Build(AddPrefixArray& aAddPrefixes,
 | |
|                  AddCompleteArray& aAddCompletes);
 | |
|   nsresult GetPrefixes(FallibleTArray<uint32_t>& aAddPrefixes);
 | |
|   void ClearCompleteCache();
 | |
| 
 | |
| #if DEBUG
 | |
|   void Dump();
 | |
| #endif
 | |
|   nsresult WriteFile();
 | |
|   nsresult Has(const Completion& aCompletion,
 | |
|                bool* aHas, bool* aComplete);
 | |
|   bool IsPrimed();
 | |
| 
 | |
| private:
 | |
|   void ClearAll();
 | |
|   nsresult Reset();
 | |
|   void UpdateHeader();
 | |
|   nsresult ReadHeader(nsIInputStream* aInputStream);
 | |
|   nsresult ReadCompletions(nsIInputStream* aInputStream);
 | |
|   nsresult EnsureSizeConsistent();
 | |
|   nsresult LoadPrefixSet();
 | |
|   // Construct a Prefix Set with known prefixes.
 | |
|   // This will Clear() aAddPrefixes when done.
 | |
|   nsresult ConstructPrefixSet(AddPrefixArray& aAddPrefixes);
 | |
| 
 | |
|   struct Header {
 | |
|     uint32_t magic;
 | |
|     uint32_t version;
 | |
|     uint32_t numCompletions;
 | |
|   };
 | |
|   Header mHeader;
 | |
| 
 | |
|   bool mPrimed;
 | |
|   nsCString mTableName;
 | |
|   nsCOMPtr<nsIFile> mStoreDirectory;
 | |
|   CompletionArray mCompletions;
 | |
|   // Set of prefixes known to be in the database
 | |
|   RefPtr<nsUrlClassifierPrefixSet> mPrefixSet;
 | |
| };
 | |
| 
 | |
| } // namespace safebrowsing
 | |
| } // namespace mozilla
 | |
| 
 | |
| #endif
 |