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

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: Use PostTask to delete file. Created 7 years, 1 month 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>
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // was sent, or when the ping fails (if |success| is false). 102 // was sent, or when the ping fails (if |success| is false).
103 void OnPingChromeReply(bool success); 103 void OnPingChromeReply(bool success);
104 104
105 // Called |kPingChromeTimeoutSeconds| after startup, to allow a timeout on the 105 // Called |kPingChromeTimeoutSeconds| after startup, to allow a timeout on the
106 // ping event to be detected. 106 // ping event to be detected.
107 void OnPingChromeTimeout(); 107 void OnPingChromeTimeout();
108 108
109 // Connects to Chrome and sends a LaunchApp message. 109 // Connects to Chrome and sends a LaunchApp message.
110 void Init(); 110 void Init();
111 111
112 // Create a channel from |socket_path| and send a LaunchApp message.
113 // This may be called multiple times at startup to try to connect to different
114 // paths.
115 void CreateChannelAndSendLaunchApp(const base::FilePath& socket_path);
116
112 // Builds main menu bar items. 117 // Builds main menu bar items.
113 void SetUpMenu(); 118 void SetUpMenu();
114 119
115 void SendSetAppHidden(bool hidden); 120 void SendSetAppHidden(bool hidden);
116 121
117 void SendQuitApp(); 122 void SendQuitApp();
118 123
119 // Called when the app is activated, e.g. by clicking on it in the dock, by 124 // 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. 125 // dropping a file on the dock icon, or by Cmd+Tabbing to it.
121 // Returns whether the message was sent. 126 // Returns whether the message was sent.
(...skipping 11 matching lines...) Expand all
133 138
134 // Hide this app. 139 // Hide this app.
135 void OnHide(); 140 void OnHide();
136 141
137 // Requests user attention. 142 // Requests user attention.
138 void OnRequestUserAttention(); 143 void OnRequestUserAttention();
139 144
140 // Terminates the app shim process. 145 // Terminates the app shim process.
141 void Close(); 146 void Close();
142 147
143 IPC::ChannelProxy* channel_; 148 base::FilePath user_data_dir_;
149 bool should_try_long_socket_path;
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 : should_try_long_socket_path(true),
153 delegate_([[AppShimDelegate alloc] init]), 160 delegate_([[AppShimDelegate alloc] init]),
154 launch_app_done_(false), 161 launch_app_done_(false),
155 ping_chrome_reply_received_(false) { 162 ping_chrome_reply_received_(false) {
156 // Since AppShimController is created before the main message loop starts, 163 // Since AppShimController is created before the main message loop starts,
157 // NSApp will not be set, so use sharedApplication. 164 // NSApp will not be set, so use sharedApplication.
158 [[NSApplication sharedApplication] setDelegate:delegate_]; 165 [[NSApplication sharedApplication] setDelegate:delegate_];
159 } 166 }
160 167
161 AppShimController::~AppShimController() { 168 AppShimController::~AppShimController() {
162 // Un-set the delegate since NSApplication does not retain it. 169 // Un-set the delegate since NSApplication does not retain it.
(...skipping 19 matching lines...) Expand all
182 DCHECK(g_io_thread); 189 DCHECK(g_io_thread);
183 190
184 SetUpMenu(); 191 SetUpMenu();
185 192
186 // Chrome will relaunch shims when relaunching apps. 193 // Chrome will relaunch shims when relaunching apps.
187 if (base::mac::IsOSLionOrLater()) 194 if (base::mac::IsOSLionOrLater())
188 [NSApp disableRelaunchOnLogin]; 195 [NSApp disableRelaunchOnLogin];
189 196
190 // The user_data_dir for shims actually contains the app_data_path. 197 // The user_data_dir for shims actually contains the app_data_path.
191 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/ 198 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/
192 base::FilePath user_data_dir = 199 user_data_dir_ = g_info->user_data_dir.DirName().DirName().DirName();
193 g_info->user_data_dir.DirName().DirName().DirName(); 200 CHECK(!user_data_dir_.empty());
194 CHECK(!user_data_dir.empty());
195 201
196 base::FilePath socket_path = 202 // Connect to the short socket path first.
197 user_data_dir.Append(app_mode::kAppShimSocketName); 203 CreateChannelAndSendLaunchApp(app_mode::GetShortSocketPath(user_data_dir_));
204 }
205
206 void AppShimController::CreateChannelAndSendLaunchApp(
207 const base::FilePath& socket_path) {
198 IPC::ChannelHandle handle(socket_path.value()); 208 IPC::ChannelHandle handle(socket_path.value());
199 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, 209 channel_.reset(new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT,
200 this, g_io_thread->message_loop_proxy().get()); 210 this, g_io_thread->message_loop_proxy().get()));
201 211
202 bool launched_by_chrome = 212 bool launched_by_chrome =
203 CommandLine::ForCurrentProcess()->HasSwitch( 213 CommandLine::ForCurrentProcess()->HasSwitch(
204 app_mode::kLaunchedByChromeProcessId); 214 app_mode::kLaunchedByChromeProcessId);
205 apps::AppShimLaunchType launch_type = launched_by_chrome ? 215 apps::AppShimLaunchType launch_type = launched_by_chrome ?
206 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL; 216 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL;
207 217
208 [delegate_ setController:this]; 218 [delegate_ setController:this];
209 219
210 std::vector<base::FilePath> files; 220 std::vector<base::FilePath> files;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone) 281 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone)
272 IPC_MESSAGE_HANDLER(AppShimMsg_Hide, OnHide) 282 IPC_MESSAGE_HANDLER(AppShimMsg_Hide, OnHide)
273 IPC_MESSAGE_HANDLER(AppShimMsg_RequestUserAttention, OnRequestUserAttention) 283 IPC_MESSAGE_HANDLER(AppShimMsg_RequestUserAttention, OnRequestUserAttention)
274 IPC_MESSAGE_UNHANDLED(handled = false) 284 IPC_MESSAGE_UNHANDLED(handled = false)
275 IPC_END_MESSAGE_MAP() 285 IPC_END_MESSAGE_MAP()
276 286
277 return handled; 287 return handled;
278 } 288 }
279 289
280 void AppShimController::OnChannelError() { 290 void AppShimController::OnChannelError() {
291 // TODO(jackhou): Remove this in M35 or later.
292 // On failure, try to connect to the long socket path.
293 if (should_try_long_socket_path) {
294 should_try_long_socket_path = false;
295 base::FilePath udd_plus_socket_name =
296 user_data_dir_.Append(app_mode::kAppShimSocketName);
297 CreateChannelAndSendLaunchApp(udd_plus_socket_name);
298 return;
299 }
300
281 Close(); 301 Close();
282 } 302 }
283 303
284 void AppShimController::OnLaunchAppDone(apps::AppShimLaunchResult result) { 304 void AppShimController::OnLaunchAppDone(apps::AppShimLaunchResult result) {
305 should_try_long_socket_path = false;
306
285 if (result != apps::APP_SHIM_LAUNCH_SUCCESS) { 307 if (result != apps::APP_SHIM_LAUNCH_SUCCESS) {
286 Close(); 308 Close();
287 return; 309 return;
288 } 310 }
289 311
290 std::vector<base::FilePath> files; 312 std::vector<base::FilePath> files;
291 if ([delegate_ getFilesToOpenAtStartup:&files]) 313 if ([delegate_ getFilesToOpenAtStartup:&files])
292 SendFocusApp(apps::APP_SHIM_FOCUS_OPEN_FILES, files); 314 SendFocusApp(apps::APP_SHIM_FOCUS_OPEN_FILES, files);
293 315
294 launch_app_done_ = true; 316 launch_app_done_ = true;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 // minute. 659 // minute.
638 main_message_loop.PostTask( 660 main_message_loop.PostTask(
639 FROM_HERE, 661 FROM_HERE,
640 base::Bind(&AppShimController::Init, 662 base::Bind(&AppShimController::Init,
641 base::Unretained(&controller))); 663 base::Unretained(&controller)));
642 } 664 }
643 665
644 main_message_loop.Run(); 666 main_message_loop.Run();
645 return 0; 667 return 0;
646 } 668 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698