Index: components/profile_service/profile_service_impl.cc |
diff --git a/components/profile_service/profile_service_impl.cc b/components/profile_service/profile_service_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..66fcca2300aabb0a2d424420b5d996e589b2f3f8 |
--- /dev/null |
+++ b/components/profile_service/profile_service_impl.cc |
@@ -0,0 +1,86 @@ |
+// Copyright 2016 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 "components/profile_service/profile_service_impl.h" |
+ |
+#include "base/files/file_path.h" |
+#include "base/files/file_util.h" |
+#include "base/files/scoped_temp_dir.h" |
+#include "components/filesystem/directory_impl.h" |
+#include "components/filesystem/lock_table.h" |
+#include "mojo/shell/public/cpp/connection.h" |
+ |
+#if defined(OS_WIN) |
+#include "base/strings/sys_string_conversions.h" |
+#endif |
+ |
+namespace profile { |
+ |
+namespace { |
+ |
+const char kEscapeChar = ','; |
+ |
+} // namespace |
+ |
+ProfileServiceImpl::ProfileServiceImpl( |
+ mojo::Connection* connection, |
+ mojo::InterfaceRequest<ProfileService> request, |
+ base::FilePath base_profile_dir, |
+ filesystem::LockTable* lock_table) |
+ : binding_(this, std::move(request)), |
+ lock_table_(lock_table) { |
+ std::string sanitized_origin = BuildSanitizedOrigin( |
jam
2016/02/27 01:34:45
it wasn't clear to me that GetDirectory returns a
Elliot Glaysher
2016/02/29 23:04:13
My assumption was that the conversion code would l
|
+ connection->GetRemoteApplicationURL()); |
+#if defined(OS_WIN) |
+ path_ = base_profile_dir.Append(base::UTF8ToWide(sanitized_origin)); |
+#else |
+ path_ = base_profile_dir.Append(sanitized_origin); |
+#endif |
+ if (!base::PathExists(path_)) |
+ base::CreateDirectory(path_); |
+} |
+ |
+ProfileServiceImpl::~ProfileServiceImpl() { |
+} |
+ |
+void ProfileServiceImpl::GetDirectory( |
+ mojo::InterfaceRequest<filesystem::Directory> request) { |
+ new filesystem::DirectoryImpl(std::move(request), |
+ path_, |
+ scoped_ptr<base::ScopedTempDir>(), |
+ lock_table_); |
+} |
+ |
+// static |
+std::string ProfileServiceImpl::BuildSanitizedOrigin( |
+ const std::string& origin) { |
+ std::string sanitized_origin; |
+ // We take the origin string, and encode it in a way safe for filesystem |
+ // access. This is vaguely based on //net/tools/dump_cache/ |
+ // url_to_filename_encoder.h; that file strips out schemes, and does weird |
+ // things with subdirectories. We do follow the basic algorithm used there, |
+ // including using ',' as our escape character. |
+ for (size_t i = 0; i < origin.length(); ++i) { |
+ unsigned char ch = origin[i]; |
+ char encoded[3]; |
+ int encoded_len; |
+ if ((ch == '_') || (ch == '.') || (ch == '=') || (ch == '+') || |
+ (ch == '-') || (('0' <= ch) && (ch <= '9')) || |
+ (('A' <= ch) && (ch <= 'Z')) || (('a' <= ch) && (ch <= 'z'))) { |
+ encoded[0] = ch; |
+ encoded_len = 1; |
+ } else { |
+ encoded[0] = kEscapeChar; |
+ encoded[1] = ch / 16; |
+ encoded[1] += (encoded[1] >= 10) ? 'A' - 10 : '0'; |
+ encoded[2] = ch % 16; |
+ encoded[2] += (encoded[2] >= 10) ? 'A' - 10 : '0'; |
+ encoded_len = 3; |
+ } |
+ sanitized_origin.append(encoded, encoded_len); |
+ } |
+ return sanitized_origin; |
+} |
+ |
+} // namespace profile |