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

Unified Diff: apps/app_shim/app_shim_util_mac.mm

Issue 14579006: Start app shim when app launched. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698