LCOV - code coverage report
Current view: directory - toolkit/components/url-classifier - nsUrlClassifierProxies.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 102 95 93.1 %
Date: 2012-06-02 Functions: 44 42 95.5 %

       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             760 : DispatchToWorkerThread(nsIRunnable* r)
      43                 : {
      44             760 :   nsIThread* t = nsUrlClassifierDBService::BackgroundThread();
      45             760 :   if (!t)
      46               0 :     return NS_ERROR_FAILURE;
      47                 : 
      48             760 :   return t->Dispatch(r, NS_DISPATCH_NORMAL);
      49                 : }
      50                 : 
      51              48 : NS_IMPL_THREADSAFE_ISUPPORTS1(UrlClassifierDBServiceWorkerProxy,
      52                 :                               nsIUrlClassifierDBServiceWorker)
      53                 : 
      54                 : NS_IMETHODIMP
      55             141 : UrlClassifierDBServiceWorkerProxy::Lookup(const nsACString& aSpec,
      56                 :                                           nsIUrlClassifierCallback* aCB)
      57                 : {
      58             423 :   nsCOMPtr<nsIRunnable> r = new LookupRunnable(mTarget, aSpec, aCB);
      59             141 :   return DispatchToWorkerThread(r);
      60                 : }
      61                 : 
      62                 : NS_IMETHODIMP
      63             141 : UrlClassifierDBServiceWorkerProxy::LookupRunnable::Run()
      64                 : {
      65             141 :   mTarget->Lookup(mSpec, mCB);
      66             141 :   return NS_OK;
      67                 : }
      68                 : 
      69                 : NS_IMETHODIMP
      70              53 : UrlClassifierDBServiceWorkerProxy::GetTables(nsIUrlClassifierCallback* aCB)
      71                 : {
      72             159 :   nsCOMPtr<nsIRunnable> r = new GetTablesRunnable(mTarget, aCB);
      73              53 :   return DispatchToWorkerThread(r);
      74                 : }
      75                 : 
      76                 : NS_IMETHODIMP
      77              53 : UrlClassifierDBServiceWorkerProxy::GetTablesRunnable::Run()
      78                 : {
      79              53 :   mTarget->GetTables(mCB);
      80              53 :   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              87 : UrlClassifierDBServiceWorkerProxy::BeginUpdate
      93                 :   (nsIUrlClassifierUpdateObserver* aUpdater,
      94                 :    const nsACString& aTables,
      95                 :    const nsACString& aClientKey)
      96                 : {
      97                 :   nsCOMPtr<nsIRunnable> r = new BeginUpdateRunnable(mTarget, aUpdater,
      98             261 :                                                     aTables, aClientKey);
      99              87 :   return DispatchToWorkerThread(r);
     100                 : }
     101                 : 
     102                 : NS_IMETHODIMP
     103              87 : UrlClassifierDBServiceWorkerProxy::BeginUpdateRunnable::Run()
     104                 : {
     105              87 :   mTarget->BeginUpdate(mUpdater, mTables, mClientKey);
     106              87 :   return NS_OK;
     107                 : }
     108                 : 
     109                 : NS_IMETHODIMP
     110             102 : UrlClassifierDBServiceWorkerProxy::BeginStream(const nsACString& aTable,
     111                 :                                                const nsACString& aServerMAC)
     112                 : {
     113                 :   nsCOMPtr<nsIRunnable> r =
     114             306 :     new BeginStreamRunnable(mTarget, aTable, aServerMAC);
     115             102 :   return DispatchToWorkerThread(r);
     116                 : }
     117                 : 
     118                 : NS_IMETHODIMP
     119             102 : UrlClassifierDBServiceWorkerProxy::BeginStreamRunnable::Run()
     120                 : {
     121             102 :   mTarget->BeginStream(mTable, mServerMAC);
     122             102 :   return NS_OK;
     123                 : }
     124                 : 
     125                 : NS_IMETHODIMP
     126             100 : UrlClassifierDBServiceWorkerProxy::UpdateStream(const nsACString& aUpdateChunk)
     127                 : {
     128                 :   nsCOMPtr<nsIRunnable> r =
     129             300 :     new UpdateStreamRunnable(mTarget, aUpdateChunk);
     130             100 :   return DispatchToWorkerThread(r);
     131                 : }
     132                 : 
     133                 : NS_IMETHODIMP
     134             100 : UrlClassifierDBServiceWorkerProxy::UpdateStreamRunnable::Run()
     135                 : {
     136             100 :   mTarget->UpdateStream(mUpdateChunk);
     137             100 :   return NS_OK;
     138                 : }
     139                 : 
     140                 : NS_IMETHODIMP
     141             100 : UrlClassifierDBServiceWorkerProxy::FinishStream()
     142                 : {
     143                 :   nsCOMPtr<nsIRunnable> r =
     144                 :     NS_NewRunnableMethod(mTarget,
     145             200 :                          &nsIUrlClassifierDBServiceWorker::FinishStream);
     146             100 :   return DispatchToWorkerThread(r);
     147                 : }
     148                 : 
     149                 : NS_IMETHODIMP
     150              85 : UrlClassifierDBServiceWorkerProxy::FinishUpdate()
     151                 : {
     152                 :   nsCOMPtr<nsIRunnable> r =
     153                 :     NS_NewRunnableMethod(mTarget,
     154             170 :                          &nsIUrlClassifierDBServiceWorker::FinishUpdate);
     155              85 :   return DispatchToWorkerThread(r);
     156                 : }
     157                 : 
     158                 : NS_IMETHODIMP
     159              10 : UrlClassifierDBServiceWorkerProxy::CancelUpdate()
     160                 : {
     161                 :   nsCOMPtr<nsIRunnable> r =
     162                 :     NS_NewRunnableMethod(mTarget,
     163              20 :                          &nsIUrlClassifierDBServiceWorker::CancelUpdate);
     164              10 :   return DispatchToWorkerThread(r);
     165                 : }
     166                 : 
     167                 : NS_IMETHODIMP
     168              54 : UrlClassifierDBServiceWorkerProxy::ResetDatabase()
     169                 : {
     170                 :   nsCOMPtr<nsIRunnable> r =
     171                 :     NS_NewRunnableMethod(mTarget,
     172             108 :                          &nsIUrlClassifierDBServiceWorker::ResetDatabase);
     173              54 :   return DispatchToWorkerThread(r);
     174                 : }
     175                 : 
     176                 : NS_IMETHODIMP
     177               8 : UrlClassifierDBServiceWorkerProxy::CloseDb()
     178                 : {
     179                 :   nsCOMPtr<nsIRunnable> r =
     180                 :     NS_NewRunnableMethod(mTarget,
     181              16 :                          &nsIUrlClassifierDBServiceWorker::CloseDb);
     182               8 :   return DispatchToWorkerThread(r);
     183                 : }
     184                 : 
     185                 : NS_IMETHODIMP
     186              20 : UrlClassifierDBServiceWorkerProxy::CacheCompletions(nsTArray<nsUrlClassifierLookupResult>* aEntries)
     187                 : {
     188              60 :   nsCOMPtr<nsIRunnable> r = new CacheCompletionsRunnable(mTarget, aEntries);
     189              20 :   return DispatchToWorkerThread(r);
     190                 : }
     191                 : 
     192                 : NS_IMETHODIMP
     193              20 : UrlClassifierDBServiceWorkerProxy::CacheCompletionsRunnable::Run()
     194                 : {
     195              20 :   mTarget->CacheCompletions(mEntries);
     196              20 :   return NS_OK;
     197                 : }
     198                 : 
     199            1833 : NS_IMPL_THREADSAFE_ISUPPORTS1(UrlClassifierLookupCallbackProxy,
     200                 :                               nsIUrlClassifierLookupCallback)
     201                 : 
     202                 : NS_IMETHODIMP
     203             141 : UrlClassifierLookupCallbackProxy::LookupComplete
     204                 :   (nsTArray<nsUrlClassifierLookupResult>* aResults)
     205                 : {
     206             423 :   nsCOMPtr<nsIRunnable> r = new LookupCompleteRunnable(mTarget, aResults);
     207             141 :   return NS_DispatchToMainThread(r);
     208                 : }
     209                 : 
     210                 : NS_IMETHODIMP
     211             141 : UrlClassifierLookupCallbackProxy::LookupCompleteRunnable::Run()
     212                 : {
     213             141 :   mTarget->LookupComplete(mResults);
     214             141 :   return NS_OK;
     215                 : }
     216                 : 
     217             583 : NS_IMPL_THREADSAFE_ISUPPORTS1(UrlClassifierCallbackProxy,
     218                 :                               nsIUrlClassifierCallback)
     219                 : 
     220                 : NS_IMETHODIMP
     221              53 : UrlClassifierCallbackProxy::HandleEvent(const nsACString& aValue)
     222                 : {
     223             159 :   nsCOMPtr<nsIRunnable> r = new HandleEventRunnable(mTarget, aValue);
     224              53 :   return NS_DispatchToMainThread(r);
     225                 : }
     226                 : 
     227                 : NS_IMETHODIMP
     228              53 : UrlClassifierCallbackProxy::HandleEventRunnable::Run()
     229                 : {
     230              53 :   mTarget->HandleEvent(mValue);
     231              53 :   return NS_OK;
     232                 : }
     233                 : 
     234            1392 : NS_IMPL_THREADSAFE_ISUPPORTS1(UrlClassifierUpdateObserverProxy,
     235                 :                               nsIUrlClassifierUpdateObserver)
     236                 : 
     237                 : NS_IMETHODIMP
     238              17 : UrlClassifierUpdateObserverProxy::UpdateUrlRequested
     239                 :   (const nsACString& aURL,
     240                 :    const nsACString& aTable,
     241                 :    const nsACString& aServerMAC)
     242                 : {
     243                 :   nsCOMPtr<nsIRunnable> r =
     244              51 :     new UpdateUrlRequestedRunnable(mTarget, aURL, aTable, aServerMAC);
     245              17 :   return NS_DispatchToMainThread(r);
     246                 : }
     247                 : 
     248                 : NS_IMETHODIMP
     249              17 : UrlClassifierUpdateObserverProxy::UpdateUrlRequestedRunnable::Run()
     250                 : {
     251              17 :   mTarget->UpdateUrlRequested(mURL, mTable, mServerMAC);
     252              17 :   return NS_OK;
     253                 : }
     254                 : 
     255                 : NS_IMETHODIMP
     256               0 : UrlClassifierUpdateObserverProxy::RekeyRequested()
     257                 : {
     258                 :   nsCOMPtr<nsIRunnable> r =
     259               0 :     NS_NewRunnableMethod(mTarget, &nsIUrlClassifierUpdateObserver::RekeyRequested);
     260               0 :   return NS_DispatchToMainThread(r);
     261                 : }
     262                 : 
     263                 : NS_IMETHODIMP
     264             100 : UrlClassifierUpdateObserverProxy::StreamFinished(nsresult aStatus,
     265                 :                                                  PRUint32 aDelay)
     266                 : {
     267                 :   nsCOMPtr<nsIRunnable> r =
     268             300 :     new StreamFinishedRunnable(mTarget, aStatus, aDelay);
     269             100 :   return NS_DispatchToMainThread(r);
     270                 : }
     271                 : 
     272                 : NS_IMETHODIMP
     273             100 : UrlClassifierUpdateObserverProxy::StreamFinishedRunnable::Run()
     274                 : {
     275             100 :   mTarget->StreamFinished(mStatus, mDelay);
     276             100 :   return NS_OK;
     277                 : }
     278                 : 
     279                 : NS_IMETHODIMP
     280               3 : UrlClassifierUpdateObserverProxy::UpdateError(nsresult aError)
     281                 : {
     282                 :   nsCOMPtr<nsIRunnable> r =
     283               9 :     new UpdateErrorRunnable(mTarget, aError);
     284               3 :   return NS_DispatchToMainThread(r);
     285                 : }
     286                 : 
     287                 : NS_IMETHODIMP
     288               3 : UrlClassifierUpdateObserverProxy::UpdateErrorRunnable::Run()
     289                 : {
     290               3 :   mTarget->UpdateError(mError);
     291               3 :   return NS_OK;
     292                 : }
     293                 : 
     294                 : NS_IMETHODIMP
     295              84 : UrlClassifierUpdateObserverProxy::UpdateSuccess(PRUint32 aRequestedTimeout)
     296                 : {
     297                 :   nsCOMPtr<nsIRunnable> r =
     298             252 :     new UpdateSuccessRunnable(mTarget, aRequestedTimeout);
     299              84 :   return NS_DispatchToMainThread(r);
     300                 : }
     301                 : 
     302                 : NS_IMETHODIMP
     303              84 : UrlClassifierUpdateObserverProxy::UpdateSuccessRunnable::Run()
     304                 : {
     305              84 :   mTarget->UpdateSuccess(mRequestedTimeout);
     306              84 :   return NS_OK;
     307                 : }

Generated by: LCOV version 1.7