Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: apps/app_shim/app_shim_host_mac.h

Issue 15269003: Refactor extension handling code from AppShimHost into ExtensionAppShimHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « apps/app_shim/app_shim_handler_mac.cc ('k') | apps/app_shim/app_shim_host_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "apps/app_shim/app_shim_handler_mac.h" 10 #include "apps/app_shim/app_shim_handler_mac.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/non_thread_safe.h" 12 #include "base/threading/non_thread_safe.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "ipc/ipc_listener.h" 13 #include "ipc/ipc_listener.h"
16 #include "ipc/ipc_sender.h" 14 #include "ipc/ipc_sender.h"
17 15
18 class Profile; 16 class Profile;
19 17
20 namespace IPC { 18 namespace IPC {
21 struct ChannelHandle; 19 struct ChannelHandle;
22 class ChannelProxy; 20 class ChannelProxy;
23 class Message; 21 class Message;
24 } // namespace IPC 22 } // namespace IPC
25 23
26 // This is the counterpart to AppShimController in 24 // This is the counterpart to AppShimController in
27 // chrome/app/chrome_main_app_mode_mac.mm. The AppShimHost owns itself, and is 25 // chrome/app/chrome_main_app_mode_mac.mm. The AppShimHost owns itself, and is
28 // destroyed when the app it corresponds to is closed or when the channel 26 // destroyed when the app it corresponds to is closed or when the channel
29 // connected to the app shim is closed. 27 // connected to the app shim is closed.
30 class AppShimHost : public IPC::Listener, 28 class AppShimHost : public IPC::Listener,
31 public IPC::Sender, 29 public IPC::Sender,
32 public apps::AppShimHandler::Host, 30 public apps::AppShimHandler::Host,
33 public content::NotificationObserver,
34 public base::NonThreadSafe { 31 public base::NonThreadSafe {
35 public: 32 public:
36 AppShimHost(); 33 AppShimHost();
37 virtual ~AppShimHost(); 34 virtual ~AppShimHost();
38 35
39 // Creates a new server-side IPC channel at |handle|, which should contain a 36 // Creates a new server-side IPC channel at |handle|, which should contain a
40 // file descriptor of a channel created by an IPC::ChannelFactory, and begins 37 // file descriptor of a channel created by an IPC::ChannelFactory, and begins
41 // listening for messages on it. 38 // listening for messages on it.
42 void ServeChannel(const IPC::ChannelHandle& handle); 39 void ServeChannel(const IPC::ChannelHandle& handle);
43 40
44 protected: 41 protected:
45 const std::string& app_id() const { return app_id_; }
46 const Profile* profile() const { return profile_; }
47 42
48 // Used internally; virtual so they can be mocked for testing. 43 // Used internally; virtual so they can be mocked for testing.
49 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir); 44 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir);
50 virtual bool LaunchApp(Profile* profile);
51 45
52 // IPC::Listener implementation. 46 // IPC::Listener implementation.
53 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 47 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
54 virtual void OnChannelError() OVERRIDE; 48 virtual void OnChannelError() OVERRIDE;
55 49
56 // IPC::Sender implementation. 50 // IPC::Sender implementation.
57 virtual bool Send(IPC::Message* message) OVERRIDE; 51 virtual bool Send(IPC::Message* message) OVERRIDE;
58 52
59 private: 53 private:
60 // The app shim process is requesting that an app be launched. Once it has 54 // The app shim process is requesting that an app be launched. Once it has
61 // done so the |profile| and |app_id| are stored, and all future messages 55 // done so the |profile| and |app_id| are stored, and all future messages
62 // from the app shim relate to the app it launched. It is an error for the 56 // from the app shim relate to the app it launched. It is an error for the
63 // app shim to send multiple launch messages. 57 // app shim to send multiple launch messages.
64 void OnLaunchApp(std::string profile, std::string app_id); 58 void OnLaunchApp(std::string profile, std::string app_id);
65 59
66 // Called when the app shim process notifies that the app should be brought 60 // Called when the app shim process notifies that the app should be brought
67 // to the front (i.e. the user has clicked on the app's icon in the dock or 61 // to the front (i.e. the user has clicked on the app's icon in the dock or
68 // Cmd+Tabbed to it.) 62 // Cmd+Tabbed to it.)
69 void OnFocus(); 63 void OnFocus();
70 64
71 bool LaunchAppImpl(const std::string& profile_dir); 65 // apps::AppShimHandler::Host overrides:
72
73 // The AppShimHost listens to the NOTIFICATION_EXTENSION_HOST_DESTROYED
74 // message to detect when the app closes. When that happens, the AppShimHost
75 // closes the channel, which causes the app shim process to quit.
76 virtual void Observe(int type,
77 const content::NotificationSource& source,
78 const content::NotificationDetails& details) OVERRIDE;
79
80 // apps::AppShimHandler::Host override:
81 virtual void OnAppClosed() OVERRIDE; 66 virtual void OnAppClosed() OVERRIDE;
67 virtual Profile* GetProfile() const OVERRIDE;
68 virtual std::string GetAppId() const OVERRIDE;
82 69
83 // Closes the channel and destroys the AppShimHost. 70 // Closes the channel and destroys the AppShimHost.
84 void Close(); 71 void Close();
85 72
86 scoped_ptr<IPC::ChannelProxy> channel_; 73 scoped_ptr<IPC::ChannelProxy> channel_;
87 std::string app_id_; 74 std::string app_id_;
88 Profile* profile_; 75 Profile* profile_;
89 content::NotificationRegistrar registrar_;
90 }; 76 };
91 77
92 #endif // CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_ 78 #endif // CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_
OLDNEW
« no previous file with comments | « apps/app_shim/app_shim_handler_mac.cc ('k') | apps/app_shim/app_shim_host_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698