1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MANAGER_MAC_H_
6 #define CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MANAGER_MAC_H_
8 #include "apps/app_shim/extension_app_shim_handler_mac.h"
9 #include "base/memory/ref_counted.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "ipc/ipc_channel_factory.h"
18 class AppShimHostManagerTestApi
;
21 // The AppShimHostManager receives connections from app shims on a UNIX
22 // socket (|factory_|) and creates a helper object to manage the connection.
23 class AppShimHostManager
24 : public IPC::ChannelFactory::Delegate
,
25 public base::RefCountedThreadSafe
<
26 AppShimHostManager
, content::BrowserThread::DeleteOnUIThread
> {
30 // Init passes this AppShimHostManager to PostTask which requires it to have
31 // a non-zero refcount. Therefore, Init cannot be called in the constructor
32 // since the refcount is zero at that point.
35 apps::ExtensionAppShimHandler
* extension_app_shim_handler() {
36 return &extension_app_shim_handler_
;
40 friend class base::RefCountedThreadSafe
<AppShimHostManager
>;
41 friend struct content::BrowserThread::DeleteOnThread
<
42 content::BrowserThread::UI
>;
43 friend class base::DeleteHelper
<AppShimHostManager
>;
44 friend class test::AppShimHostManagerTestApi
;
45 virtual ~AppShimHostManager();
47 // IPC::ChannelFactory::Delegate implementation.
48 virtual void OnClientConnected(const IPC::ChannelHandle
& handle
) OVERRIDE
;
49 virtual void OnListenError() OVERRIDE
;
51 // The |factory_| must be created on a thread which allows blocking I/O, so
52 // part of the initialization of this class must be carried out on the file
54 void InitOnFileThread();
56 // Called on the IO thread to begin listening for connections from app shims.
57 void ListenOnIOThread();
59 // If set, used instead of chrome::DIR_USER_DATA for placing the socket.
60 static const base::FilePath
* g_override_user_data_dir_
;
62 scoped_ptr
<IPC::ChannelFactory
> factory_
;
64 apps::ExtensionAppShimHandler extension_app_shim_handler_
;
66 DISALLOW_COPY_AND_ASSIGN(AppShimHostManager
);
69 #endif // CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MANAGER_MAC_H_