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

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: Add default handler to AppShimHandler. Fix test. 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
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_; } 42 virtual const std::string& app_id() const OVERRIDE;
tapted 2013/05/21 06:15:37 nit: move these to the same place as the other ove
jackhou1 2013/05/22 23:54:44 Done.
46 const Profile* profile() const { return profile_; } 43 virtual Profile* profile() const OVERRIDE;
47 44
48 // Used internally; virtual so they can be mocked for testing. 45 // Used internally; virtual so they can be mocked for testing.
49 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir); 46 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir);
50 virtual bool LaunchApp(Profile* profile);
51 47
52 // IPC::Listener implementation. 48 // IPC::Listener implementation.
53 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 49 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
54 virtual void OnChannelError() OVERRIDE; 50 virtual void OnChannelError() OVERRIDE;
55 51
56 // IPC::Sender implementation. 52 // IPC::Sender implementation.
57 virtual bool Send(IPC::Message* message) OVERRIDE; 53 virtual bool Send(IPC::Message* message) OVERRIDE;
58 54
59 private: 55 private:
60 // The app shim process is requesting that an app be launched. Once it has 56 // 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 57 // 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 58 // from the app shim relate to the app it launched. It is an error for the
63 // app shim to send multiple launch messages. 59 // app shim to send multiple launch messages.
64 void OnLaunchApp(std::string profile, std::string app_id); 60 void OnLaunchApp(std::string profile, std::string app_id);
65 61
66 // Called when the app shim process notifies that the app should be brought 62 // 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 63 // to the front (i.e. the user has clicked on the app's icon in the dock or
68 // Cmd+Tabbed to it.) 64 // Cmd+Tabbed to it.)
69 void OnFocus(); 65 void OnFocus();
70 66
71 bool LaunchAppImpl(const std::string& profile_dir);
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: 67 // apps::AppShimHandler::Host override:
81 virtual void OnAppClosed() OVERRIDE; 68 virtual void OnAppClosed() 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

Powered by Google App Engine
This is Rietveld 408576698