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