Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsUrlClassifierProxies_h |
michael@0 | 7 | #define nsUrlClassifierProxies_h |
michael@0 | 8 | |
michael@0 | 9 | #include "nsIUrlClassifierDBService.h" |
michael@0 | 10 | #include "nsProxyRelease.h" |
michael@0 | 11 | #include "nsThreadUtils.h" |
michael@0 | 12 | #include "mozilla/Attributes.h" |
michael@0 | 13 | #include "nsIPrincipal.h" |
michael@0 | 14 | #include "LookupCache.h" |
michael@0 | 15 | |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * Thread proxy from the main thread to the worker thread. |
michael@0 | 19 | */ |
michael@0 | 20 | class UrlClassifierDBServiceWorkerProxy MOZ_FINAL : |
michael@0 | 21 | public nsIUrlClassifierDBServiceWorker |
michael@0 | 22 | { |
michael@0 | 23 | public: |
michael@0 | 24 | UrlClassifierDBServiceWorkerProxy(nsIUrlClassifierDBServiceWorker* aTarget) |
michael@0 | 25 | : mTarget(aTarget) |
michael@0 | 26 | { } |
michael@0 | 27 | |
michael@0 | 28 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 29 | NS_DECL_NSIURLCLASSIFIERDBSERVICE |
michael@0 | 30 | NS_DECL_NSIURLCLASSIFIERDBSERVICEWORKER |
michael@0 | 31 | |
michael@0 | 32 | class LookupRunnable : public nsRunnable |
michael@0 | 33 | { |
michael@0 | 34 | public: |
michael@0 | 35 | LookupRunnable(nsIUrlClassifierDBServiceWorker* aTarget, |
michael@0 | 36 | nsIPrincipal* aPrincipal, |
michael@0 | 37 | const nsACString& aTables, |
michael@0 | 38 | nsIUrlClassifierCallback* aCB) |
michael@0 | 39 | : mTarget(aTarget) |
michael@0 | 40 | , mPrincipal(aPrincipal) |
michael@0 | 41 | , mLookupTables(aTables) |
michael@0 | 42 | , mCB(aCB) |
michael@0 | 43 | { } |
michael@0 | 44 | |
michael@0 | 45 | NS_DECL_NSIRUNNABLE |
michael@0 | 46 | |
michael@0 | 47 | private: |
michael@0 | 48 | nsCOMPtr<nsIUrlClassifierDBServiceWorker> mTarget; |
michael@0 | 49 | nsCOMPtr<nsIPrincipal> mPrincipal; |
michael@0 | 50 | nsCString mLookupTables; |
michael@0 | 51 | nsCOMPtr<nsIUrlClassifierCallback> mCB; |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | class GetTablesRunnable : public nsRunnable |
michael@0 | 55 | { |
michael@0 | 56 | public: |
michael@0 | 57 | GetTablesRunnable(nsIUrlClassifierDBServiceWorker* aTarget, |
michael@0 | 58 | nsIUrlClassifierCallback* aCB) |
michael@0 | 59 | : mTarget(aTarget) |
michael@0 | 60 | , mCB(aCB) |
michael@0 | 61 | { } |
michael@0 | 62 | |
michael@0 | 63 | NS_DECL_NSIRUNNABLE |
michael@0 | 64 | |
michael@0 | 65 | private: |
michael@0 | 66 | nsCOMPtr<nsIUrlClassifierDBServiceWorker> mTarget; |
michael@0 | 67 | nsCOMPtr<nsIUrlClassifierCallback> mCB; |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | class BeginUpdateRunnable : public nsRunnable |
michael@0 | 71 | { |
michael@0 | 72 | public: |
michael@0 | 73 | BeginUpdateRunnable(nsIUrlClassifierDBServiceWorker* aTarget, |
michael@0 | 74 | nsIUrlClassifierUpdateObserver* aUpdater, |
michael@0 | 75 | const nsACString& aTables) |
michael@0 | 76 | : mTarget(aTarget) |
michael@0 | 77 | , mUpdater(aUpdater) |
michael@0 | 78 | , mTables(aTables) |
michael@0 | 79 | { } |
michael@0 | 80 | |
michael@0 | 81 | NS_DECL_NSIRUNNABLE |
michael@0 | 82 | |
michael@0 | 83 | private: |
michael@0 | 84 | nsCOMPtr<nsIUrlClassifierDBServiceWorker> mTarget; |
michael@0 | 85 | nsCOMPtr<nsIUrlClassifierUpdateObserver> mUpdater; |
michael@0 | 86 | nsCString mTables; |
michael@0 | 87 | }; |
michael@0 | 88 | |
michael@0 | 89 | class BeginStreamRunnable : public nsRunnable |
michael@0 | 90 | { |
michael@0 | 91 | public: |
michael@0 | 92 | BeginStreamRunnable(nsIUrlClassifierDBServiceWorker* aTarget, |
michael@0 | 93 | const nsACString& aTable) |
michael@0 | 94 | : mTarget(aTarget) |
michael@0 | 95 | , mTable(aTable) |
michael@0 | 96 | { } |
michael@0 | 97 | |
michael@0 | 98 | NS_DECL_NSIRUNNABLE |
michael@0 | 99 | |
michael@0 | 100 | private: |
michael@0 | 101 | nsCOMPtr<nsIUrlClassifierDBServiceWorker> mTarget; |
michael@0 | 102 | nsCString mTable; |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | class UpdateStreamRunnable : public nsRunnable |
michael@0 | 106 | { |
michael@0 | 107 | public: |
michael@0 | 108 | UpdateStreamRunnable(nsIUrlClassifierDBServiceWorker* aTarget, |
michael@0 | 109 | const nsACString& aUpdateChunk) |
michael@0 | 110 | : mTarget(aTarget) |
michael@0 | 111 | , mUpdateChunk(aUpdateChunk) |
michael@0 | 112 | { } |
michael@0 | 113 | |
michael@0 | 114 | NS_DECL_NSIRUNNABLE |
michael@0 | 115 | |
michael@0 | 116 | private: |
michael@0 | 117 | nsCOMPtr<nsIUrlClassifierDBServiceWorker> mTarget; |
michael@0 | 118 | nsCString mUpdateChunk; |
michael@0 | 119 | }; |
michael@0 | 120 | |
michael@0 | 121 | class CacheCompletionsRunnable : public nsRunnable |
michael@0 | 122 | { |
michael@0 | 123 | public: |
michael@0 | 124 | CacheCompletionsRunnable(nsIUrlClassifierDBServiceWorker* aTarget, |
michael@0 | 125 | mozilla::safebrowsing::CacheResultArray *aEntries) |
michael@0 | 126 | : mTarget(aTarget) |
michael@0 | 127 | , mEntries(aEntries) |
michael@0 | 128 | { } |
michael@0 | 129 | |
michael@0 | 130 | NS_DECL_NSIRUNNABLE |
michael@0 | 131 | |
michael@0 | 132 | private: |
michael@0 | 133 | nsCOMPtr<nsIUrlClassifierDBServiceWorker> mTarget; |
michael@0 | 134 | mozilla::safebrowsing::CacheResultArray *mEntries; |
michael@0 | 135 | }; |
michael@0 | 136 | |
michael@0 | 137 | class CacheMissesRunnable : public nsRunnable |
michael@0 | 138 | { |
michael@0 | 139 | public: |
michael@0 | 140 | CacheMissesRunnable(nsIUrlClassifierDBServiceWorker* aTarget, |
michael@0 | 141 | mozilla::safebrowsing::PrefixArray *aEntries) |
michael@0 | 142 | : mTarget(aTarget) |
michael@0 | 143 | , mEntries(aEntries) |
michael@0 | 144 | { } |
michael@0 | 145 | |
michael@0 | 146 | NS_DECL_NSIRUNNABLE |
michael@0 | 147 | |
michael@0 | 148 | private: |
michael@0 | 149 | nsCOMPtr<nsIUrlClassifierDBServiceWorker> mTarget; |
michael@0 | 150 | mozilla::safebrowsing::PrefixArray *mEntries; |
michael@0 | 151 | }; |
michael@0 | 152 | |
michael@0 | 153 | private: |
michael@0 | 154 | nsCOMPtr<nsIUrlClassifierDBServiceWorker> mTarget; |
michael@0 | 155 | }; |
michael@0 | 156 | |
michael@0 | 157 | // The remaining classes here are all proxies to the main thread |
michael@0 | 158 | |
michael@0 | 159 | class UrlClassifierLookupCallbackProxy MOZ_FINAL : |
michael@0 | 160 | public nsIUrlClassifierLookupCallback |
michael@0 | 161 | { |
michael@0 | 162 | public: |
michael@0 | 163 | UrlClassifierLookupCallbackProxy(nsIUrlClassifierLookupCallback* aTarget) |
michael@0 | 164 | : mTarget(new nsMainThreadPtrHolder<nsIUrlClassifierLookupCallback>(aTarget)) |
michael@0 | 165 | { } |
michael@0 | 166 | |
michael@0 | 167 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 168 | NS_DECL_NSIURLCLASSIFIERLOOKUPCALLBACK |
michael@0 | 169 | |
michael@0 | 170 | class LookupCompleteRunnable : public nsRunnable |
michael@0 | 171 | { |
michael@0 | 172 | public: |
michael@0 | 173 | LookupCompleteRunnable(const nsMainThreadPtrHandle<nsIUrlClassifierLookupCallback>& aTarget, |
michael@0 | 174 | mozilla::safebrowsing::LookupResultArray *aResults) |
michael@0 | 175 | : mTarget(aTarget) |
michael@0 | 176 | , mResults(aResults) |
michael@0 | 177 | { } |
michael@0 | 178 | |
michael@0 | 179 | NS_DECL_NSIRUNNABLE |
michael@0 | 180 | |
michael@0 | 181 | private: |
michael@0 | 182 | nsMainThreadPtrHandle<nsIUrlClassifierLookupCallback> mTarget; |
michael@0 | 183 | mozilla::safebrowsing::LookupResultArray * mResults; |
michael@0 | 184 | }; |
michael@0 | 185 | |
michael@0 | 186 | private: |
michael@0 | 187 | nsMainThreadPtrHandle<nsIUrlClassifierLookupCallback> mTarget; |
michael@0 | 188 | }; |
michael@0 | 189 | |
michael@0 | 190 | class UrlClassifierCallbackProxy MOZ_FINAL : public nsIUrlClassifierCallback |
michael@0 | 191 | { |
michael@0 | 192 | public: |
michael@0 | 193 | UrlClassifierCallbackProxy(nsIUrlClassifierCallback* aTarget) |
michael@0 | 194 | : mTarget(new nsMainThreadPtrHolder<nsIUrlClassifierCallback>(aTarget)) |
michael@0 | 195 | { } |
michael@0 | 196 | |
michael@0 | 197 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 198 | NS_DECL_NSIURLCLASSIFIERCALLBACK |
michael@0 | 199 | |
michael@0 | 200 | class HandleEventRunnable : public nsRunnable |
michael@0 | 201 | { |
michael@0 | 202 | public: |
michael@0 | 203 | HandleEventRunnable(const nsMainThreadPtrHandle<nsIUrlClassifierCallback>& aTarget, |
michael@0 | 204 | const nsACString& aValue) |
michael@0 | 205 | : mTarget(aTarget) |
michael@0 | 206 | , mValue(aValue) |
michael@0 | 207 | { } |
michael@0 | 208 | |
michael@0 | 209 | NS_DECL_NSIRUNNABLE |
michael@0 | 210 | |
michael@0 | 211 | private: |
michael@0 | 212 | nsMainThreadPtrHandle<nsIUrlClassifierCallback> mTarget; |
michael@0 | 213 | nsCString mValue; |
michael@0 | 214 | }; |
michael@0 | 215 | |
michael@0 | 216 | private: |
michael@0 | 217 | nsMainThreadPtrHandle<nsIUrlClassifierCallback> mTarget; |
michael@0 | 218 | }; |
michael@0 | 219 | |
michael@0 | 220 | class UrlClassifierUpdateObserverProxy MOZ_FINAL : |
michael@0 | 221 | public nsIUrlClassifierUpdateObserver |
michael@0 | 222 | { |
michael@0 | 223 | public: |
michael@0 | 224 | UrlClassifierUpdateObserverProxy(nsIUrlClassifierUpdateObserver* aTarget) |
michael@0 | 225 | : mTarget(new nsMainThreadPtrHolder<nsIUrlClassifierUpdateObserver>(aTarget)) |
michael@0 | 226 | { } |
michael@0 | 227 | |
michael@0 | 228 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 229 | NS_DECL_NSIURLCLASSIFIERUPDATEOBSERVER |
michael@0 | 230 | |
michael@0 | 231 | class UpdateUrlRequestedRunnable : public nsRunnable |
michael@0 | 232 | { |
michael@0 | 233 | public: |
michael@0 | 234 | UpdateUrlRequestedRunnable(const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver>& aTarget, |
michael@0 | 235 | const nsACString& aURL, |
michael@0 | 236 | const nsACString& aTable) |
michael@0 | 237 | : mTarget(aTarget) |
michael@0 | 238 | , mURL(aURL) |
michael@0 | 239 | , mTable(aTable) |
michael@0 | 240 | { } |
michael@0 | 241 | |
michael@0 | 242 | NS_DECL_NSIRUNNABLE |
michael@0 | 243 | |
michael@0 | 244 | private: |
michael@0 | 245 | nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget; |
michael@0 | 246 | nsCString mURL, mTable; |
michael@0 | 247 | }; |
michael@0 | 248 | |
michael@0 | 249 | class StreamFinishedRunnable : public nsRunnable |
michael@0 | 250 | { |
michael@0 | 251 | public: |
michael@0 | 252 | StreamFinishedRunnable(const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver>& aTarget, |
michael@0 | 253 | nsresult aStatus, uint32_t aDelay) |
michael@0 | 254 | : mTarget(aTarget) |
michael@0 | 255 | , mStatus(aStatus) |
michael@0 | 256 | , mDelay(aDelay) |
michael@0 | 257 | { } |
michael@0 | 258 | |
michael@0 | 259 | NS_DECL_NSIRUNNABLE |
michael@0 | 260 | |
michael@0 | 261 | private: |
michael@0 | 262 | nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget; |
michael@0 | 263 | nsresult mStatus; |
michael@0 | 264 | uint32_t mDelay; |
michael@0 | 265 | }; |
michael@0 | 266 | |
michael@0 | 267 | class UpdateErrorRunnable : public nsRunnable |
michael@0 | 268 | { |
michael@0 | 269 | public: |
michael@0 | 270 | UpdateErrorRunnable(const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver>& aTarget, |
michael@0 | 271 | nsresult aError) |
michael@0 | 272 | : mTarget(aTarget) |
michael@0 | 273 | , mError(aError) |
michael@0 | 274 | { } |
michael@0 | 275 | |
michael@0 | 276 | NS_DECL_NSIRUNNABLE |
michael@0 | 277 | |
michael@0 | 278 | private: |
michael@0 | 279 | nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget; |
michael@0 | 280 | nsresult mError; |
michael@0 | 281 | }; |
michael@0 | 282 | |
michael@0 | 283 | class UpdateSuccessRunnable : public nsRunnable |
michael@0 | 284 | { |
michael@0 | 285 | public: |
michael@0 | 286 | UpdateSuccessRunnable(const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver>& aTarget, |
michael@0 | 287 | uint32_t aRequestedTimeout) |
michael@0 | 288 | : mTarget(aTarget) |
michael@0 | 289 | , mRequestedTimeout(aRequestedTimeout) |
michael@0 | 290 | { } |
michael@0 | 291 | |
michael@0 | 292 | NS_DECL_NSIRUNNABLE |
michael@0 | 293 | |
michael@0 | 294 | private: |
michael@0 | 295 | nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget; |
michael@0 | 296 | uint32_t mRequestedTimeout; |
michael@0 | 297 | }; |
michael@0 | 298 | |
michael@0 | 299 | private: |
michael@0 | 300 | nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget; |
michael@0 | 301 | }; |
michael@0 | 302 | |
michael@0 | 303 | #endif // nsUrlClassifierProxies_h |