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 APPS_APP_SHIM_APP_SHIM_HOST_MAC_H_
6 #define APPS_APP_SHIM_APP_SHIM_HOST_MAC_H_
11 #include "apps/app_shim/app_shim_handler_mac.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "ipc/ipc_listener.h"
16 #include "ipc/ipc_sender.h"
24 // This is the counterpart to AppShimController in
25 // chrome/app/chrome_main_app_mode_mac.mm. The AppShimHost owns itself, and is
26 // destroyed when the app it corresponds to is closed or when the channel
27 // connected to the app shim is closed.
28 class AppShimHost
: public IPC::Listener
,
30 public apps::AppShimHandler::Host
,
31 public base::NonThreadSafe
{
34 virtual ~AppShimHost();
36 // Creates a new server-side IPC channel at |handle|, which should contain a
37 // file descriptor of a channel created by an UnixDomainSocketAcceptor,
38 // and begins listening for messages on it.
39 void ServeChannel(const IPC::ChannelHandle
& handle
);
42 // IPC::Listener implementation.
43 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
44 virtual void OnChannelError() OVERRIDE
;
46 // IPC::Sender implementation.
47 virtual bool Send(IPC::Message
* message
) OVERRIDE
;
50 // The app shim process is requesting to be associated with the given profile
51 // and app_id. Once the profile and app_id are stored, and all future
52 // messages from the app shim relate to this app. The app is launched
53 // immediately if |launch_now| is true.
54 void OnLaunchApp(const base::FilePath
& profile_dir
,
55 const std::string
& app_id
,
56 apps::AppShimLaunchType launch_type
,
57 const std::vector
<base::FilePath
>& files
);
59 // Called when the app shim process notifies that the app was focused.
60 void OnFocus(apps::AppShimFocusType focus_type
,
61 const std::vector
<base::FilePath
>& files
);
63 void OnSetHidden(bool hidden
);
65 // Called when the app shim process notifies that the app should quit.
68 // apps::AppShimHandler::Host overrides:
69 virtual void OnAppLaunchComplete(apps::AppShimLaunchResult result
) OVERRIDE
;
70 virtual void OnAppClosed() OVERRIDE
;
71 virtual void OnAppHide() OVERRIDE
;
72 virtual void OnAppRequestUserAttention(
73 apps::AppShimAttentionType type
) OVERRIDE
;
74 virtual base::FilePath
GetProfilePath() const OVERRIDE
;
75 virtual std::string
GetAppId() const OVERRIDE
;
77 // Closes the channel and destroys the AppShimHost.
80 scoped_ptr
<IPC::ChannelProxy
> channel_
;
82 base::FilePath profile_path_
;
83 bool initial_launch_finished_
;
86 #endif // APPS_APP_SHIM_APP_SHIM_HOST_MAC_H_