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

Unified Diff: chrome/browser/web_applications/web_app.cc

Issue 9423048: Add user data dir field to Mac platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build Created 8 years, 10 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
« no previous file with comments | « chrome/browser/web_applications/web_app.h ('k') | chrome/browser/web_applications/web_app_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/web_applications/web_app.cc
diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc
index e7fbb344b101f319b8b1d811f2f850b94ab6bfca..4ff951f7fa94b7842d33e402e9d588b4c9acd2d5 100644
--- a/chrome/browser/web_applications/web_app.cc
+++ b/chrome/browser/web_applications/web_app.cc
@@ -10,6 +10,7 @@
#include "base/string_util.h"
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
+#include "chrome/common/extensions/extension.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
@@ -18,34 +19,6 @@ using content::BrowserThread;
namespace {
-// Returns relative directory of given web app url.
-FilePath GetWebAppDir(const ShellIntegration::ShortcutInfo& info) {
- if (!info.extension_id.empty()) {
- std::string app_name =
- web_app::GenerateApplicationNameFromExtensionId(info.extension_id);
-#if defined(OS_WIN)
- return FilePath(UTF8ToUTF16(app_name));
-#elif defined(OS_POSIX)
- return FilePath(app_name);
-#endif
- } else {
- FilePath::StringType host;
- FilePath::StringType scheme_port;
-
-#if defined(OS_WIN)
- host = UTF8ToUTF16(info.url.host());
- scheme_port = (info.url.has_scheme() ? UTF8ToUTF16(info.url.scheme())
- : L"http") + FILE_PATH_LITERAL("_") +
- (info.url.has_port() ? UTF8ToUTF16(info.url.port()) : L"80");
-#elif defined(OS_POSIX)
- host = info.url.host();
- scheme_port = info.url.scheme() + FILE_PATH_LITERAL("_") + info.url.port();
-#endif
-
- return FilePath(host).Append(scheme_port);
- }
-}
-
#if defined(TOOLKIT_VIEWS)
// Predicator for sorting images from largest to smallest.
bool IconPrecedes(const WebApplicationInfo::IconInfo& left,
@@ -68,12 +41,6 @@ static const char* kCrxAppPrefix = "_crx_";
namespace internals {
-// Returns data directory for given web app url
-FilePath GetWebAppDataDirectory(const FilePath& root_dir,
- const ShellIntegration::ShortcutInfo& info) {
- return root_dir.Append(GetWebAppDir(info));
-}
-
FilePath GetSanitizedFileName(const string16& name) {
#if defined(OS_WIN)
string16 file_name = name;
@@ -86,6 +53,38 @@ FilePath GetSanitizedFileName(const string16& name) {
} // namespace internals
+FilePath GetWebAppDataDirectory(const FilePath& profile_path,
+ const std::string& extension_id,
+ const GURL& url) {
+ FilePath app_data_dir(profile_path.Append(chrome::kWebAppDirname));
+
+ if (!extension_id.empty()) {
+ return app_data_dir.AppendASCII(
+ GenerateApplicationNameFromExtensionId(extension_id));
+ }
+
+ std::string host(url.host());
+ std::string scheme(url.has_scheme() ? url.scheme() : "http");
+ std::string port(url.has_port() ? url.port() : "80");
+ std::string scheme_port(scheme + "_" + port);
+
+#if defined(OS_WIN)
+ FilePath::StringType host_path(UTF8ToUTF16(host));
+ FilePath::StringType scheme_port_path(UTF8ToUTF16(scheme_port));
+#elif defined(OS_POSIX)
+ FilePath::StringType host_path(host);
+ FilePath::StringType scheme_port_path(scheme_port);
+#endif
+
+ return app_data_dir.Append(host_path).Append(scheme_port_path);
+}
+
+FilePath GetWebAppDataDirectory(const FilePath& profile_path,
+ const Extension& extension) {
+ return GetWebAppDataDirectory(
+ profile_path, extension.id(), GURL(extension.launch_web_url()));
+}
+
std::string GenerateApplicationNameFromInfo(
const ShellIntegration::ShortcutInfo& shortcut_info) {
if (!shortcut_info.extension_id.empty()) {
@@ -125,9 +124,10 @@ void CreateShortcut(
BrowserThread::FILE,
FROM_HERE,
base::Bind(&internals::CreateShortcutTask,
- web_app::internals::GetWebAppDataDirectory(
- web_app::GetDataDir(data_dir),
- shortcut_info),
+ GetWebAppDataDirectory(
+ data_dir,
+ shortcut_info.extension_id,
+ shortcut_info.url),
data_dir,
shortcut_info));
}
@@ -149,10 +149,6 @@ bool IsValidUrl(const GURL& url) {
return false;
}
-FilePath GetDataDir(const FilePath& profile_path) {
- return profile_path.Append(chrome::kWebAppDirname);
-}
-
#if defined(TOOLKIT_VIEWS)
void GetIconsInfo(const WebApplicationInfo& app_info,
IconInfoList* icons) {
« no previous file with comments | « chrome/browser/web_applications/web_app.h ('k') | chrome/browser/web_applications/web_app_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698