| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_ | 5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_ |
| 6 #define CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_ | 6 #define CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
| 12 #include "chrome/browser/ui/app_list/app_list_dismiss_observer_mac.h" |
| 12 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 13 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
| 14 #include "ipc/ipc_listener.h" | 15 #include "ipc/ipc_listener.h" |
| 15 #include "ipc/ipc_sender.h" | 16 #include "ipc/ipc_sender.h" |
| 16 | 17 |
| 17 class Profile; | 18 class Profile; |
| 18 | 19 |
| 19 namespace IPC { | 20 namespace IPC { |
| 20 struct ChannelHandle; | 21 struct ChannelHandle; |
| 21 class ChannelProxy; | 22 class ChannelProxy; |
| 22 class Message; | 23 class Message; |
| 23 } // namespace IPC | 24 } // namespace IPC |
| 24 | 25 |
| 25 // This is the counterpart to AppShimController in | 26 // This is the counterpart to AppShimController in |
| 26 // chrome/app/chrome_main_app_mode_mac.mm. The AppShimHost owns itself, and is | 27 // chrome/app/chrome_main_app_mode_mac.mm. The AppShimHost owns itself, and is |
| 27 // destroyed when the app it corresponds to is closed or when the channel | 28 // destroyed when the app it corresponds to is closed or when the channel |
| 28 // connected to the app shim is closed. | 29 // connected to the app shim is closed. |
| 29 class AppShimHost : public IPC::Listener, | 30 class AppShimHost : public IPC::Listener, |
| 30 public IPC::Sender, | 31 public IPC::Sender, |
| 32 public chrome::AppListDismissObserverMac, |
| 31 public content::NotificationObserver, | 33 public content::NotificationObserver, |
| 32 public base::NonThreadSafe { | 34 public base::NonThreadSafe { |
| 33 public: | 35 public: |
| 34 AppShimHost(); | 36 AppShimHost(); |
| 35 virtual ~AppShimHost(); | 37 virtual ~AppShimHost(); |
| 36 | 38 |
| 37 // Creates a new server-side IPC channel at |handle|, which should contain a | 39 // Creates a new server-side IPC channel at |handle|, which should contain a |
| 38 // file descriptor of a channel created by an IPC::ChannelFactory, and begins | 40 // file descriptor of a channel created by an IPC::ChannelFactory, and begins |
| 39 // listening for messages on it. | 41 // listening for messages on it. |
| 40 void ServeChannel(const IPC::ChannelHandle& handle); | 42 void ServeChannel(const IPC::ChannelHandle& handle); |
| 41 | 43 |
| 42 const std::string& app_id() const { return app_id_; } | 44 const std::string& app_id() const { return app_id_; } |
| 43 const Profile* profile() const { return profile_; } | 45 const Profile* profile() const { return profile_; } |
| 44 | 46 |
| 45 protected: | 47 protected: |
| 46 // Used internally; virtual so they can be mocked for testing. | 48 // Used internally; virtual so they can be mocked for testing. |
| 47 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir); | 49 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir); |
| 48 virtual bool LaunchApp(Profile* profile, const std::string& app_id); | 50 virtual bool LaunchApp(Profile* profile, const std::string& app_id); |
| 49 | 51 |
| 50 // IPC::Listener implementation. | 52 // IPC::Listener implementation. |
| 51 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 53 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 54 virtual void OnChannelError() OVERRIDE; |
| 52 | 55 |
| 53 // IPC::Sender implementation. | 56 // IPC::Sender implementation. |
| 54 virtual bool Send(IPC::Message* message) OVERRIDE; | 57 virtual bool Send(IPC::Message* message) OVERRIDE; |
| 55 | 58 |
| 56 private: | 59 private: |
| 57 // The app shim process is requesting that an app be launched. Once it has | 60 // The app shim process is requesting that an app be launched. Once it has |
| 58 // done so the |profile| and |app_id| are stored, and all future messages | 61 // done so the |profile| and |app_id| are stored, and all future messages |
| 59 // from the app shim relate to the app it launched. It is an error for the | 62 // from the app shim relate to the app it launched. It is an error for the |
| 60 // app shim to send multiple launch messages. | 63 // app shim to send multiple launch messages. |
| 61 void OnLaunchApp(std::string profile, std::string app_id); | 64 void OnLaunchApp(std::string profile, std::string app_id); |
| 62 | 65 |
| 66 // The app shim process is requesting that the app list should be shown. |
| 67 void OnLaunchAppList(); |
| 68 |
| 63 // Called when the app shim process notifies that the app should be brought | 69 // Called when the app shim process notifies that the app should be brought |
| 64 // to the front (i.e. the user has clicked on the app's icon in the dock or | 70 // to the front (i.e. the user has clicked on the app's icon in the dock or |
| 65 // Cmd+Tabbed to it.) | 71 // Cmd+Tabbed to it.) |
| 66 void OnFocus(); | 72 void OnFocus(); |
| 67 | 73 |
| 68 bool LaunchAppImpl(const std::string& profile_dir, const std::string& app_id); | 74 bool LaunchAppImpl(const std::string& profile_dir, const std::string& app_id); |
| 69 | 75 |
| 70 // The AppShimHost listens to the NOTIFICATION_EXTENSION_HOST_DESTROYED | 76 // The AppShimHost listens to the NOTIFICATION_EXTENSION_HOST_DESTROYED |
| 71 // message to detect when the app closes. When that happens, the AppShimHost | 77 // message to detect when the app closes. When that happens, the AppShimHost |
| 72 // closes the channel, which causes the app shim process to quit. | 78 // closes the channel, which causes the app shim process to quit. |
| 73 virtual void Observe(int type, | 79 virtual void Observe(int type, |
| 74 const content::NotificationSource& source, | 80 const content::NotificationSource& source, |
| 75 const content::NotificationDetails& details) OVERRIDE; | 81 const content::NotificationDetails& details) OVERRIDE; |
| 76 | 82 |
| 83 // AppListDismissObserverMac override: |
| 84 virtual void OnAppListDismissed() OVERRIDE; |
| 85 |
| 77 // Closes the channel and destroys the AppShimHost. | 86 // Closes the channel and destroys the AppShimHost. |
| 78 void Close(); | 87 void Close(); |
| 79 | 88 |
| 80 scoped_ptr<IPC::ChannelProxy> channel_; | 89 scoped_ptr<IPC::ChannelProxy> channel_; |
| 81 std::string app_id_; | 90 std::string app_id_; |
| 82 Profile* profile_; | 91 Profile* profile_; |
| 92 bool is_app_list_; |
| 83 content::NotificationRegistrar registrar_; | 93 content::NotificationRegistrar registrar_; |
| 84 }; | 94 }; |
| 85 | 95 |
| 86 #endif // CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_ | 96 #endif // CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_ |
| OLD | NEW |