15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef SANDBOX_SRC_SANDBOX_FACTORY_H__ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SANDBOX_SRC_SANDBOX_FACTORY_H__ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sandbox/win/src/sandbox.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SandboxFactory is a set of static methods to get access to the broker 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// or target services object. Only one of the two methods (GetBrokerServices, 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// GetTargetServices) will return a non-null pointer and that should be used 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// as the indication that the process is the broker or the target: 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// BrokerServices* broker_services = SandboxFactory::GetBrokerServices(); 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// if (NULL != broker_services) { 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// //we are the broker, call broker api here 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// broker_services->Init(); 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// } else { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TargetServices* target_services = SandboxFactory::GetTargetServices(); 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// if (NULL != target_services) { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// //we are the target, call target api here 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// target_services->Init(); 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// } 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The methods in this class are expected to be called from a single thread 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The Sandbox library needs to be linked against the main executable, but 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// sometimes the API calls are issued from a DLL that loads into the exe 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// process. These factory methods then need to be called from the main 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// exe and the interface pointers then can be safely passed to the DLL where 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the Sandbox API calls are made. 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace sandbox { 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SandboxFactory { 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the Broker API interface, returns NULL if this process is the 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // target. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static BrokerServices* GetBrokerServices(); 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the Target API interface, returns NULL if this process is the 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // broker. 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static TargetServices* GetTargetServices(); 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_IMPLICIT_CONSTRUCTORS(SandboxFactory); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace sandbox 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // SANDBOX_SRC_SANDBOX_FACTORY_H__ 51