Home | History | Annotate | Download | only in app_shim
      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.
      4 
      5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MANAGER_MAC_H_
      6 #define CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MANAGER_MAC_H_
      7 
      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"
     12 
     13 namespace base {
     14 class FilePath;
     15 }
     16 
     17 namespace test {
     18 class AppShimHostManagerTestApi;
     19 }
     20 
     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> {
     27  public:
     28   AppShimHostManager();
     29 
     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.
     33   void Init();
     34 
     35   apps::ExtensionAppShimHandler* extension_app_shim_handler() {
     36     return &extension_app_shim_handler_;
     37   }
     38 
     39  private:
     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();
     46 
     47   // IPC::ChannelFactory::Delegate implementation.
     48   virtual void OnClientConnected(const IPC::ChannelHandle& handle) OVERRIDE;
     49   virtual void OnListenError() OVERRIDE;
     50 
     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
     53   // thread.
     54   void InitOnFileThread();
     55 
     56   // Called on the IO thread to begin listening for connections from app shims.
     57   void ListenOnIOThread();
     58 
     59   // If set, used instead of chrome::DIR_USER_DATA for placing the socket.
     60   static const base::FilePath* g_override_user_data_dir_;
     61 
     62   scoped_ptr<IPC::ChannelFactory> factory_;
     63 
     64   apps::ExtensionAppShimHandler extension_app_shim_handler_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(AppShimHostManager);
     67 };
     68 
     69 #endif  // CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MANAGER_MAC_H_
     70