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

Side by Side Diff: apps/app_shim/chrome_main_app_mode_mac.mm

Issue 66043003: Put app shim IPC socket in a temporary directory. (Mac) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Put App Shim Socket in "/tmp/chrome-<hash of UDD>/", make a symlink to it at "<UDD>/App Shim Socket… Created 6 years, 11 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 // On Mac, one can't make shortcuts with command-line arguments. Instead, we 5 // On Mac, one can't make shortcuts with command-line arguments. Instead, we
6 // produce small app bundles which locate the Chromium framework and load it, 6 // produce small app bundles which locate the Chromium framework and load it,
7 // passing the appropriate data. This is the entry point into the framework for 7 // passing the appropriate data. This is the entry point into the framework for
8 // those app bundles. 8 // those app bundles.
9 9
10 #import <Cocoa/Cocoa.h> 10 #import <Cocoa/Cocoa.h>
11 #include <vector> 11 #include <vector>
12 12
13 #include "apps/app_shim/app_shim_messages.h" 13 #include "apps/app_shim/app_shim_messages.h"
14 #include "base/at_exit.h" 14 #include "base/at_exit.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/file_util.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/mac/bundle_locations.h" 19 #include "base/mac/bundle_locations.h"
19 #include "base/mac/foundation_util.h" 20 #include "base/mac/foundation_util.h"
20 #include "base/mac/launch_services_util.h" 21 #include "base/mac/launch_services_util.h"
21 #include "base/mac/mac_logging.h" 22 #include "base/mac/mac_logging.h"
22 #include "base/mac/mac_util.h" 23 #include "base/mac/mac_util.h"
23 #include "base/mac/scoped_nsautorelease_pool.h" 24 #include "base/mac/scoped_nsautorelease_pool.h"
24 #include "base/mac/scoped_nsobject.h" 25 #include "base/mac/scoped_nsobject.h"
25 #include "base/message_loop/message_loop.h" 26 #include "base/message_loop/message_loop.h"
26 #include "base/path_service.h" 27 #include "base/path_service.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // was sent, or when the ping fails (if |success| is false). 103 // was sent, or when the ping fails (if |success| is false).
103 void OnPingChromeReply(bool success); 104 void OnPingChromeReply(bool success);
104 105
105 // Called |kPingChromeTimeoutSeconds| after startup, to allow a timeout on the 106 // Called |kPingChromeTimeoutSeconds| after startup, to allow a timeout on the
106 // ping event to be detected. 107 // ping event to be detected.
107 void OnPingChromeTimeout(); 108 void OnPingChromeTimeout();
108 109
109 // Connects to Chrome and sends a LaunchApp message. 110 // Connects to Chrome and sends a LaunchApp message.
110 void Init(); 111 void Init();
111 112
113 // Create a channel from |socket_path| and send a LaunchApp message.
114 // This may be called multiple times at startup to try to connect to different
115 // paths.
116 void CreateChannelAndSendLaunchApp(const base::FilePath& socket_path);
117
112 // Builds main menu bar items. 118 // Builds main menu bar items.
113 void SetUpMenu(); 119 void SetUpMenu();
114 120
115 void SendSetAppHidden(bool hidden); 121 void SendSetAppHidden(bool hidden);
116 122
117 void SendQuitApp(); 123 void SendQuitApp();
118 124
119 // Called when the app is activated, e.g. by clicking on it in the dock, by 125 // Called when the app is activated, e.g. by clicking on it in the dock, by
120 // dropping a file on the dock icon, or by Cmd+Tabbing to it. 126 // dropping a file on the dock icon, or by Cmd+Tabbing to it.
121 // Returns whether the message was sent. 127 // Returns whether the message was sent.
(...skipping 11 matching lines...) Expand all
133 139
134 // Hide this app. 140 // Hide this app.
135 void OnHide(); 141 void OnHide();
136 142
137 // Requests user attention. 143 // Requests user attention.
138 void OnRequestUserAttention(); 144 void OnRequestUserAttention();
139 145
140 // Terminates the app shim process. 146 // Terminates the app shim process.
141 void Close(); 147 void Close();
142 148
143 IPC::ChannelProxy* channel_; 149 base::FilePath user_data_dir_;
150 scoped_ptr<IPC::ChannelProxy> channel_;
144 base::scoped_nsobject<AppShimDelegate> delegate_; 151 base::scoped_nsobject<AppShimDelegate> delegate_;
145 bool launch_app_done_; 152 bool launch_app_done_;
146 bool ping_chrome_reply_received_; 153 bool ping_chrome_reply_received_;
147 154
148 DISALLOW_COPY_AND_ASSIGN(AppShimController); 155 DISALLOW_COPY_AND_ASSIGN(AppShimController);
149 }; 156 };
150 157
151 AppShimController::AppShimController() 158 AppShimController::AppShimController()
152 : channel_(NULL), 159 : delegate_([[AppShimDelegate alloc] init]),
153 delegate_([[AppShimDelegate alloc] init]),
154 launch_app_done_(false), 160 launch_app_done_(false),
155 ping_chrome_reply_received_(false) { 161 ping_chrome_reply_received_(false) {
156 // Since AppShimController is created before the main message loop starts, 162 // Since AppShimController is created before the main message loop starts,
157 // NSApp will not be set, so use sharedApplication. 163 // NSApp will not be set, so use sharedApplication.
158 [[NSApplication sharedApplication] setDelegate:delegate_]; 164 [[NSApplication sharedApplication] setDelegate:delegate_];
159 } 165 }
160 166
161 AppShimController::~AppShimController() { 167 AppShimController::~AppShimController() {
162 // Un-set the delegate since NSApplication does not retain it. 168 // Un-set the delegate since NSApplication does not retain it.
163 [NSApp setDelegate:nil]; 169 [NSApp setDelegate:nil];
(...skipping 18 matching lines...) Expand all
182 DCHECK(g_io_thread); 188 DCHECK(g_io_thread);
183 189
184 SetUpMenu(); 190 SetUpMenu();
185 191
186 // Chrome will relaunch shims when relaunching apps. 192 // Chrome will relaunch shims when relaunching apps.
187 if (base::mac::IsOSLionOrLater()) 193 if (base::mac::IsOSLionOrLater())
188 [NSApp disableRelaunchOnLogin]; 194 [NSApp disableRelaunchOnLogin];
189 195
190 // The user_data_dir for shims actually contains the app_data_path. 196 // The user_data_dir for shims actually contains the app_data_path.
191 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/ 197 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/
192 base::FilePath user_data_dir = 198 user_data_dir_ = g_info->user_data_dir.DirName().DirName().DirName();
193 g_info->user_data_dir.DirName().DirName().DirName(); 199 CHECK(!user_data_dir_.empty());
194 CHECK(!user_data_dir.empty());
195 200
196 base::FilePath socket_path = 201 base::FilePath symlink_path =
197 user_data_dir.Append(app_mode::kAppShimSocketName); 202 user_data_dir_.Append(app_mode::kAppShimSocketName);
203
204 base::FilePath socket_path;
205 if (!base::ReadSymbolicLink(symlink_path, &socket_path)) {
206 CreateChannelAndSendLaunchApp(symlink_path);
tapted 2014/01/03 13:06:54 nit: maybe a comment here: ~"if the path in the us
jackhou1 2014/01/06 05:29:52 Done.
207 return;
208 }
209
210 app_mode::VerifySocketPermissions(socket_path);
211
212 CreateChannelAndSendLaunchApp(socket_path);
213 }
214
215 void AppShimController::CreateChannelAndSendLaunchApp(
216 const base::FilePath& socket_path) {
198 IPC::ChannelHandle handle(socket_path.value()); 217 IPC::ChannelHandle handle(socket_path.value());
199 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, 218 channel_.reset(new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT,
200 this, g_io_thread->message_loop_proxy().get()); 219 this, g_io_thread->message_loop_proxy().get()));
201 220
202 bool launched_by_chrome = 221 bool launched_by_chrome =
203 CommandLine::ForCurrentProcess()->HasSwitch( 222 CommandLine::ForCurrentProcess()->HasSwitch(
204 app_mode::kLaunchedByChromeProcessId); 223 app_mode::kLaunchedByChromeProcessId);
205 apps::AppShimLaunchType launch_type = launched_by_chrome ? 224 apps::AppShimLaunchType launch_type = launched_by_chrome ?
206 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL; 225 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL;
207 226
208 [delegate_ setController:this]; 227 [delegate_ setController:this];
209 228
210 std::vector<base::FilePath> files; 229 std::vector<base::FilePath> files;
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 // minute. 656 // minute.
638 main_message_loop.PostTask( 657 main_message_loop.PostTask(
639 FROM_HERE, 658 FROM_HERE,
640 base::Bind(&AppShimController::Init, 659 base::Bind(&AppShimController::Init,
641 base::Unretained(&controller))); 660 base::Unretained(&controller)));
642 } 661 }
643 662
644 main_message_loop.Run(); 663 main_message_loop.Run();
645 return 0; 664 return 0;
646 } 665 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698