/src/mozilla-central/dom/cache/ManagerId.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "mozilla/dom/cache/ManagerId.h" |
8 | | #include "mozilla/dom/quota/QuotaManager.h" |
9 | | #include "nsIPrincipal.h" |
10 | | #include "nsProxyRelease.h" |
11 | | #include "mozilla/RefPtr.h" |
12 | | #include "nsThreadUtils.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | namespace cache { |
17 | | |
18 | | using mozilla::dom::quota::QuotaManager; |
19 | | |
20 | | // static |
21 | | nsresult |
22 | | ManagerId::Create(nsIPrincipal* aPrincipal, ManagerId** aManagerIdOut) |
23 | 0 | { |
24 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
25 | 0 |
|
26 | 0 | // The QuotaManager::GetInfoFromPrincipal() has special logic for system |
27 | 0 | // and about: principals. We need to use the same modified origin in |
28 | 0 | // order to interpret calls from QM correctly. |
29 | 0 | nsCString quotaOrigin; |
30 | 0 | nsresult rv = QuotaManager::GetInfoFromPrincipal(aPrincipal, |
31 | 0 | nullptr, // suffix |
32 | 0 | nullptr, // group |
33 | 0 | "aOrigin); |
34 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } |
35 | 0 | |
36 | 0 | RefPtr<ManagerId> ref = new ManagerId(aPrincipal, quotaOrigin); |
37 | 0 | ref.forget(aManagerIdOut); |
38 | 0 |
|
39 | 0 | return NS_OK; |
40 | 0 | } |
41 | | |
42 | | already_AddRefed<nsIPrincipal> |
43 | | ManagerId::Principal() const |
44 | 0 | { |
45 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
46 | 0 | nsCOMPtr<nsIPrincipal> ref = mPrincipal; |
47 | 0 | return ref.forget(); |
48 | 0 | } |
49 | | |
50 | | ManagerId::ManagerId(nsIPrincipal* aPrincipal, const nsACString& aQuotaOrigin) |
51 | | : mPrincipal(aPrincipal) |
52 | | , mQuotaOrigin(aQuotaOrigin) |
53 | 0 | { |
54 | 0 | MOZ_DIAGNOSTIC_ASSERT(mPrincipal); |
55 | 0 | } |
56 | | |
57 | | ManagerId::~ManagerId() |
58 | 0 | { |
59 | 0 | // If we're already on the main thread, then default destruction is fine |
60 | 0 | if (NS_IsMainThread()) { |
61 | 0 | return; |
62 | 0 | } |
63 | 0 | |
64 | 0 | // Otherwise we need to proxy to main thread to do the release |
65 | 0 | |
66 | 0 | // The PBackground worker thread shouldn't be running after the main thread |
67 | 0 | // is stopped. So main thread is guaranteed to exist here. |
68 | 0 | NS_ReleaseOnMainThreadSystemGroup( |
69 | 0 | "ManagerId::mPrincipal", mPrincipal.forget()); |
70 | 0 | } |
71 | | |
72 | | } // namespace cache |
73 | | } // namespace dom |
74 | | } // namespace mozilla |