Index: apps/app_shim/app_shim_util_mac.mm |
diff --git a/apps/app_shim/app_shim_util_mac.mm b/apps/app_shim/app_shim_util_mac.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..08df175cd4424e50deb37e709035d2af4f6907b8 |
--- /dev/null |
+++ b/apps/app_shim/app_shim_util_mac.mm |
@@ -0,0 +1,97 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "apps/app_shim/app_shim_util.h" |
+ |
+#include "apps/app_shim/switches.h" |
+#include "base/command_line.h" |
+#include "base/file_util.h" |
+#include "base/files/file_path.h" |
+#include "base/mac/foundation_util.h" |
+#include "base/mac/launch_services_util.h" |
+#include "base/strings/sys_string_conversions.h" |
+#include "chrome/common/mac/app_mode_common.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+using content::BrowserThread; |
+ |
+namespace { |
+ |
+const char kAppDirName[] = "Chrome Apps.localized"; |
tapted
2013/05/16 04:51:00
maybe now is a good time to discuss with benwells
|
+ |
+base::FilePath GetWritableApplicationsDirectory() { |
+ base::FilePath path; |
+ if (base::mac::GetLocalDirectory(NSApplicationDirectory, &path) && |
+ file_util::PathIsWritable(path)) { |
+ return path; |
+ } |
+ if (base::mac::GetUserDirectory(NSApplicationDirectory, &path)) |
+ return path; |
+ return base::FilePath(); |
+} |
+ |
+base::FilePath GetPathToShim(const std::string& app_id, |
tapted
2013/05/16 04:51:00
Maybe we should consider calling this extension_id
|
+ const std::string& profile_name) { |
+ base::FilePath app_dir = app_shim::GetAppShimFolder(); |
+ if (app_dir.empty()) |
+ return base::FilePath(); |
+ |
+ file_util::FileEnumerator enumerator(app_dir, |
tapted
2013/05/16 04:51:00
perhaps a note to say why it's iterating (i.e. bec
|
+ false /* recursive */, |
+ file_util::FileEnumerator::DIRECTORIES); |
+ base::FilePath shim_path = enumerator.Next(); |
+ for (; !shim_path.empty(); shim_path = enumerator.Next()) { |
+ base::FilePath plist_path = |
+ shim_path.Append("Contents").Append("Info.plist"); |
+ NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: |
+ base::mac::FilePathToNSString(plist_path)]; |
+ std::string plist_id = base::SysNSStringToUTF8( |
+ [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); |
+ std::string plist_profile = base::SysNSStringToUTF8( |
+ [plist objectForKey:app_mode::kCrAppModeProfileDirKey]); |
+ |
+ if (plist_id == app_id && plist_profile == profile_name) { |
+ break; |
+ } |
tapted
2013/05/16 04:51:00
nit: doesn't need curlies
|
+ } |
+ return shim_path; |
+} |
+ |
+void FindAndLaunchShimOnFileThread( |
+ const std::string& app_id, |
tapted
2013/05/16 04:51:00
nit: align these with the open paren (like for Fin
|
+ const std::string& profile_name, |
+ base::Callback<void(bool)> completed) { |
+ base::FilePath shim_path = GetPathToShim(app_id, profile_name); |
tapted
2013/05/16 04:51:00
nit: before this,
DCHECK(content::BrowserThread
|
+ if (shim_path.empty()) { |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, base::Bind(completed, false)); |
+ return; |
+ } |
tapted
2013/05/16 04:51:00
nit: blank line after for early return
|
+ CommandLine command_line(CommandLine::NO_PROGRAM); |
+ command_line.AppendSwitch(app_shim::switches::kNoLaunchApp); |
+ base::mac::OpenApplicationWithPath(shim_path, command_line, NULL); |
tapted
2013/05/16 04:51:00
Do you see a reason why shim_path can't be derived
|
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, base::Bind(completed, true)); |
+} |
+ |
+} // namespace |
+ |
+namespace app_shim { |
+ |
+base::FilePath GetAppShimFolder() { |
+ base::FilePath path = GetWritableApplicationsDirectory(); |
tapted
2013/05/16 04:51:00
GetWritableApplicationsDirectory might need to be
|
+ return path.empty() ? path : path.Append(kAppDirName); |
+} |
+ |
+void FindAndLaunchShimForApp( |
+ const std::string& app_id, |
tapted
2013/05/16 04:51:00
nit: align these like the header
|
+ const std::string& profile_name, |
+ base::Callback<void(bool)> completed) { |
+ BrowserThread::PostTask( |
+ BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&FindAndLaunchShimOnFileThread, |
+ app_id, profile_name, completed)); |
+} |
+ |
+} // namespace app_shim |