media/mtransport/transportlayer.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 // Original author: ekr@rtfm.com
michael@0 8 #include "logging.h"
michael@0 9 #include "transportflow.h"
michael@0 10 #include "transportlayer.h"
michael@0 11 #include "nsThreadUtils.h"
michael@0 12
michael@0 13 // Logging context
michael@0 14 namespace mozilla {
michael@0 15
michael@0 16 MOZ_MTLOG_MODULE("mtransport")
michael@0 17
michael@0 18 nsresult TransportLayer::Init() {
michael@0 19 if (state_ != TS_NONE)
michael@0 20 return state_ == TS_ERROR ? NS_ERROR_FAILURE : NS_OK;
michael@0 21
michael@0 22 nsresult rv = InitInternal();
michael@0 23
michael@0 24 if (!NS_SUCCEEDED(rv)) {
michael@0 25 state_ = TS_ERROR;
michael@0 26 return rv;
michael@0 27 }
michael@0 28 state_ = TS_INIT;
michael@0 29
michael@0 30 return NS_OK;
michael@0 31 }
michael@0 32
michael@0 33 void TransportLayer::Inserted(TransportFlow *flow, TransportLayer *downward) {
michael@0 34 downward_ = downward;
michael@0 35 flow_id_ = flow->id();
michael@0 36 MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Inserted: downward='" <<
michael@0 37 (downward ? downward->id(): "none") << "'");
michael@0 38
michael@0 39 WasInserted();
michael@0 40 }
michael@0 41
michael@0 42 void TransportLayer::SetState(State state, const char *file, unsigned line) {
michael@0 43 if (state != state_) {
michael@0 44 MOZ_MTLOG(state == TS_ERROR ? ML_ERROR : ML_DEBUG,
michael@0 45 file << ":" << line << ": " <<
michael@0 46 LAYER_INFO << "state " << state_ << "->" << state);
michael@0 47 state_ = state;
michael@0 48 SignalStateChange(this, state);
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 nsresult TransportLayer::RunOnThread(nsIRunnable *event) {
michael@0 53 if (target_) {
michael@0 54 nsIThread *thr;
michael@0 55
michael@0 56 DebugOnly<nsresult> rv = NS_GetCurrentThread(&thr);
michael@0 57 MOZ_ASSERT(NS_SUCCEEDED(rv));
michael@0 58
michael@0 59 if (target_ != thr) {
michael@0 60 return target_->Dispatch(event, NS_DISPATCH_SYNC);
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64 return event->Run();
michael@0 65 }
michael@0 66
michael@0 67 } // close namespace

mercurial