LCOV - code coverage report
Current view: directory - toolkit/components/url-classifier - nsUrlClassifierProxies.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 108 104 96.3 %
Date: 2012-04-21 Functions: 46 45 97.8 %

       1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Firefox.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * the Mozilla Foundation <http://www.mozilla.org>.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #include "nsUrlClassifierProxies.h"
      39                 : #include "nsUrlClassifierDBService.h"
      40                 : 
      41                 : static nsresult
      42             834 : DispatchToWorkerThread(nsIRunnable* r)
      43                 : {
      44             834 :   nsIThread* t = nsUrlClassifierDBService::BackgroundThread();
      45             834 :   if (!t)
      46               0 :     return NS_ERROR_FAILURE;
      47                 : 
      48             834 :   return t->Dispatch(r, NS_DISPATCH_NORMAL);
      49                 : }
      50                 : 
      51              42 : NS_IMPL_THREADSAFE_ISUPPORTS1(UrlClassifierDBServiceWorkerProxy,
      52                 :                               nsIUrlClassifierDBServiceWorker)
      53                 : 
      54                 : NS_IMETHODIMP
      55             140 : UrlClassifierDBServiceWorkerProxy::Lookup(const nsACString& aSpec,
      56                 :                                           nsIUrlClassifierCallback* aCB)
      57                 : {
      58             420 :   nsCOMPtr<nsIRunnable> r = new LookupRunnable(mTarget, aSpec, aCB);
      59             140 :   return DispatchToWorkerThread(r);
      60                 : }
      61                 : 
      62                 : NS_IMETHODIMP
      63             140 : UrlClassifierDBServiceWorkerProxy::LookupRunnable::Run()
      64                 : {
      65             140 :   mTarget->Lookup(mSpec, mCB);
      66             140 :   return NS_OK;
      67                 : }
      68                 : 
      69                 : NS_IMETHODIMP
      70              48 : UrlClassifierDBServiceWorkerProxy::GetTables(nsIUrlClassifierCallback* aCB)
      71                 : {
      72             144 :   nsCOMPtr<nsIRunnable> r = new GetTablesRunnable(mTarget, aCB);
      73              48 :   return DispatchToWorkerThread(r);
      74                 : }
      75                 : 
      76                 : NS_IMETHODIMP
      77              48 : UrlClassifierDBServiceWorkerProxy::GetTablesRunnable::Run()
      78                 : {
      79              48 :   mTarget->GetTables(mCB);
      80              48 :   return NS_OK;
      81                 : }
      82                 : 
      83                 : NS_IMETHODIMP
      84               0 : UrlClassifierDBServiceWorkerProxy::SetHashCompleter
      85                 :   (const nsACString&, nsIUrlClassifierHashCompleter*)
      86                 : {
      87               0 :   NS_NOTREACHED("This method should not be called!");
      88               0 :   return NS_ERROR_NOT_IMPLEMENTED;
      89                 : }
      90                 : 
      91                 : NS_IMETHODIMP
      92              77 : UrlClassifierDBServiceWorkerProxy::BeginUpdate
      93                 :   (nsIUrlClassifierUpdateObserver* aUpdater,
      94                 :    const nsACString& aTables,
      95                 :    const nsACString& aClientKey)
      96                 : {
      97                 :   nsCOMPtr<nsIRunnable> r = new BeginUpdateRunnable(mTarget, aUpdater,
      98             231 :                                                     aTables, aClientKey);
      99              77 :   return DispatchToWorkerThread(r);
     100                 : }
     101                 : 
     102                 : NS_IMETHODIMP
     103              77 : UrlClassifierDBServiceWorkerProxy::BeginUpdateRunnable::Run()
     104                 : {
     105              77 :   mTarget->BeginUpdate(mUpdater, mTables, mClientKey);
     106              77 :   return NS_OK;
     107                 : }
     108                 : 
     109                 : NS_IMETHODIMP
     110              89 : UrlClassifierDBServiceWorkerProxy::BeginStream(const nsACString& aTable,
     111                 :                                                const nsACString& aServerMAC)
     112                 : {
     113                 :   nsCOMPtr<nsIRunnable> r =
     114             267 :     new BeginStreamRunnable(mTarget, aTable, aServerMAC);
     115              89 :   return DispatchToWorkerThread(r);
     116                 : }
     117                 : 
     118                 : NS_IMETHODIMP
     119              89 : UrlClassifierDBServiceWorkerProxy::BeginStreamRunnable::Run()
     120                 : {
     121              89 :   mTarget->BeginStream(mTable, mServerMAC);
     122              89 :   return NS_OK;
     123                 : }
     124                 : 
     125                 : NS_IMETHODIMP
     126              87 : UrlClassifierDBServiceWorkerProxy::UpdateStream(const nsACString& aUpdateChunk)
     127                 : {
     128                 :   nsCOMPtr<nsIRunnable> r =
     129             261 :     new UpdateStreamRunnable(mTarget, aUpdateChunk);
     130              87 :   return DispatchToWorkerThread(r);
     131                 : }
     132                 : 
     133                 : NS_IMETHODIMP
     134              87 : UrlClassifierDBServiceWorkerProxy::UpdateStreamRunnable::Run()
     135                 : {
     136              87 :   mTarget->UpdateStream(mUpdateChunk);
     137              87 :   return NS_OK;
     138                 : }
     139                 : 
     140                 : NS_IMETHODIMP
     141              87 : UrlClassifierDBServiceWorkerProxy::FinishStream()
     142                 : {
     143                 :   nsCOMPtr<nsIRunnable> r =
     144                 :     NS_NewRunnableMethod(mTarget,
     145             174 :                          &nsIUrlClassifierDBServiceWorker::FinishStream);
     146              87 :   return DispatchToWorkerThread(r);
     147                 : }
     148                 : 
     149                 : NS_IMETHODIMP
     150              75 : UrlClassifierDBServiceWorkerProxy::FinishUpdate()
     151                 : {
     152                 :   nsCOMPtr<nsIRunnable> r =
     153                 :     NS_NewRunnableMethod(mTarget,
     154             150 :                          &nsIUrlClassifierDBServiceWorker::FinishUpdate);
     155              75 :   return DispatchToWorkerThread(r);
     156                 : }
     157                 : 
     158                 : NS_IMETHODIMP
     159               9 : UrlClassifierDBServiceWorkerProxy::CancelUpdate()
     160                 : {
     161                 :   nsCOMPtr<nsIRunnable> r =
     162                 :     NS_NewRunnableMethod(mTarget,
     163              18 :                          &nsIUrlClassifierDBServiceWorker::CancelUpdate);
     164               9 :   return DispatchToWorkerThread(r);
     165                 : }
     166                 : 
     167                 : NS_IMETHODIMP
     168              46 : UrlClassifierDBServiceWorkerProxy::ResetDatabase()
     169                 : {
     170                 :   nsCOMPtr<nsIRunnable> r =
     171                 :     NS_NewRunnableMethod(mTarget,
     172              92 :                          &nsIUrlClassifierDBServiceWorker::ResetDatabase);
     173              46 :   return DispatchToWorkerThread(r);
     174                 : }
     175                 : 
     176                 : NS_IMETHODIMP
     177               7 : UrlClassifierDBServiceWorkerProxy::CloseDb()
     178                 : {
     179                 :   nsCOMPtr<nsIRunnable> r =
     180                 :     NS_NewRunnableMethod(mTarget,
     181              14 :                          &nsIUrlClassifierDBServiceWorker::CloseDb);
     182               7 :   return DispatchToWorkerThread(r);
     183                 : }
     184                 : 
     185                 : NS_IMETHODIMP
     186              29 : UrlClassifierDBServiceWorkerProxy::CacheCompletions(CacheResultArray * aEntries)
     187                 : {
     188              87 :   nsCOMPtr<nsIRunnable> r = new CacheCompletionsRunnable(mTarget, aEntries);
     189              29 :   return DispatchToWorkerThread(r);
     190                 : }
     191                 : 
     192                 : NS_IMETHODIMP
     193              29 : UrlClassifierDBServiceWorkerProxy::CacheCompletionsRunnable::Run()
     194                 : {
     195              29 :   mTarget->CacheCompletions(mEntries);
     196              29 :   return NS_OK;
     197                 : }
     198                 : 
     199                 : NS_IMETHODIMP
     200             140 : UrlClassifierDBServiceWorkerProxy::CacheMisses(PrefixArray * aEntries)
     201                 : {
     202             420 :   nsCOMPtr<nsIRunnable> r = new CacheMissesRunnable(mTarget, aEntries);
     203             140 :   return DispatchToWorkerThread(r);
     204                 : }
     205                 : 
     206                 : NS_IMETHODIMP
     207             140 : UrlClassifierDBServiceWorkerProxy::CacheMissesRunnable::Run()
     208                 : {
     209             140 :   mTarget->CacheMisses(mEntries);
     210             140 :   return NS_OK;
     211                 : }
     212                 : 
     213                 : 
     214            1820 : NS_IMPL_THREADSAFE_ISUPPORTS1(UrlClassifierLookupCallbackProxy,
     215                 :                               nsIUrlClassifierLookupCallback)
     216                 : 
     217                 : NS_IMETHODIMP
     218             140 : UrlClassifierLookupCallbackProxy::LookupComplete
     219                 :   (LookupResultArray * aResults)
     220                 : {
     221             420 :   nsCOMPtr<nsIRunnable> r = new LookupCompleteRunnable(mTarget, aResults);
     222             140 :   return NS_DispatchToMainThread(r);
     223                 : }
     224                 : 
     225                 : NS_IMETHODIMP
     226             140 : UrlClassifierLookupCallbackProxy::LookupCompleteRunnable::Run()
     227                 : {
     228             140 :   mTarget->LookupComplete(mResults);
     229             140 :   return NS_OK;
     230                 : }
     231                 : 
     232             528 : NS_IMPL_THREADSAFE_ISUPPORTS1(UrlClassifierCallbackProxy,
     233                 :                               nsIUrlClassifierCallback)
     234                 : 
     235                 : NS_IMETHODIMP
     236              48 : UrlClassifierCallbackProxy::HandleEvent(const nsACString& aValue)
     237                 : {
     238             144 :   nsCOMPtr<nsIRunnable> r = new HandleEventRunnable(mTarget, aValue);
     239              48 :   return NS_DispatchToMainThread(r);
     240                 : }
     241                 : 
     242                 : NS_IMETHODIMP
     243              48 : UrlClassifierCallbackProxy::HandleEventRunnable::Run()
     244                 : {
     245              48 :   mTarget->HandleEvent(mValue);
     246              48 :   return NS_OK;
     247                 : }
     248                 : 
     249            1232 : NS_IMPL_THREADSAFE_ISUPPORTS1(UrlClassifierUpdateObserverProxy,
     250                 :                               nsIUrlClassifierUpdateObserver)
     251                 : 
     252                 : NS_IMETHODIMP
     253              16 : UrlClassifierUpdateObserverProxy::UpdateUrlRequested
     254                 :   (const nsACString& aURL,
     255                 :    const nsACString& aTable,
     256                 :    const nsACString& aServerMAC)
     257                 : {
     258                 :   nsCOMPtr<nsIRunnable> r =
     259              48 :     new UpdateUrlRequestedRunnable(mTarget, aURL, aTable, aServerMAC);
     260              16 :   return NS_DispatchToMainThread(r);
     261                 : }
     262                 : 
     263                 : NS_IMETHODIMP
     264              16 : UrlClassifierUpdateObserverProxy::UpdateUrlRequestedRunnable::Run()
     265                 : {
     266              16 :   mTarget->UpdateUrlRequested(mURL, mTable, mServerMAC);
     267              16 :   return NS_OK;
     268                 : }
     269                 : 
     270                 : NS_IMETHODIMP
     271               1 : UrlClassifierUpdateObserverProxy::RekeyRequested()
     272                 : {
     273                 :   nsCOMPtr<nsIRunnable> r =
     274               2 :     NS_NewRunnableMethod(mTarget, &nsIUrlClassifierUpdateObserver::RekeyRequested);
     275               1 :   return NS_DispatchToMainThread(r);
     276                 : }
     277                 : 
     278                 : NS_IMETHODIMP
     279              87 : UrlClassifierUpdateObserverProxy::StreamFinished(nsresult aStatus,
     280                 :                                                  PRUint32 aDelay)
     281                 : {
     282                 :   nsCOMPtr<nsIRunnable> r =
     283             261 :     new StreamFinishedRunnable(mTarget, aStatus, aDelay);
     284              87 :   return NS_DispatchToMainThread(r);
     285                 : }
     286                 : 
     287                 : NS_IMETHODIMP
     288              87 : UrlClassifierUpdateObserverProxy::StreamFinishedRunnable::Run()
     289                 : {
     290              87 :   mTarget->StreamFinished(mStatus, mDelay);
     291              87 :   return NS_OK;
     292                 : }
     293                 : 
     294                 : NS_IMETHODIMP
     295               9 : UrlClassifierUpdateObserverProxy::UpdateError(nsresult aError)
     296                 : {
     297                 :   nsCOMPtr<nsIRunnable> r =
     298              27 :     new UpdateErrorRunnable(mTarget, aError);
     299               9 :   return NS_DispatchToMainThread(r);
     300                 : }
     301                 : 
     302                 : NS_IMETHODIMP
     303               9 : UrlClassifierUpdateObserverProxy::UpdateErrorRunnable::Run()
     304                 : {
     305               9 :   mTarget->UpdateError(mError);
     306               9 :   return NS_OK;
     307                 : }
     308                 : 
     309                 : NS_IMETHODIMP
     310              68 : UrlClassifierUpdateObserverProxy::UpdateSuccess(PRUint32 aRequestedTimeout)
     311                 : {
     312                 :   nsCOMPtr<nsIRunnable> r =
     313             204 :     new UpdateSuccessRunnable(mTarget, aRequestedTimeout);
     314              68 :   return NS_DispatchToMainThread(r);
     315                 : }
     316                 : 
     317                 : NS_IMETHODIMP
     318              68 : UrlClassifierUpdateObserverProxy::UpdateSuccessRunnable::Run()
     319                 : {
     320              68 :   mTarget->UpdateSuccess(mRequestedTimeout);
     321              68 :   return NS_OK;
     322                 : }

Generated by: LCOV version 1.7