Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include <stdio.h> |
michael@0 | 6 | #include <windows.h> |
michael@0 | 7 | #include "sandbox/win/src/sandbox.h" |
michael@0 | 8 | #include "sandbox/win/src/sandbox_factory.h" |
michael@0 | 9 | #include "sandbox/win/src/broker_services.h" |
michael@0 | 10 | #include "sandbox/win/src/target_services.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace sandbox { |
michael@0 | 13 | // The section for IPC and policy. |
michael@0 | 14 | SANDBOX_INTERCEPT HANDLE g_shared_section = NULL; |
michael@0 | 15 | |
michael@0 | 16 | static bool s_is_broker = false; |
michael@0 | 17 | |
michael@0 | 18 | // GetBrokerServices: the current implementation relies on a shared section |
michael@0 | 19 | // that is created by the broker and opened by the target. |
michael@0 | 20 | BrokerServices* SandboxFactory::GetBrokerServices() { |
michael@0 | 21 | // Can't be the broker if the shared section is open. |
michael@0 | 22 | if (NULL != g_shared_section) { |
michael@0 | 23 | return NULL; |
michael@0 | 24 | } |
michael@0 | 25 | // If the shared section does not exist we are the broker, then create |
michael@0 | 26 | // the broker object. |
michael@0 | 27 | s_is_broker = true; |
michael@0 | 28 | return BrokerServicesBase::GetInstance(); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | // GetTargetServices implementation must follow the same technique as the |
michael@0 | 32 | // GetBrokerServices, but in this case the logic is the opposite. |
michael@0 | 33 | TargetServices* SandboxFactory::GetTargetServices() { |
michael@0 | 34 | // Can't be the target if the section handle is not valid. |
michael@0 | 35 | if (NULL == g_shared_section) { |
michael@0 | 36 | return NULL; |
michael@0 | 37 | } |
michael@0 | 38 | // We are the target |
michael@0 | 39 | s_is_broker = false; |
michael@0 | 40 | // Creates and returns the target services implementation. |
michael@0 | 41 | return TargetServicesBase::GetInstance(); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | } // namespace sandbox |