toolkit/components/downloads/nsDownloadScanner.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /* vim: se cin sw=2 ts=2 et : */
     8 #ifndef nsDownloadScanner_h_
     9 #define nsDownloadScanner_h_
    11 #ifdef WIN32_LEAN_AND_MEAN
    12 #undef WIN32_LEAN_AND_MEAN
    13 #endif
    14 #include <windows.h>
    15 #define AVVENDOR
    16 #include <objidl.h>
    17 #include <msoav.h>
    18 #include <shlobj.h>
    20 #include "nsAutoPtr.h"
    21 #include "nsThreadUtils.h"
    22 #include "nsTArray.h"
    23 #include "nsIObserver.h"
    24 #include "nsIURI.h"
    26 enum AVScanState
    27 {
    28   AVSCAN_NOTSTARTED = 0,
    29   AVSCAN_SCANNING,
    30   AVSCAN_GOOD,
    31   AVSCAN_BAD,
    32   AVSCAN_UGLY,
    33   AVSCAN_FAILED,
    34   AVSCAN_TIMEDOUT
    35 };
    37 enum AVCheckPolicyState
    38 {
    39   AVPOLICY_DOWNLOAD,
    40   AVPOLICY_PROMPT,
    41   AVPOLICY_BLOCKED
    42 };
    44 // See nsDownloadScanner.cpp for declaration and definition
    45 class nsDownloadScannerWatchdog;
    46 class nsDownload;
    48 class nsDownloadScanner
    49 {
    50 public:
    51   nsDownloadScanner();
    52   ~nsDownloadScanner();
    53   nsresult Init();
    54   nsresult ScanDownload(nsDownload *download);
    55   AVCheckPolicyState CheckPolicy(nsIURI *aSource, nsIURI *aTarget);
    57 private:
    58   bool mAESExists;
    59   nsTArray<CLSID> mScanCLSID;
    60   bool IsAESAvailable();
    61   bool EnumerateOAVProviders();
    63   nsAutoPtr<nsDownloadScannerWatchdog> mWatchdog;
    65   static unsigned int __stdcall ScannerThreadFunction(void *p);
    66   class Scan : public nsRunnable
    67   {
    68   public:
    69     Scan(nsDownloadScanner *scanner, nsDownload *download);
    70     ~Scan();
    71     nsresult Start();
    73     // Returns the time that Start was called
    74     PRTime GetStartTime() const { return mStartTime; }
    75     // Returns a copy of the thread handle that can be waited on, but not
    76     // terminated
    77     // The caller is responsible for closing the handle
    78     // If the thread has terminated, then this will return the pseudo-handle
    79     // INVALID_HANDLE_VALUE
    80     HANDLE GetWaitableThreadHandle() const;
    82     // Called on a secondary thread to notify the scan that it has timed out
    83     // this is used only by the watchdog thread
    84     bool NotifyTimeout();
    86   private:
    87     nsDownloadScanner *mDLScanner;
    88     PRTime mStartTime;
    89     HANDLE mThread;
    90     nsRefPtr<nsDownload> mDownload;
    91     // Guards mStatus
    92     CRITICAL_SECTION mStateSync;
    93     AVScanState mStatus;
    94     nsString mPath;
    95     nsString mName;
    96     nsString mOrigin;
    97     // Also true if it is an ftp download
    98     bool mIsHttpDownload;
    99     bool mSkipSource;
   101     /* @summary Sets the Scan's state to newState if the current state is
   102                 expectedState
   103      * @param newState The new state of the scan
   104      * @param expectedState The state that the caller expects the scan to be in
   105      * @return If the old state matched expectedState
   106      */
   107     bool CheckAndSetState(AVScanState newState, AVScanState expectedState);
   109     NS_IMETHOD Run();
   111     void DoScan();
   112     bool DoScanAES();
   113     bool DoScanOAV();
   115     friend unsigned int __stdcall nsDownloadScanner::ScannerThreadFunction(void *);
   116   };
   117   // Used to give access to Scan
   118   friend class nsDownloadScannerWatchdog;
   119 };
   120 #endif

mercurial