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

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: Always use short socket path 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();
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
148 base::FilePath user_data_dir_;
149 base::FilePath socket_path_;
tapted 2013/11/21 11:12:05 can this be an argument to CreateChannelAndSendLau
jackhou1 2013/11/22 00:20:40 Done.
143 IPC::ChannelProxy* channel_; 150 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 : channel_(NULL),
(...skipping 29 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 base::FilePath udd_plus_socket_name =
198 IPC::ChannelHandle handle(socket_path.value()); 204 user_data_dir_.Append(app_mode::kAppShimSocketName);
205 socket_path_ = app_mode::GetShortSocketPath(udd_plus_socket_name);
206
207 CreateChannelAndSendLaunchApp();
208 }
209
210 void AppShimController::CreateChannelAndSendLaunchApp() {
211 IPC::ChannelHandle handle(socket_path_.value());
199 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, 212 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT,
200 this, g_io_thread->message_loop_proxy().get()); 213 this, g_io_thread->message_loop_proxy().get());
201 214
202 bool launched_by_chrome = 215 bool launched_by_chrome =
203 CommandLine::ForCurrentProcess()->HasSwitch( 216 CommandLine::ForCurrentProcess()->HasSwitch(
204 app_mode::kLaunchedByChromeProcessId); 217 app_mode::kLaunchedByChromeProcessId);
205 apps::AppShimLaunchType launch_type = launched_by_chrome ? 218 apps::AppShimLaunchType launch_type = launched_by_chrome ?
206 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL; 219 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL;
207 220
208 [delegate_ setController:this]; 221 [delegate_ setController:this];
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone) 284 IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone)
272 IPC_MESSAGE_HANDLER(AppShimMsg_Hide, OnHide) 285 IPC_MESSAGE_HANDLER(AppShimMsg_Hide, OnHide)
273 IPC_MESSAGE_HANDLER(AppShimMsg_RequestUserAttention, OnRequestUserAttention) 286 IPC_MESSAGE_HANDLER(AppShimMsg_RequestUserAttention, OnRequestUserAttention)
274 IPC_MESSAGE_UNHANDLED(handled = false) 287 IPC_MESSAGE_UNHANDLED(handled = false)
275 IPC_END_MESSAGE_MAP() 288 IPC_END_MESSAGE_MAP()
276 289
277 return handled; 290 return handled;
278 } 291 }
279 292
280 void AppShimController::OnChannelError() { 293 void AppShimController::OnChannelError() {
294 // On failure, try to connect to the long socket path.
295 base::FilePath udd_plus_socket_name =
296 user_data_dir_.Append(app_mode::kAppShimSocketName);
297 if (socket_path_ != udd_plus_socket_name) {
tapted 2013/11/21 11:12:05 I think we shouldn't try this if we ever successfu
jackhou1 2013/11/22 00:20:40 Done.
298 socket_path_ = udd_plus_socket_name;
299 CreateChannelAndSendLaunchApp();
300 return;
301 }
302
281 Close(); 303 Close();
282 } 304 }
283 305
284 void AppShimController::OnLaunchAppDone(apps::AppShimLaunchResult result) { 306 void AppShimController::OnLaunchAppDone(apps::AppShimLaunchResult result) {
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;
(...skipping 346 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