summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/sync/engine/apply_updates_command_unittest.cc7
-rw-r--r--chrome/browser/sync/engine/auth_watcher.cc7
-rw-r--r--chrome/browser/sync/engine/auth_watcher_unittest.cc2
-rw-r--r--chrome/browser/sync/engine/build_commit_command.cc12
-rw-r--r--chrome/browser/sync/engine/download_updates_command.cc4
-rw-r--r--chrome/browser/sync/engine/net/server_connection_manager.cc3
-rw-r--r--chrome/browser/sync/engine/net/url_translator.cc1
-rw-r--r--chrome/browser/sync/engine/process_commit_response_command.cc1
-rw-r--r--chrome/browser/sync/engine/process_updates_command.cc1
-rw-r--r--chrome/browser/sync/engine/syncapi.cc76
-rw-r--r--chrome/browser/sync/engine/syncapi.h3
-rw-r--r--chrome/browser/sync/engine/syncer.cc1
-rw-r--r--chrome/browser/sync/engine/syncer_proto_util.cc19
-rw-r--r--chrome/browser/sync/engine/syncer_unittest.cc11
-rw-r--r--chrome/browser/sync/engine/syncer_util.cc12
-rw-r--r--chrome/browser/sync/engine/verify_updates_command.cc1
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.cc12
-rw-r--r--chrome/browser/sync/syncable/directory_backing_store.cc8
-rw-r--r--chrome/browser/sync/syncable/directory_backing_store.h5
-rw-r--r--chrome/browser/sync/syncable/directory_manager.cc26
-rw-r--r--chrome/browser/sync/syncable/directory_manager.h13
-rw-r--r--chrome/browser/sync/syncable/syncable.cc167
-rw-r--r--chrome/browser/sync/syncable/syncable.h23
-rw-r--r--chrome/browser/sync/syncable/syncable_unittest.cc67
-rw-r--r--chrome/browser/sync/util/character_set_converters.cc79
-rw-r--r--chrome/browser/sync/util/character_set_converters.h231
-rw-r--r--chrome/browser/sync/util/character_set_converters_posix.cc52
-rw-r--r--chrome/browser/sync/util/character_set_converters_unittest.cc143
-rw-r--r--chrome/browser/sync/util/character_set_converters_win.cc56
-rw-r--r--chrome/browser/sync/util/compat_file.h33
-rw-r--r--chrome/browser/sync/util/compat_file_posix.cc13
-rw-r--r--chrome/browser/sync/util/compat_file_win.cc14
-rw-r--r--chrome/browser/sync/util/path_helpers.cc149
-rw-r--r--chrome/browser/sync/util/path_helpers.h30
-rw-r--r--chrome/browser/sync/util/path_helpers_linux.cc6
-rw-r--r--chrome/browser/sync/util/path_helpers_mac.cc7
-rw-r--r--chrome/browser/sync/util/path_helpers_posix.cc107
-rw-r--r--chrome/browser/sync/util/path_helpers_unittest.cc153
-rw-r--r--chrome/browser/sync/util/path_helpers_win.cc85
-rw-r--r--chrome/browser/sync/util/query_helpers.cc47
-rw-r--r--chrome/browser/sync/util/query_helpers.h12
-rw-r--r--chrome/browser/sync/util/query_helpers_unittest.cc27
-rw-r--r--chrome/browser/sync/util/sync_types.h29
-rw-r--r--chrome/browser/sync/util/user_settings.cc14
-rw-r--r--chrome/browser/sync/util/user_settings.h5
-rw-r--r--chrome/browser/sync/util/user_settings_unittest.cc26
-rwxr-xr-xchrome/chrome.gyp7
-rw-r--r--chrome/test/sync/engine/mock_server_connection.cc3
-rw-r--r--chrome/test/sync/engine/test_directory_setter_upper.cc13
-rw-r--r--chrome/test/sync/engine/test_directory_setter_upper.h2
50 files changed, 401 insertions, 1424 deletions
diff --git a/chrome/browser/sync/engine/apply_updates_command_unittest.cc b/chrome/browser/sync/engine/apply_updates_command_unittest.cc
index afa0969..aff2c63 100644
--- a/chrome/browser/sync/engine/apply_updates_command_unittest.cc
+++ b/chrome/browser/sync/engine/apply_updates_command_unittest.cc
@@ -9,7 +9,6 @@
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/syncable/syncable_id.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
#include "chrome/test/sync/engine/test_directory_setter_upper.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -46,12 +45,10 @@ class ApplyUpdatesCommandTest : public testing::Test {
MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
Id::CreateFromServerId(item_id));
ASSERT_TRUE(entry.good());
- PathString name;
- AppendUTF8ToPathString(item_id, &name);
entry.Put(syncable::SERVER_VERSION, next_revision_++);
entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
- entry.Put(syncable::SERVER_NAME, name);
- entry.Put(syncable::SERVER_NON_UNIQUE_NAME, name);
+ entry.Put(syncable::SERVER_NAME, item_id);
+ entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id);
entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id));
entry.Put(syncable::SERVER_IS_DIR, true);
}
diff --git a/chrome/browser/sync/engine/auth_watcher.cc b/chrome/browser/sync/engine/auth_watcher.cc
index c722a8d..9d81d28 100644
--- a/chrome/browser/sync/engine/auth_watcher.cc
+++ b/chrome/browser/sync/engine/auth_watcher.cc
@@ -13,7 +13,6 @@
#include "chrome/browser/sync/notifier/listener/talk_mediator.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
#include "chrome/browser/sync/util/event_sys-inl.h"
#include "chrome/browser/sync/util/user_settings.h"
@@ -122,8 +121,7 @@ void AuthWatcher::DoAuthenticateWithToken(const std::string& gaia_email,
case Authenticator::SUCCESS:
{
status_ = GAIA_AUTHENTICATED;
- PathString share_name;
- CHECK(AppendUTF8ToPathString(email.data(), email.size(), &share_name));
+ const PathString& share_name = email;
user_settings_->SwitchUser(email);
// Set the authentication token for notifications
@@ -165,8 +163,7 @@ bool AuthWatcher::AuthenticateLocally(string email) {
gaia_->SetUsername(email);
status_ = LOCALLY_AUTHENTICATED;
user_settings_->SwitchUser(email);
- PathString share_name;
- CHECK(AppendUTF8ToPathString(email.data(), email.size(), &share_name));
+ const PathString& share_name = email;
LoadDirectoryListAndOpen(share_name);
NotifyAuthSucceeded(email);
return true;
diff --git a/chrome/browser/sync/engine/auth_watcher_unittest.cc b/chrome/browser/sync/engine/auth_watcher_unittest.cc
index ede4023..c2561630 100644
--- a/chrome/browser/sync/engine/auth_watcher_unittest.cc
+++ b/chrome/browser/sync/engine/auth_watcher_unittest.cc
@@ -86,7 +86,7 @@ class AuthWatcherTest : public testing::Test {
allstatus_.reset(new AllStatus());
user_settings_.reset(new UserSettings());
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- PathString user_settings_path = temp_dir_.path().value() + kUserSettingsDB;
+ FilePath user_settings_path = temp_dir_.path().Append(kUserSettingsDB);
user_settings_->Init(user_settings_path);
gaia_auth_ = new GaiaAuthMockForAuthWatcher();
talk_mediator_.reset(new TalkMediatorImpl());
diff --git a/chrome/browser/sync/engine/build_commit_command.cc b/chrome/browser/sync/engine/build_commit_command.cc
index 5058bba..07ae99a 100644
--- a/chrome/browser/sync/engine/build_commit_command.cc
+++ b/chrome/browser/sync/engine/build_commit_command.cc
@@ -14,7 +14,6 @@
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/syncable/syncable_changes_version.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
#include "chrome/browser/sync/util/sync_types.h"
using std::set;
@@ -46,7 +45,7 @@ void BuildCommitCommand::AddExtensionsActivityToMessage(
void BuildCommitCommand::ExecuteImpl(SyncerSession* session) {
ClientToServerMessage message;
- message.set_share(ToUTF8(session->account_name()).get_string());
+ message.set_share(session->account_name());
message.set_message_contents(ClientToServerMessage::COMMIT);
CommitMessage* commit_message = message.mutable_commit();
@@ -69,15 +68,14 @@ void BuildCommitCommand::ExecuteImpl(SyncerSession* session) {
Name name = meta_entry.GetName();
CHECK(!name.value().empty()); // Make sure this isn't an update.
- sync_entry->set_name(ToUTF8(name.value()).get_string());
+ sync_entry->set_name(name.value());
// Set the non_unique_name if we have one. If we do, the server ignores
// the |name| value (using |non_unique_name| instead), and will return
// in the CommitResponse a unique name if one is generated. Even though
// we could get away with only sending |name|, we send both because it
// may aid in logging.
if (name.value() != name.non_unique_value()) {
- sync_entry->set_non_unique_name(
- ToUTF8(name.non_unique_value()).get_string());
+ sync_entry->set_non_unique_name(name.non_unique_value());
}
// Deleted items with negative parent ids can be a problem so we set the
// parent to 0. (TODO(sync): Still true in protocol?).
@@ -126,7 +124,7 @@ void BuildCommitCommand::ExecuteImpl(SyncerSession* session) {
++iter) {
sync_pb::ExtendedAttributes_ExtendedAttribute *extended_attribute =
mutable_extended_attributes->add_extendedattribute();
- extended_attribute->set_key(ToUTF8(iter->key()).get_string());
+ extended_attribute->set_key(iter->key());
SyncerProtoUtil::CopyBlobIntoProtoBytes(iter->value(),
extended_attribute->mutable_value());
}
@@ -143,7 +141,7 @@ void BuildCommitCommand::ExecuteImpl(SyncerSession* session) {
sync_entry->set_insert_after_item_id(prev_string);
if (!meta_entry.Get(syncable::IS_DIR)) {
- string bookmark_url = ToUTF8(meta_entry.Get(syncable::BOOKMARK_URL));
+ string bookmark_url = meta_entry.Get(syncable::BOOKMARK_URL);
bookmark->set_bookmark_url(bookmark_url);
SyncerProtoUtil::CopyBlobIntoProtoBytes(
meta_entry.Get(syncable::BOOKMARK_FAVICON),
diff --git a/chrome/browser/sync/engine/download_updates_command.cc b/chrome/browser/sync/engine/download_updates_command.cc
index 889567e..1883e31 100644
--- a/chrome/browser/sync/engine/download_updates_command.cc
+++ b/chrome/browser/sync/engine/download_updates_command.cc
@@ -10,7 +10,6 @@
#include "chrome/browser/sync/engine/syncer_proto_util.h"
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
#include "chrome/browser/sync/util/sync_types.h"
using syncable::ScopedDirLookup;
@@ -26,8 +25,7 @@ void DownloadUpdatesCommand::ExecuteImpl(SyncerSession* session) {
ClientToServerMessage client_to_server_message;
ClientToServerResponse update_response;
- client_to_server_message.set_share(
- static_cast<const string&>(ToUTF8(session->account_name())));
+ client_to_server_message.set_share(session->account_name());
client_to_server_message.set_message_contents(
ClientToServerMessage::GET_UPDATES);
GetUpdatesMessage* get_updates =
diff --git a/chrome/browser/sync/engine/net/server_connection_manager.cc b/chrome/browser/sync/engine/net/server_connection_manager.cc
index c8165a9..38d140f 100644
--- a/chrome/browser/sync/engine/net/server_connection_manager.cc
+++ b/chrome/browser/sync/engine/net/server_connection_manager.cc
@@ -18,7 +18,6 @@
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
#include "chrome/browser/sync/util/event_sys-inl.h"
namespace browser_sync {
@@ -355,7 +354,7 @@ bool FillMessageWithShareDetails(sync_pb::ClientToServerMessage* csm,
string birthday = dir->store_birthday();
if (!birthday.empty())
csm->set_store_birthday(birthday);
- csm->set_share(ToUTF8(share).get_string());
+ csm->set_share(share);
return true;
}
diff --git a/chrome/browser/sync/engine/net/url_translator.cc b/chrome/browser/sync/engine/net/url_translator.cc
index 8a1c0a3..6dc2754 100644
--- a/chrome/browser/sync/engine/net/url_translator.cc
+++ b/chrome/browser/sync/engine/net/url_translator.cc
@@ -10,7 +10,6 @@
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/port.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
#include "net/base/escape.h"
using std::string;
diff --git a/chrome/browser/sync/engine/process_commit_response_command.cc b/chrome/browser/sync/engine/process_commit_response_command.cc
index 72fd0e6..de993fb 100644
--- a/chrome/browser/sync/engine/process_commit_response_command.cc
+++ b/chrome/browser/sync/engine/process_commit_response_command.cc
@@ -15,7 +15,6 @@
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
using syncable::ScopedDirLookup;
using syncable::WriteTransaction;
diff --git a/chrome/browser/sync/engine/process_updates_command.cc b/chrome/browser/sync/engine/process_updates_command.cc
index 31d267d..fefa234 100644
--- a/chrome/browser/sync/engine/process_updates_command.cc
+++ b/chrome/browser/sync/engine/process_updates_command.cc
@@ -14,7 +14,6 @@
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
using std::vector;
diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc
index 7d953d0..7cf18bc 100644
--- a/chrome/browser/sync/engine/syncapi.cc
+++ b/chrome/browser/sync/engine/syncapi.cc
@@ -133,8 +133,8 @@ class AddressWatchTask : public Task {
namespace sync_api {
class ModelSafeWorkerBridge;
-static const PSTR_CHAR kBookmarkSyncUserSettingsDatabase[] =
- PSTR("BookmarkSyncSettings.sqlite3");
+static const FilePath::CharType kBookmarkSyncUserSettingsDatabase[] =
+ FILE_PATH_LITERAL("BookmarkSyncSettings.sqlite3");
static const PSTR_CHAR kDefaultNameForNewNodes[] = PSTR(" ");
// The list of names which are reserved for use by the server.
@@ -171,29 +171,11 @@ static bool EndsWithSpace(const string16& string) {
return !string.empty() && *string.rbegin() == ' ';
}
-static inline void String16ToPathString(const sync_char16 *in,
- PathString *out) {
- string16 in_str(in);
-#if defined(OS_WIN)
- out->assign(in_str);
-#else
- UTF16ToUTF8(in_str.c_str(), in_str.length(), out);
-#endif
-}
-
-static inline void PathStringToString16(const PathString& in, string16* out) {
-#if defined(OS_WIN)
- out->assign(in);
-#else
- UTF8ToUTF16(in.c_str(), in.length(), out);
-#endif
-}
-
// When taking a name from the syncapi, append a space if it matches the
// pattern of a server-illegal name followed by zero or more spaces.
static void SyncAPINameToServerName(const sync_char16 *sync_api_name,
PathString* out) {
- String16ToPathString(sync_api_name, out);
+ *out = UTF16ToUTF8(sync_api_name);
string16 sync_api_name_str(sync_api_name);
if (IsNameServerIllegalAfterTrimming(sync_api_name_str))
out->append(PSTR(" "));
@@ -204,8 +186,7 @@ static void SyncAPINameToServerName(const sync_char16 *sync_api_name,
// space.
static void ServerNameToSyncAPIName(const PathString& server_name,
string16*out) {
- string16 server_name_str;
- PathStringToString16(server_name, &server_name_str);
+ string16 server_name_str(UTF8ToUTF16(server_name));
if (IsNameServerIllegalAfterTrimming(server_name_str) &&
EndsWithSpace(server_name_str))
out->assign(server_name_str, 0, server_name_str.size() - 1);
@@ -272,7 +253,7 @@ const sync_char16* BaseNode::GetTitle() const {
const sync_char16* BaseNode::GetURL() const {
// Store the string in data_ so that the returned pointer is valid.
- PathStringToString16(GetEntry()->Get(syncable::BOOKMARK_URL), &data_->url);
+ data_->url = UTF8ToUTF16(GetEntry()->Get(syncable::BOOKMARK_URL));
return data_->url.c_str();
}
@@ -357,8 +338,7 @@ void WriteNode::SetTitle(const sync_char16* title) {
}
void WriteNode::SetURL(const sync_char16* url) {
- PathString url_string;
- String16ToPathString(url, &url_string);
+ PathString url_string(UTF16ToUTF8(url));
if (url_string == entry_->Get(syncable::BOOKMARK_URL))
return; // Skip redundant changes.
@@ -543,8 +523,7 @@ const BaseTransaction* ReadNode::GetTransaction() const {
bool ReadNode::InitByTagLookup(const sync_char16* tag) {
DCHECK(!entry_) << "Init called twice";
- PathString tag_string;
- String16ToPathString(tag, &tag_string);
+ PathString tag_string(UTF16ToUTF8(tag));
if (tag_string.empty())
return false;
syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
@@ -702,7 +681,7 @@ class SyncManager::SyncInternal {
~SyncInternal() { }
- bool Init(const PathString& database_location,
+ bool Init(const FilePath& database_location,
const std::string& sync_server_and_path,
int port,
const char* gaia_service_id,
@@ -941,7 +920,7 @@ SyncManager::SyncManager() {
data_ = new SyncInternal(this);
}
-bool SyncManager::Init(const sync_char16* database_location,
+bool SyncManager::Init(const FilePath& database_location,
const char* sync_server_and_path,
int sync_server_port,
const char* gaia_service_id,
@@ -952,13 +931,10 @@ bool SyncManager::Init(const sync_char16* database_location,
ModelSafeWorkerInterface* model_safe_worker,
bool attempt_last_user_authentication,
const char* user_agent) {
- DCHECK(database_location);
DCHECK(post_factory);
- PathString db_path;
- String16ToPathString(database_location, &db_path);
string server_string(sync_server_and_path);
- return data_->Init(db_path,
+ return data_->Init(database_location,
server_string,
sync_server_port,
gaia_service_id,
@@ -982,13 +958,12 @@ const char* SyncManager::GetAuthenticatedUsername() {
}
const char* SyncManager::SyncInternal::GetAuthenticatedUsername() {
- cached_auth_watcher_email_ = browser_sync::ToUTF8(
- username_for_share()).get_string();
+ cached_auth_watcher_email_ = username_for_share();
return cached_auth_watcher_email_.c_str();
}
bool SyncManager::SyncInternal::Init(
- const PathString& database_location,
+ const FilePath& database_location,
const std::string& sync_server_and_path,
int port,
const char* gaia_service_id,
@@ -1001,8 +976,8 @@ bool SyncManager::SyncInternal::Init(
// Set up UserSettings, creating the db if necessary. We need this to
// instantiate a URLFactory to give to the Syncer.
- PathString settings_db_file = AppendSlash(database_location) +
- kBookmarkSyncUserSettingsDatabase;
+ FilePath settings_db_file =
+ database_location.Append(FilePath(kBookmarkSyncUserSettingsDatabase));
user_settings_.reset(new UserSettings());
if (!user_settings_->Init(settings_db_file))
return false;
@@ -1103,8 +1078,7 @@ void SyncManager::SyncInternal::MarkAndNotifyInitializationComplete() {
void SyncManager::SyncInternal::Authenticate(const std::string& username,
const std::string& password) {
- DCHECK(username_for_share().empty() ||
- (username == browser_sync::ToUTF8(username_for_share()).get_string()))
+ DCHECK(username_for_share().empty() || username == username_for_share())
<< "Username change from valid username detected";
if (allstatus()->status().authenticated)
return;
@@ -1127,13 +1101,7 @@ void SyncManager::SyncInternal::AuthenticateForLastKnownUser() {
return;
}
- browser_sync::ToPathString s(username);
- if (s.good()) {
- share_.authenticated_name = s.get_string16();
- } else {
- RaiseAuthNeededEvent();
- return;
- }
+ share_.authenticated_name = username;
// We optimize by opening the directory before the "fresh" authentication
// attempt completes so that we can immediately begin processing changes.
@@ -1449,16 +1417,12 @@ void SyncManager::SyncInternal::HandleAuthWatcherEvent(
// We now know the supplied username and password were valid. If this
// wasn't the first sync, authenticated_name should already be assigned.
if (username_for_share().empty()) {
- browser_sync::ToPathString s(event.user_email);
- if (s.good())
- share_.authenticated_name = s.get_string16();
+ share_.authenticated_name = event.user_email;
}
- DCHECK(LowerCaseEqualsASCII(browser_sync::ToUTF8(
- username_for_share()).get_string(),
+ DCHECK(LowerCaseEqualsASCII(username_for_share(),
StringToLowerASCII(event.user_email).c_str()))
- << "username_for_share= "
- << browser_sync::ToUTF8(username_for_share())
+ << "username_for_share= " << username_for_share()
<< ", event.user_email= " << event.user_email;
if (observer_)
@@ -1536,7 +1500,7 @@ void SyncManager::SetupForTestMode(const sync_char16* test_username) {
void SyncManager::SyncInternal::SetupForTestMode(
const sync_char16* test_username) {
- String16ToPathString(test_username, &share_.authenticated_name);
+ share_.authenticated_name = UTF16ToUTF8(test_username);
if (!dir_manager()->Open(username_for_share()))
DCHECK(false) << "Could not open directory when running in test mode";
diff --git a/chrome/browser/sync/engine/syncapi.h b/chrome/browser/sync/engine/syncapi.h
index 474a7a5..f85b25b 100644
--- a/chrome/browser/sync/engine/syncapi.h
+++ b/chrome/browser/sync/engine/syncapi.h
@@ -39,6 +39,7 @@
#define CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_
#include "base/basictypes.h"
+#include "base/file_path.h"
#include "build/build_config.h"
#if defined(OS_WIN)
@@ -523,7 +524,7 @@ class SYNC_EXPORT SyncManager {
// |model_safe_worker| ownership is given to the SyncManager.
// |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent
// HTTP header. Used internally when collecting stats to classify clients.
- bool Init(const sync_char16* database_location,
+ bool Init(const FilePath& database_location,
const char* sync_server_and_path,
int sync_server_port,
const char* gaia_service_id,
diff --git a/chrome/browser/sync/engine/syncer.cc b/chrome/browser/sync/engine/syncer.cc
index ee56bb9..ee92258 100644
--- a/chrome/browser/sync/engine/syncer.cc
+++ b/chrome/browser/sync/engine/syncer.cc
@@ -26,7 +26,6 @@
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable-inl.h"
#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
using sync_pb::ClientCommand;
using syncable::Blob;
diff --git a/chrome/browser/sync/engine/syncer_proto_util.cc b/chrome/browser/sync/engine/syncer_proto_util.cc
index 4896c59..7eb0227 100644
--- a/chrome/browser/sync/engine/syncer_proto_util.cc
+++ b/chrome/browser/sync/engine/syncer_proto_util.cc
@@ -11,7 +11,6 @@
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable-inl.h"
#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
using std::string;
using std::stringstream;
@@ -246,14 +245,9 @@ void SyncerProtoUtil::CopyBlobIntoProtoBytes(const syncable::Blob& blob,
// static
syncable::SyncName SyncerProtoUtil::NameFromSyncEntity(
const SyncEntity& entry) {
- SyncName result(PSTR(""));
-
- AppendUTF8ToPathString(entry.name(), &result.value());
+ SyncName result(entry.name());
if (entry.has_non_unique_name()) {
- AppendUTF8ToPathString(entry.non_unique_name(),
- &result.non_unique_value());
- } else {
- result.non_unique_value() = result.value();
+ result.set_non_unique_value(entry.non_unique_name());
}
return result;
}
@@ -261,14 +255,9 @@ syncable::SyncName SyncerProtoUtil::NameFromSyncEntity(
// static
syncable::SyncName SyncerProtoUtil::NameFromCommitEntryResponse(
const CommitResponse_EntryResponse& entry) {
- SyncName result(PSTR(""));
-
- AppendUTF8ToPathString(entry.name(), &result.value());
+ SyncName result(entry.name());
if (entry.has_non_unique_name()) {
- AppendUTF8ToPathString(entry.non_unique_name(),
- &result.non_unique_value());
- } else {
- result.non_unique_value() = result.value();
+ result.set_non_unique_value(entry.non_unique_name());
}
return result;
}
diff --git a/chrome/browser/sync/engine/syncer_unittest.cc b/chrome/browser/sync/engine/syncer_unittest.cc
index 288ed42..47a67bc 100644
--- a/chrome/browser/sync/engine/syncer_unittest.cc
+++ b/chrome/browser/sync/engine/syncer_unittest.cc
@@ -27,8 +27,6 @@
#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
-#include "chrome/browser/sync/util/compat_file.h"
#include "chrome/browser/sync/util/event_sys-inl.h"
#include "chrome/test/sync/engine/mock_server_connection.h"
#include "chrome/test/sync/engine/test_directory_setter_upper.h"
@@ -1392,14 +1390,13 @@ TEST_F(SyncerTest, CommitTimeRenameI18N) {
// Verify it was correctly renamed.
{
ReadTransaction trans(dir, __FILE__, __LINE__);
- PathString expectedFolder;
- AppendUTF8ToPathString(i18nString, &expectedFolder);
- AppendUTF8ToPathString("Folder", &expectedFolder);
+ PathString expectedFolder(i18nString);
+ expectedFolder.append("Folder");
Entry entry_folder(&trans, GET_BY_PATH, expectedFolder);
ASSERT_TRUE(entry_folder.good());
PathString expected = expectedFolder + PathString(kPathSeparator);
- AppendUTF8ToPathString(i18nString, &expected);
- AppendUTF8ToPathString("new_entry", &expected);
+ expected.append(i18nString);
+ expected.append("new_entry");
Entry entry_new(&trans, GET_BY_PATH, expected);
ASSERT_TRUE(entry_new.good());
diff --git a/chrome/browser/sync/engine/syncer_util.cc b/chrome/browser/sync/engine/syncer_util.cc
index 4074cd6..6828297 100644
--- a/chrome/browser/sync/engine/syncer_util.cc
+++ b/chrome/browser/sync/engine/syncer_util.cc
@@ -15,7 +15,6 @@
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/syncable/syncable_changes_version.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
#include "chrome/browser/sync/util/path_helpers.h"
#include "chrome/browser/sync/util/sync_types.h"
@@ -329,15 +328,13 @@ void SyncerUtil::UpdateServerFieldsFromUpdate(
local_entry->Put(SERVER_IS_BOOKMARK_OBJECT, server_entry.has_bookmarkdata());
local_entry->Put(SERVER_IS_DIR, server_entry.IsFolder());
if (server_entry.has_singleton_tag()) {
- PathString tag;
- AppendUTF8ToPathString(server_entry.singleton_tag(), &tag);
+ const PathString& tag = server_entry.singleton_tag();
local_entry->Put(SINGLETON_TAG, tag);
}
if (server_entry.has_bookmarkdata() && !server_entry.deleted()) {
const SyncEntity::BookmarkData& bookmark = server_entry.bookmarkdata();
if (bookmark.has_bookmark_url()) {
- PathString url;
- AppendUTF8ToPathString(bookmark.bookmark_url(), &url);
+ const PathString& url = bookmark.bookmark_url();
local_entry->Put(SERVER_BOOKMARK_URL, url);
}
if (bookmark.has_bookmark_favicon()) {
@@ -371,9 +368,8 @@ void SyncerUtil::ApplyExtendedAttributes(
const sync_pb::ExtendedAttributes & extended_attributes =
server_entry.extended_attributes();
for (int i = 0; i < extended_attributes.extendedattribute_size(); i++) {
- PathString pathstring_key;
- AppendUTF8ToPathString(
- extended_attributes.extendedattribute(i).key(), &pathstring_key);
+ const PathString& pathstring_key =
+ extended_attributes.extendedattribute(i).key();
ExtendedAttributeKey key(local_entry->Get(META_HANDLE), pathstring_key);
MutableExtendedAttribute local_attribute(local_entry->write_transaction(),
CREATE, key);
diff --git a/chrome/browser/sync/engine/verify_updates_command.cc b/chrome/browser/sync/engine/verify_updates_command.cc
index 7a23477..83d0257 100644
--- a/chrome/browser/sync/engine/verify_updates_command.cc
+++ b/chrome/browser/sync/engine/verify_updates_command.cc
@@ -12,7 +12,6 @@
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
#include "chrome/browser/sync/util/sync_types.h"
namespace browser_sync {
diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc
index b10659c..523a30f 100644
--- a/chrome/browser/sync/glue/sync_backend_host.cc
+++ b/chrome/browser/sync/glue/sync_backend_host.cc
@@ -3,8 +3,9 @@
// found in the LICENSE file.
#include "build/build_config.h"
-#include "base/file_version_info.h"
+#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/file_version_info.h"
#include "base/string_util.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/sync/glue/change_processor.h"
@@ -174,13 +175,8 @@ void SyncBackendHost::Core::DoInitialize(
DCHECK(success);
syncapi_->SetObserver(this);
- string16 path_str;
-#if defined (OS_WIN)
- path_str = host_->sync_data_folder_path().value();
-#elif defined(OS_LINUX) || defined(OS_MACOSX)
- path_str = UTF8ToUTF16(host_->sync_data_folder_path().value());
-#endif
- success = syncapi_->Init(path_str.c_str(),
+ const FilePath& path_str = host_->sync_data_folder_path();
+ success = syncapi_->Init(path_str,
(service_url.host() + service_url.path()).c_str(),
service_url.EffectiveIntPort(),
kGaiaServiceId,
diff --git a/chrome/browser/sync/syncable/directory_backing_store.cc b/chrome/browser/sync/syncable/directory_backing_store.cc
index 26577d6..173dc0b 100644
--- a/chrome/browser/sync/syncable/directory_backing_store.cc
+++ b/chrome/browser/sync/syncable/directory_backing_store.cc
@@ -71,11 +71,7 @@ static void PathNameMatch16WithEscape(sqlite3_context* context,
#endif
static void RegisterPathNameCollate(sqlite3* dbhandle) {
-#if defined(OS_WIN)
- const int collate = SQLITE_UTF16;
-#else
const int collate = SQLITE_UTF8;
-#endif
CHECK(SQLITE_OK == sqlite3_create_collation(dbhandle, "PATHNAME", collate,
NULL, &ComparePathNames16));
}
@@ -246,7 +242,7 @@ static string ComposeCreateTableColumnSpecs(const ColumnSpec* begin,
// DirectoryBackingStore implementation.
DirectoryBackingStore::DirectoryBackingStore(const PathString& dir_name,
- const PathString& backing_filepath)
+ const FilePath& backing_filepath)
: load_dbhandle_(NULL),
save_dbhandle_(NULL),
dir_name_(dir_name),
@@ -266,7 +262,7 @@ DirectoryBackingStore::~DirectoryBackingStore() {
bool DirectoryBackingStore::OpenAndConfigureHandleHelper(
sqlite3** handle) const {
- if (SQLITE_OK == SqliteOpen(backing_filepath_.c_str(), handle)) {
+ if (SQLITE_OK == SqliteOpen(backing_filepath_, handle)) {
sqlite3_busy_timeout(*handle, kDirectoryBackingStoreBusyTimeoutMs);
RegisterPathNameCollate(*handle);
RegisterPathNameMatch(*handle);
diff --git a/chrome/browser/sync/syncable/directory_backing_store.h b/chrome/browser/sync/syncable/directory_backing_store.h
index a0bf8b1..d12bde7 100644
--- a/chrome/browser/sync/syncable/directory_backing_store.h
+++ b/chrome/browser/sync/syncable/directory_backing_store.h
@@ -7,6 +7,7 @@
#include <set>
+#include "base/file_path.h"
#include "chrome/browser/sync/syncable/dir_open_result.h"
#include "chrome/browser/sync/syncable/syncable.h"
@@ -45,7 +46,7 @@ typedef Directory::MetahandlesIndex MetahandlesIndex;
class DirectoryBackingStore {
public:
DirectoryBackingStore(const PathString& dir_name,
- const PathString& backing_filepath);
+ const FilePath& backing_filepath);
virtual ~DirectoryBackingStore();
@@ -113,7 +114,7 @@ class DirectoryBackingStore {
sqlite3* save_dbhandle_;
PathString dir_name_;
- PathString backing_filepath_;
+ FilePath backing_filepath_;
DISALLOW_COPY_AND_ASSIGN(DirectoryBackingStore);
};
diff --git a/chrome/browser/sync/syncable/directory_manager.cc b/chrome/browser/sync/syncable/directory_manager.cc
index edce2e27c..d934f94 100644
--- a/chrome/browser/sync/syncable/directory_manager.cc
+++ b/chrome/browser/sync/syncable/directory_manager.cc
@@ -10,13 +10,15 @@
#include "base/logging.h"
#include "base/port.h"
+#include "base/scoped_ptr.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/util/event_sys-inl.h"
#include "chrome/browser/sync/util/path_helpers.h"
namespace syncable {
-static const PSTR_CHAR kSyncDataDatabaseFilename[] = PSTR("SyncData.sqlite3");
+static const FilePath::CharType kSyncDataDatabaseFilename[] =
+ FILE_PATH_LITERAL("SyncData.sqlite3");
DirectoryManagerEvent DirectoryManagerShutdownEvent() {
DirectoryManagerEvent event;
@@ -25,18 +27,16 @@ DirectoryManagerEvent DirectoryManagerShutdownEvent() {
}
// static
-const PathString DirectoryManager::GetSyncDataDatabaseFilename() {
- return PathString(kSyncDataDatabaseFilename);
+const FilePath DirectoryManager::GetSyncDataDatabaseFilename() {
+ return FilePath(kSyncDataDatabaseFilename);
}
-const PathString DirectoryManager::GetSyncDataDatabasePath() const {
- PathString path(root_path_);
- path.append(kSyncDataDatabaseFilename);
- return path;
+const FilePath DirectoryManager::GetSyncDataDatabasePath() const {
+ return root_path_.Append(GetSyncDataDatabaseFilename());
}
-DirectoryManager::DirectoryManager(const PathString& path)
- : root_path_(AppendSlash(path)),
+DirectoryManager::DirectoryManager(const FilePath& path)
+ : root_path_(path),
managed_directory_(NULL),
channel_(new Channel(DirectoryManagerShutdownEvent())) {
}
@@ -68,7 +68,7 @@ bool DirectoryManager::Open(const PathString& name) {
// Opens a directory. Returns false on error.
DirOpenResult DirectoryManager::OpenImpl(const PathString& name,
- const PathString& path,
+ const FilePath& path,
bool* was_open) {
bool opened = false;
{
@@ -85,13 +85,11 @@ DirOpenResult DirectoryManager::OpenImpl(const PathString& name,
return syncable::OPENED;
// Otherwise, open it.
- Directory* dir = new Directory;
+ scoped_ptr<Directory> dir(new Directory);
const DirOpenResult result = dir->Open(path, name);
if (syncable::OPENED == result) {
AutoLock lock(lock_);
- managed_directory_ = dir;
- } else {
- delete dir;
+ managed_directory_ = dir.release();
}
return result;
}
diff --git a/chrome/browser/sync/syncable/directory_manager.h b/chrome/browser/sync/syncable/directory_manager.h
index f059257..5d9a106 100644
--- a/chrome/browser/sync/syncable/directory_manager.h
+++ b/chrome/browser/sync/syncable/directory_manager.h
@@ -15,8 +15,9 @@
#include <vector>
#include "base/atomicops.h"
-#include "base/lock.h"
#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "base/lock.h"
#include "chrome/browser/sync/syncable/dir_open_result.h"
#include "chrome/browser/sync/syncable/path_name_cmp.h"
#include "chrome/browser/sync/syncable/syncable.h"
@@ -50,11 +51,11 @@ class DirectoryManager {
typedef EventChannel<DirectoryManagerEvent> Channel;
// root_path specifies where db is stored.
- explicit DirectoryManager(const PathString& root_path);
+ explicit DirectoryManager(const FilePath& root_path);
~DirectoryManager();
- static const PathString GetSyncDataDatabaseFilename();
- const PathString GetSyncDataDatabasePath() const;
+ static const FilePath GetSyncDataDatabaseFilename();
+ const FilePath GetSyncDataDatabasePath() const;
// Opens a directory. Returns false on error.
// Name parameter is the the user's login,
@@ -75,13 +76,13 @@ class DirectoryManager {
Channel* channel() const { return channel_; }
protected:
- DirOpenResult OpenImpl(const PathString& name, const PathString& path,
+ DirOpenResult OpenImpl(const PathString& name, const FilePath& path,
bool* was_open);
// Helpers for friend class ScopedDirLookup:
friend class ScopedDirLookup;
- const PathString root_path_;
+ const FilePath root_path_;
// protects managed_directory_
Lock lock_;
diff --git a/chrome/browser/sync/syncable/syncable.cc b/chrome/browser/sync/syncable/syncable.cc
index 550c495..0ba9dab 100644
--- a/chrome/browser/sync/syncable/syncable.cc
+++ b/chrome/browser/sync/syncable/syncable.cc
@@ -26,9 +26,11 @@
#include <string>
#include "base/hash_tables.h"
+#include "base/file_util.h"
#include "base/logging.h"
#include "base/perftimer.h"
#include "base/scoped_ptr.h"
+#include "base/string_util.h"
#include "base/time.h"
#include "chrome/browser/sync/engine/syncer.h"
#include "chrome/browser/sync/engine/syncer_util.h"
@@ -38,8 +40,6 @@
#include "chrome/browser/sync/syncable/syncable-inl.h"
#include "chrome/browser/sync/syncable/syncable_changes_version.h"
#include "chrome/browser/sync/syncable/syncable_columns.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
-#include "chrome/browser/sync/util/compat_file.h"
#include "chrome/browser/sync/util/crypto_helpers.h"
#include "chrome/browser/sync/util/event_sys-inl.h"
#include "chrome/browser/sync/util/fast_dump.h"
@@ -90,15 +90,6 @@ int64 Now() {
// Callback for sqlite3
int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes,
const void* b) {
-#if defined(OS_WIN)
- DCHECK_EQ(0, a_bytes % 2);
- DCHECK_EQ(0, b_bytes % 2);
- int result = CompareString(LOCALE_INVARIANT, NORM_IGNORECASE,
- static_cast<const PathChar*>(a), a_bytes / 2,
- static_cast<const PathChar*>(b), b_bytes / 2);
- CHECK(0 != result) << "Error comparing strings: " << GetLastError();
- return result - 2; // Convert to -1, 0, 1
-#elif defined(OS_LINUX)
int result = base::strncasecmp(reinterpret_cast<const char *>(a),
reinterpret_cast<const char *>(b),
std::min(a_bytes, b_bytes));
@@ -107,21 +98,6 @@ int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes,
} else {
return a_bytes > b_bytes ? 1 : b_bytes > a_bytes ? -1 : 0;
}
-#elif defined(OS_MACOSX)
- CFStringRef a_str;
- CFStringRef b_str;
- a_str = CFStringCreateWithBytes(NULL, reinterpret_cast<const UInt8*>(a),
- a_bytes, kCFStringEncodingUTF8, FALSE);
- b_str = CFStringCreateWithBytes(NULL, reinterpret_cast<const UInt8*>(b),
- b_bytes, kCFStringEncodingUTF8, FALSE);
- CFComparisonResult res;
- res = CFStringCompare(a_str, b_str, kCFCompareCaseInsensitive);
- CFRelease(a_str);
- CFRelease(b_str);
- return res;
-#else
-#error no ComparePathNames16() for your OS
-#endif
}
template <Int64Field field_index>
@@ -177,7 +153,7 @@ Name Name::FromEntryKernel(EntryKernel* kernel) {
static const DirectoryChangeEvent kShutdownChangesEvent =
{ DirectoryChangeEvent::SHUTDOWN, 0, 0 };
-Directory::Kernel::Kernel(const PathString& db_path,
+Directory::Kernel::Kernel(const FilePath& db_path,
const PathString& name,
const KernelLoadInfo& info)
: db_path(db_path),
@@ -247,7 +223,7 @@ BOOL PathNameMatch(const PathString& pathname, const PathString& pathspec) {
++pathname_ptr, ++pathspec_ptr;
// If we have more inital spaces in the pathspec than in the pathname then the
- // result from PathMatchSpec will be erronous.
+ // result from PathMatchSpec will be erroneous.
if (*pathspec_ptr == ' ')
return FALSE;
@@ -257,10 +233,10 @@ BOOL PathNameMatch(const PathString& pathname, const PathString& pathspec) {
// substituting ';' with ':' which is illegal character in file name and
// we're not going to see it there. With ':' in path name and spec
// PathMatchSpec works fine.
- if ((NULL == wcschr(pathname_ptr, L';')) &&
- (NULL == wcschr(pathspec_ptr, L';'))) {
+ if ((NULL == strchr(pathname_ptr, ';')) &&
+ (NULL == strchr(pathspec_ptr, ';'))) {
// No ';' in file name and in spec. Just pass it as it is.
- return ::PathMatchSpec(pathname_ptr, pathspec_ptr);
+ return ::PathMatchSpecA(pathname_ptr, pathspec_ptr);
}
// We need to subst ';' with ':' in both, name and spec.
@@ -269,23 +245,23 @@ BOOL PathNameMatch(const PathString& pathname, const PathString& pathspec) {
PathString::size_type index = name_subst.find(L';');
while (PathString::npos != index) {
- name_subst[index] = L':';
- index = name_subst.find(L';', index + 1);
+ name_subst[index] = ':';
+ index = name_subst.find(';', index + 1);
}
index = spec_subst.find(L';');
while (PathString::npos != index) {
- spec_subst[index] = L':';
- index = spec_subst.find(L';', index + 1);
+ spec_subst[index] = ':';
+ index = spec_subst.find(';', index + 1);
}
- return ::PathMatchSpec(name_subst.c_str(), spec_subst.c_str());
+ return ::PathMatchSpecA(name_subst.c_str(), spec_subst.c_str());
#else
return 0 == ComparePathNames(pathname, pathspec);
#endif
}
-DirOpenResult Directory::Open(const PathString& file_path,
+DirOpenResult Directory::Open(const FilePath& file_path,
const PathString& name) {
const DirOpenResult result = OpenImpl(file_path, name);
if (OPENED != result)
@@ -308,18 +284,19 @@ void Directory::InitializeIndices() {
}
DirectoryBackingStore* Directory::CreateBackingStore(
- const PathString& dir_name, const PathString& backing_filepath) {
+ const PathString& dir_name, const FilePath& backing_filepath) {
return new DirectoryBackingStore(dir_name, backing_filepath);
}
-DirOpenResult Directory::OpenImpl(const PathString& file_path,
+DirOpenResult Directory::OpenImpl(const FilePath& file_path,
const PathString& name) {
DCHECK_EQ(static_cast<DirectoryBackingStore*>(NULL), store_);
- const PathString db_path = ::GetFullPath(file_path);
+ FilePath db_path(file_path);
+ file_util::AbsolutePath(&db_path);
store_ = CreateBackingStore(name, db_path);
KernelLoadInfo info;
- // Temporary indicies before kernel_ initialized in case Load fails. We 0(1)
+ // Temporary indices before kernel_ initialized in case Load fails. We 0(1)
// swap these later.
MetahandlesIndex metas_bucket;
ExtendedAttributes xattrs_bucket;
@@ -506,62 +483,6 @@ struct ExactPathMatcher : public PathMatcher {
const PathString pathspec_;
};
-// Matches a pathspec with wildcards.
-struct PartialPathMatcher : public PathMatcher {
- PartialPathMatcher(const PathString& pathspec,
- PathString::size_type wildcard, const Id& parent_id)
- : PathMatcher(parent_id), pathspec_(pathspec) {
- if (0 == wildcard)
- return;
- lesser_.assign(pathspec_.data(), wildcard);
- greater_.assign(pathspec_.data(), wildcard);
- // Increment the last letter of greater so we can then less than
- // compare to it.
- PathString::size_type i = greater_.size() - 1;
- do {
- if (greater_[i] == std::numeric_limits<PathString::value_type>::max()) {
- greater_.resize(i); // Try the preceding character.
- if (0 == i--)
- break;
- } else {
- greater_[i] += 1;
- }
- // Yes, there are cases where incrementing a character
- // actually decreases its position in the sort. Example: 9 -> :
- } while (ComparePathNames(lesser_, greater_) >= 0);
- }
-
- virtual MatchType PathMatches(const PathString& path) {
- return PathNameMatch(path, pathspec_) ? MATCH : NO_MATCH;
- }
-
- virtual Index::iterator lower_bound(Index* index) {
- needle_.ref(PARENT_ID) = parent_id_;
- needle_.ref(NAME) = lesser_;
- return index->lower_bound(&needle_);
- }
- virtual Index::iterator upper_bound(Index* index) {
- if (greater_.empty()) {
- needle_.ref(PARENT_ID) = parent_id_;
- needle_.ref(NAME).clear();
- Index::iterator i = index->upper_bound(&needle_),
- end = index->end();
- while (i != end && (*i)->ref(PARENT_ID) == parent_id_)
- ++i;
- return i;
- } else {
- needle_.ref(PARENT_ID) = parent_id_;
- needle_.ref(NAME) = greater_;
- return index->lower_bound(&needle_);
- }
- }
-
- const PathString pathspec_;
- PathString lesser_;
- PathString greater_;
-};
-
-
void Directory::GetChildHandles(BaseTransaction* trans, const Id& parent_id,
Directory::ChildHandles* result) {
AllPathsMatcher matcher(parent_id);
@@ -1658,25 +1579,7 @@ static int PathStringToInteger(PathString s) {
if (PathString::npos == PathString(PSTR("0123456789")).find(*i))
return -1;
}
- return
-#if !PATHSTRING_IS_STD_STRING
- _wtoi
-#else
- atoi
-#endif
- (s.c_str());
-}
-
-static PathString IntegerToPathString(int i) {
- const size_t kBufSize = 25;
- PathChar buf[kBufSize];
-#if !PATHSTRING_IS_STD_STRING
- const int radix = 10;
- _itow(i, buf, radix);
-#else
- snprintf(buf, kBufSize, "%d", i);
-#endif
- return buf;
+ return atoi(s.c_str());
}
// appends ~1 to the end of 's' unless there is already ~#, in which case
@@ -1690,7 +1593,7 @@ static PathString FixBasenameInCollision(const PathString s) {
if ((n = PathStringToInteger(s.substr(last_tilde + 1))) != -1) {
n++;
PathString pre_number = s.substr(0, last_tilde + 1);
- return pre_number + IntegerToPathString(n);
+ return pre_number + IntToString(n);
} else {
// we have a ~, but not a number following it, so we'll add another
// ~ and this time, a number
@@ -1724,31 +1627,6 @@ void DBName::MakeNoncollidingForEntry(BaseTransaction* trans,
swap(new_value);
}
-PathString GetFullPath(BaseTransaction* trans, const Entry& e) {
- PathString result;
-#if defined(COMPILER_MSVC)
- result.reserve(MAX_PATH);
-#endif
- ReverseAppend(e.Get(NAME), &result);
- Id id = e.Get(PARENT_ID);
- while (!id.IsRoot()) {
- result.push_back(kPathSeparator[0]);
- Entry ancestor(trans, GET_BY_ID, id);
- if (!ancestor.good()) {
- // This can happen if the parent folder got deleted before the entry.
- LOG(WARNING) << "Cannot get full path of " << e
- << "\nbecause an ancestor folder has been deleted.";
- result.clear();
- return result;
- }
- ReverseAppend(ancestor.Get(NAME), &result);
- id = ancestor.Get(PARENT_ID);
- }
- result.push_back(kPathSeparator[0]);
- reverse(result.begin(), result.end());
- return result;
-}
-
const Blob* GetExtendedAttributeValue(const Entry& e,
const PathString& attribute_name) {
ExtendedAttributeKey key(e.Get(META_HANDLE), attribute_name);
@@ -1788,7 +1666,6 @@ inline FastDump& operator<<(FastDump& dump, const DumpColon&) {
std::ostream& operator<<(std::ostream& stream, const syncable::Entry& entry) {
// Using ostreams directly here is dreadfully slow, because a mutex is
// acquired for every <<. Users noticed it spiking CPU.
- using browser_sync::ToUTF8;
using syncable::BitField;
using syncable::BitTemp;
using syncable::BlobField;
@@ -1823,8 +1700,8 @@ std::ostream& operator<<(std::ostream& stream, const syncable::Entry& entry) {
s << g_metas_columns[i].name << separator;
}
for ( ; i < STRING_FIELDS_END; ++i) {
- ToUTF8 field(kernel->ref(static_cast<StringField>(i)));
- s << g_metas_columns[i].name << colon << field.get_string() << separator;
+ const PathString& field = kernel->ref(static_cast<StringField>(i));
+ s << g_metas_columns[i].name << colon << field << separator;
}
for ( ; i < BLOB_FIELDS_END; ++i) {
s << g_metas_columns[i].name << colon
diff --git a/chrome/browser/sync/syncable/syncable.h b/chrome/browser/sync/syncable/syncable.h
index 5c6195e..c92ea7b 100644
--- a/chrome/browser/sync/syncable/syncable.h
+++ b/chrome/browser/sync/syncable/syncable.h
@@ -15,6 +15,7 @@
#include "base/atomicops.h"
#include "base/basictypes.h"
+#include "base/file_path.h"
#include "base/lock.h"
#include "base/time.h"
#include "chrome/browser/sync/syncable/blob.h"
@@ -22,7 +23,6 @@
#include "chrome/browser/sync/syncable/directory_event.h"
#include "chrome/browser/sync/syncable/path_name_cmp.h"
#include "chrome/browser/sync/syncable/syncable_id.h"
-#include "chrome/browser/sync/util/compat_file.h"
#include "chrome/browser/sync/util/dbgq.h"
#include "chrome/browser/sync/util/event_sys.h"
#include "chrome/browser/sync/util/path_helpers.h"
@@ -319,6 +319,9 @@ class SyncName {
PathString& value() { return value_; }
const PathString& non_unique_value() const { return non_unique_value_; }
PathString& non_unique_value() { return non_unique_value_; }
+ void set_non_unique_value(const PathString& value) {
+ non_unique_value_ = value;
+ }
inline bool operator==(const SyncName& right_hand_side) const {
return value_ == right_hand_side.value_ &&
@@ -886,7 +889,7 @@ class Directory {
Directory();
virtual ~Directory();
- DirOpenResult Open(const PathString& file_path, const PathString& name);
+ DirOpenResult Open(const FilePath& file_path, const PathString& name);
void Close();
@@ -895,7 +898,7 @@ class Directory {
// by the server only.
Id NextId();
- PathString file_path() const { return kernel_->db_path; }
+ const FilePath& file_path() const { return kernel_->db_path; }
bool good() const { return NULL != store_; }
// The sync timestamp is an index into the list of changes for an account.
@@ -938,7 +941,7 @@ class Directory {
// Overridden by tests.
virtual DirectoryBackingStore* CreateBackingStore(
const PathString& dir_name,
- const PathString& backing_filepath);
+ const FilePath& backing_filepath);
private:
// These private versions expect the kernel lock to already be held
@@ -951,7 +954,7 @@ class Directory {
const PathString& name,
ScopedKernelLock* const lock);
- DirOpenResult OpenImpl(const PathString& file_path, const PathString& name);
+ DirOpenResult OpenImpl(const FilePath& file_path, const PathString& name);
struct DirectoryEventTraits {
typedef DirectoryEvent EventType;
@@ -1086,12 +1089,12 @@ class Directory {
private:
struct Kernel {
- Kernel(const PathString& db_path, const PathString& name,
+ Kernel(const FilePath& db_path, const PathString& name,
const KernelLoadInfo& info);
~Kernel();
- PathString const db_path;
+ FilePath const db_path;
// TODO(timsteele): audit use of the member and remove if possible
volatile base::subtle::AtomicWord refcount;
void AddRef(); // For convenience.
@@ -1254,12 +1257,6 @@ int64 Now();
// Does wildcard processing.
BOOL PathNameMatch(const PathString& pathname, const PathString& pathspec);
-PathString GetFullPath(BaseTransaction* trans, const Entry& e);
-
-inline void ReverseAppend(const PathString& s, PathString* target) {
- target->append(s.rbegin(), s.rend());
-}
-
class ExtendedAttribute {
public:
ExtendedAttribute(BaseTransaction* trans, GetByHandle,
diff --git a/chrome/browser/sync/syncable/syncable_unittest.cc b/chrome/browser/sync/syncable/syncable_unittest.cc
index db5bc08..d5bcd8c 100644
--- a/chrome/browser/sync/syncable/syncable_unittest.cc
+++ b/chrome/browser/sync/syncable/syncable_unittest.cc
@@ -30,13 +30,14 @@
#endif // !defined(OS_WIN)
#include "base/at_exit.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
#include "base/logging.h"
#include "base/platform_thread.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/sync/syncable/directory_backing_store.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/util/closure.h"
-#include "chrome/browser/sync/util/compat_file.h"
#include "chrome/browser/sync/util/event_sys-inl.h"
#include "chrome/browser/sync/util/path_helpers.h"
#include "chrome/browser/sync/util/query_helpers.h"
@@ -78,7 +79,8 @@ void ExpectDataFromExtendedAttributeEquals(BaseTransaction* trans,
TEST(Syncable, General) {
remove("SimpleTest.sqlite3");
Directory dir;
- dir.Open(PSTR("SimpleTest.sqlite3"), PSTR("SimpleTest"));
+ FilePath test_db(FILE_PATH_LITERAL("SimpleTest.sqlite3"));
+ dir.Open(test_db, PSTR("SimpleTest"));
bool entry_exists = false;
int64 metahandle;
const Id id = TestIdFactory::FromNumber(99);
@@ -176,14 +178,14 @@ class TestUnsaveableDirectory : public Directory {
class UnsaveableBackingStore : public DirectoryBackingStore {
public:
UnsaveableBackingStore(const PathString& dir_name,
- const PathString& backing_filepath)
+ const FilePath& backing_filepath)
: DirectoryBackingStore(dir_name, backing_filepath) { }
virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot) {
return false;
}
};
virtual DirectoryBackingStore* CreateBackingStore(
- const PathString& dir_name, const PathString& backing_filepath) {
+ const PathString& dir_name, const FilePath& backing_filepath) {
return new UnsaveableBackingStore(dir_name, backing_filepath);
}
};
@@ -191,18 +193,18 @@ class TestUnsaveableDirectory : public Directory {
// Test suite for syncable::Directory.
class SyncableDirectoryTest : public testing::Test {
protected:
- static const PathString kFilePath;
+ static const FilePath::CharType kFilePath[];
static const PathString kName;
- static const PathChar* kSqlite3File;
static const Id kId;
// SetUp() is called before each test case is run.
// The sqlite3 DB is deleted before each test is run.
virtual void SetUp() {
- PathRemove(PathString(kSqlite3File));
+ file_path_ = FilePath(kFilePath);
+ file_util::Delete(file_path_, true);
dir_.reset(new Directory());
ASSERT_TRUE(dir_.get());
- ASSERT_TRUE(OPENED == dir_->Open(kFilePath, kName));
+ ASSERT_TRUE(OPENED == dir_->Open(file_path_, kName));
ASSERT_TRUE(dir_->good());
}
@@ -210,10 +212,11 @@ class SyncableDirectoryTest : public testing::Test {
// This also closes file handles.
dir_->SaveChanges();
dir_.reset();
- PathRemove(PathString(kSqlite3File));
+ file_util::Delete(file_path_, true);
}
scoped_ptr<Directory> dir_;
+ FilePath file_path_;
// Creates an empty entry and sets the ID field to the default kId.
void CreateEntry(const PathString &entryname) {
@@ -239,8 +242,8 @@ class SyncableDirectoryTest : public testing::Test {
bool set_server_fields, bool is_dir, bool add_to_lru, int64 *meta_handle);
};
-const PathString SyncableDirectoryTest::kFilePath(PSTR("Test.sqlite3"));
-const PathChar* SyncableDirectoryTest::kSqlite3File(PSTR("Test.sqlite3"));
+const FilePath::CharType SyncableDirectoryTest::kFilePath[] =
+ FILE_PATH_LITERAL("Test.sqlite3");
const PathString SyncableDirectoryTest::kName(PSTR("Foo"));
const Id SyncableDirectoryTest::kId(TestIdFactory::FromNumber(-99));
@@ -291,27 +294,6 @@ TEST_F(SyncableDirectoryTest, TestDelete) {
ASSERT_TRUE(e1.Put(IS_DEL, true));
}
-TEST_F(SyncableDirectoryTest, TestGetFullPathNeverCrashes) {
- PathString dirname = PSTR("honey"),
- childname = PSTR("jelly");
- WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__);
- MutableEntry e1(&trans, CREATE, trans.root_id(), dirname);
- ASSERT_TRUE(e1.good());
- ASSERT_TRUE(e1.Put(IS_DIR, true));
- MutableEntry e2(&trans, CREATE, e1.Get(ID), childname);
- ASSERT_TRUE(e2.good());
- PathString path = GetFullPath(&trans, e2);
- ASSERT_FALSE(path.empty());
- // Give the child a parent that doesn't exist.
- e2.Put(PARENT_ID, TestIdFactory::FromNumber(42));
- path = GetFullPath(&trans, e2);
- ASSERT_TRUE(path.empty());
- // Done testing, make sure CheckTreeInvariants doesn't choke.
- e2.Put(PARENT_ID, e1.Get(ID));
- e2.Put(IS_DEL, true);
- e1.Put(IS_DEL, true);
-}
-
TEST_F(SyncableDirectoryTest, TestGetUnsynced) {
Directory::UnsyncedMetaHandles handles;
int64 handle1, handle2;
@@ -723,7 +705,7 @@ TEST_F(SyncableDirectoryTest, TestSaveChangesFailure) {
dir_.reset(new TestUnsaveableDirectory());
ASSERT_TRUE(dir_.get());
- ASSERT_TRUE(OPENED == dir_->Open(kFilePath, kName));
+ ASSERT_TRUE(OPENED == dir_->Open(FilePath(kFilePath), kName));
ASSERT_TRUE(dir_->good());
int64 handle2 = 0;
{
@@ -775,13 +757,13 @@ void SyncableDirectoryTest::ValidateEntry(BaseTransaction* trans, int64 id,
}
TEST(SyncableDirectoryManager, TestFileRelease) {
- DirectoryManager dm(PSTR("."));
+ DirectoryManager dm(FilePath(FILE_PATH_LITERAL(".")));
ASSERT_TRUE(dm.Open(PSTR("ScopeTest")));
{
ScopedDirLookup(&dm, PSTR("ScopeTest"));
}
dm.Close(PSTR("ScopeTest"));
- ASSERT_TRUE(0 == PathRemove(dm.GetSyncDataDatabasePath()));
+ ASSERT_TRUE(file_util::Delete(dm.GetSyncDataDatabasePath(), true));
}
class ThreadOpenTestDelegate : public PlatformThread::Delegate {
@@ -800,7 +782,7 @@ class ThreadOpenTestDelegate : public PlatformThread::Delegate {
};
TEST(SyncableDirectoryManager, ThreadOpenTest) {
- DirectoryManager dm(PSTR("."));
+ DirectoryManager dm(FilePath(FILE_PATH_LITERAL(".")));
PlatformThreadHandle thread_handle;
ThreadOpenTestDelegate test_delegate(&dm);
ASSERT_TRUE(PlatformThread::Create(0, &test_delegate, &thread_handle));
@@ -881,7 +863,7 @@ class ThreadBugDelegate : public PlatformThread::Delegate {
TEST(SyncableDirectoryManager, ThreadBug1) {
Step step;
step.number = 0;
- DirectoryManager dirman(PSTR("."));
+ DirectoryManager dirman(FilePath(FILE_PATH_LITERAL(".")));
ThreadBugDelegate thread_delegate_1(0, &step, &dirman);
ThreadBugDelegate thread_delegate_2(1, &step, &dirman);
@@ -918,7 +900,8 @@ class DirectoryKernelStalenessBugDelegate : public ThreadBugDelegate {
case 0:
{
// Clean up remnants of earlier test runs.
- PathRemove(directory_manager_->GetSyncDataDatabasePath());
+ file_util::Delete(directory_manager_->GetSyncDataDatabasePath(),
+ true);
// Test.
directory_manager_->Open(dirname);
ScopedDirLookup dir(directory_manager_, dirname);
@@ -974,7 +957,7 @@ class DirectoryKernelStalenessBugDelegate : public ThreadBugDelegate {
TEST(SyncableDirectoryManager, DirectoryKernelStalenessBug) {
Step step;
- DirectoryManager dirman(PSTR("."));
+ DirectoryManager dirman(FilePath(FILE_PATH_LITERAL(".")));
DirectoryKernelStalenessBugDelegate thread_delegate_1(0, &step, &dirman);
DirectoryKernelStalenessBugDelegate thread_delegate_2(1, &step, &dirman);
@@ -1034,9 +1017,9 @@ class StressTransactionsDelegate : public PlatformThread::Delegate {
};
TEST(SyncableDirectory, StressTransactions) {
- DirectoryManager dirman(PSTR("."));
+ DirectoryManager dirman(FilePath(FILE_PATH_LITERAL(".")));
PathString dirname = PSTR("stress");
- PathRemove(dirman.GetSyncDataDatabasePath());
+ file_util::Delete(dirman.GetSyncDataDatabasePath(), true);
dirman.Open(dirname);
const int kThreadCount = 7;
@@ -1055,7 +1038,7 @@ TEST(SyncableDirectory, StressTransactions) {
}
dirman.Close(dirname);
- PathRemove(dirman.GetSyncDataDatabasePath());
+ file_util::Delete(dirman.GetSyncDataDatabasePath(), true);
}
TEST(Syncable, ComparePathNames) {
diff --git a/chrome/browser/sync/util/character_set_converters.cc b/chrome/browser/sync/util/character_set_converters.cc
index a9114cf3..3c66c35 100644
--- a/chrome/browser/sync/util/character_set_converters.cc
+++ b/chrome/browser/sync/util/character_set_converters.cc
@@ -4,51 +4,44 @@
#include "chrome/browser/sync/util/character_set_converters.h"
-#include <string>
-
-using std::string;
-
namespace browser_sync {
-void PathStringToUTF8(const PathChar* wide, int size,
- std::string* output_string) {
- CHECK(output_string);
- output_string->clear();
- AppendPathStringToUTF8(wide, size, output_string);
-}
-
-bool UTF8ToPathString(const char* utf8, size_t size,
- PathString* output_string) {
- CHECK(output_string);
- output_string->clear();
- return AppendUTF8ToPathString(utf8, size, output_string);
-};
-
-ToUTF8::ToUTF8(const PathChar* wide, size_t size) {
- PathStringToUTF8(wide, size, &result_);
-}
-
-ToUTF8::ToUTF8(const PathString& wide) {
- PathStringToUTF8(wide.data(), wide.length(), &result_);
-}
-
-ToUTF8::ToUTF8(const PathChar* wide) {
- PathStringToUTF8(wide, PathLen(wide), &result_);
-}
-
-ToPathString::ToPathString(const char* utf8, size_t size) {
- good_ = UTF8ToPathString(utf8, size, &result_);
- good_checked_ = false;
-}
-
-ToPathString::ToPathString(const std::string& utf8) {
- good_ = UTF8ToPathString(utf8.data(), utf8.length(), &result_);
- good_checked_ = false;
-}
-
-ToPathString::ToPathString(const char* utf8) {
- good_ = UTF8ToPathString(utf8, strlen(utf8), &result_);
- good_checked_ = false;
+void TrimPathStringToValidCharacter(PathString* string) {
+ // Constants from http://en.wikipedia.org/wiki/UTF-8
+ CHECK(string);
+ if (string->empty())
+ return;
+ if (0 == (string->at(string->length() - 1) & 0x080))
+ return;
+ size_t partial_enc_bytes = 0;
+ for (partial_enc_bytes = 0 ; true ; ++partial_enc_bytes) {
+ if (4 == partial_enc_bytes || partial_enc_bytes == string->length()) {
+ // original string was broken, garbage in, garbage out.
+ return;
+ }
+ PathChar c = string->at(string->length() - 1 - partial_enc_bytes);
+ if ((c & 0x0c0) == 0x080) // utf continuation char;
+ continue;
+ if ((c & 0x0e0) == 0x0e0) { // 2-byte encoded char.
+ if (1 == partial_enc_bytes)
+ return;
+ else
+ break;
+ }
+ if ((c & 0x0f0) == 0xc0) { // 3-byte encoded char.
+ if (2 == partial_enc_bytes)
+ return;
+ else
+ break;
+ }
+ if ((c & 0x0f8) == 0x0f0) { // 4-byte encoded char.
+ if (3 == partial_enc_bytes)
+ return;
+ else
+ break;
+ }
+ }
+ string->resize(string->length() - 1 - partial_enc_bytes);
}
} // namespace browser_sync
diff --git a/chrome/browser/sync/util/character_set_converters.h b/chrome/browser/sync/util/character_set_converters.h
index 6a833ee..44aa8a7 100644
--- a/chrome/browser/sync/util/character_set_converters.h
+++ b/chrome/browser/sync/util/character_set_converters.h
@@ -5,240 +5,21 @@
#ifndef CHROME_BROWSER_SYNC_UTIL_CHARACTER_SET_CONVERTERS_H_
#define CHROME_BROWSER_SYNC_UTIL_CHARACTER_SET_CONVERTERS_H_
-// A pair of classes to convert UTF8 <-> UCS2 character strings.
-//
-// Note that the current implementation is limited to UCS2, whereas the
-// interface is agnostic to the wide encoding used.
-//
-// Also note that UCS2 is different from UTF-16, in that UTF-16 can encode all
-// the code points in the Unicode character set by multi-character encodings,
-// while UCS2 is limited to encoding < 2^16 code points.
-//
-// It appears that Windows support UTF-16, which means we have to be careful
-// what we feed this class.
-//
-// Usage:
-// string utf8;
-// CHECK(browser_sync::Append(wide_string, &utf8));
-// PathString bob;
-// CHECK(browser_sync::Append(utf8, &bob));
-// PathString fred = bob;
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/logging.h"
-#include "base/string16.h"
+#include "base/file_path.h"
#include "chrome/browser/sync/util/sync_types.h"
// Need to cast literals (Linux, OSX)
#define STRING16_UGLY_DOUBLE_DEFINE_HACK(s) \
- reinterpret_cast<const char16*>(L##s)
+ reinterpret_cast<const char16*>(L##s)
#define STRING16(s) STRING16_UGLY_DOUBLE_DEFINE_HACK(s)
-using std::string;
-
namespace browser_sync {
-// These 2 classes are deprecated. Instead, prefer the Append() functions.
-
-// A class to convert wide -> UTF8.
-class ToUTF8 {
- public:
- explicit ToUTF8(const PathChar* wide);
- ToUTF8(const PathChar* wide, PathString::size_type size);
- explicit ToUTF8(const PathString& wide);
-
- // cast operators
- operator const std::string&() const;
- operator const char*() const;
-
- // accessors
- const std::string& get_string() const;
- const char* data() const;
- std::string::size_type byte_length() const;
-
- private:
- std::string result_;
-};
-
-// A class to convert UTF8 -> wide.
-class ToPathString {
- public:
- explicit ToPathString(const char*);
- ToPathString(const char*, size_t size);
- explicit ToPathString(const std::string&);
-
- // true iff UTF-8 to wide conversion succeeded in constructor.
- bool good() {
- good_checked_ = true;
- return good_;
- }
-
- // It's invalid to invoke the accessors or the cast operators unless the
- // string is good and good() has been invoked at least once.
-
- // Implicit casts to const PathString& and const PathChar*
- operator const PathString&() const;
- operator const PathChar*() const;
-
- // Accessors
- const PathString& get_string16() const;
- const PathChar* data() const;
- PathString::size_type length() const;
-
- private:
- PathString result_;
-
- // Conversion succeeded.
- bool good_;
- // good() has been invoked at least once.
- bool good_checked_;
-};
-
-// Converts the UCS2 string "wide" to UTF8 encoding and stores the result in
-// output_string.
-void PathStringToUTF8(const PathChar* wide, int size,
- std::string* output_string);
-
-// Converts UCS2 string wide to UTF8 encoding and appends the result to
-// output_string.
-void AppendPathStringToUTF8(const PathChar* wide, int size,
- std::string* output_string);
-
-// Converts the UTF8 encoded string "utf8" to UCS16 and stores the result in
-// output_string.
-//
-// Returns true iff conversion was successful, false otherwise.
-bool UTF8ToPathString(const char* utf8, size_t size,
- PathString* output_string);
-
-// Converts the UTF8 encoded string "utf8" to UCS2 and appends the result in
-// output_string.
-//
-// Returns true iff conversion was successful, false otherwise.
-bool AppendUTF8ToPathString(const char* utf8, size_t size,
- PathString* output_string);
-
-// Converts the UTF8 encoded string "utf8" to UCS2 and appends the result in
-// output_string.
-//
-// @returns true iff conversion was successful, false otherwise.
-inline bool AppendUTF8ToPathString(const std::string& utf8,
- PathString* output_string) {
- return AppendUTF8ToPathString(utf8.data(), utf8.length(), output_string);
-}
-
-// Converts UCS2 string wide to UTF8 encoding and appends the result to
-// output_string.
-inline void AppendPathStringToUTF8(const PathString& wide,
- std::string* output_string) {
- return AppendPathStringToUTF8(wide.data(), wide.length(), output_string);
-}
-
-// Versions of UTF8ToPathString/PathStringToUTF8 that return the converted
-// string directly. Any errors encountered will CHECK(). These functions are
-// intended to be used only for testing.
-
-inline PathString UTF8ToPathStringQuick(const std::string &utf8) {
- PathString wide;
- CHECK(UTF8ToPathString(utf8.data(), utf8.size(), &wide));
- return wide;
-}
-
-inline std::string PathStringToUTF8Quick(const PathString& wide) {
- std::string utf8;
- PathStringToUTF8(wide.data(), wide.size(), &utf8);
- return utf8;
-}
-
-inline bool Append(const PathChar* wide, int size,
- std::string* output_string) {
- AppendPathStringToUTF8(wide, size, output_string);
- return true;
-}
-
-inline bool Append(const PathChar* wide, std::string* output_string) {
- AppendPathStringToUTF8(wide, PathLen(wide), output_string);
- return true;
-}
-
-inline bool Append(const std::string& utf8, PathString* output_string) {
- return AppendUTF8ToPathString(utf8.data(), utf8.length(), output_string);
-}
-
-#if !PATHSTRING_IS_STD_STRING
-inline bool Append(const char* utf8, size_t size, PathString* output_string) {
- return AppendUTF8ToPathString(utf8, size, output_string);
-}
-
-inline bool Append(const char* s, int size, std::string* output_string) {
- output_string->append(s, size);
- return true;
-}
-
-inline bool Append(const char* utf8, PathString* output_string) {
- return AppendUTF8ToPathString(utf8, strlen(utf8), output_string);
-}
-
-inline bool Append(const char* s, std::string* output_string) {
- output_string->append(s);
- return true;
-}
-
-inline bool Append(const PathString& wide, std::string* output_string) {
- return Append(wide.data(), wide.length(), output_string);
-}
-
-inline bool Append(const std::string& s, std::string* output_string) {
- return Append(s.data(), s.length(), output_string);
-}
-#endif
-
-inline ToUTF8::operator const std::string&() const {
- return result_;
-}
-
-inline ToUTF8::operator const char*() const {
- return result_.c_str();
-}
-
-inline const std::string& ToUTF8::get_string() const {
- return result_;
-}
-
-inline const char* ToUTF8::data() const {
- return result_.data();
-}
-
-inline std::string::size_type ToUTF8::byte_length() const {
- return result_.size();
-}
-
-inline ToPathString::operator const PathString&() const {
- DCHECK(good_ && good_checked_);
- return result_;
-}
-
-inline ToPathString::operator const PathChar*() const {
- DCHECK(good_ && good_checked_);
- return result_.c_str();
-}
-
-inline const PathString& ToPathString::get_string16() const {
- DCHECK(good_ && good_checked_);
- return result_;
-}
-
-inline const PathChar* ToPathString::data() const {
- DCHECK(good_ && good_checked_);
- return result_.data();
-}
+// Returns UTF8 string from the given FilePath.
+std::string FilePathToUTF8(const FilePath& file_path);
-inline PathString::size_type ToPathString::length() const {
- DCHECK(good_ && good_checked_);
- return result_.length();
-}
+// Returns FilePath from the given UTF8 string.
+FilePath UTF8ToFilePath(const std::string& utf8);
void TrimPathStringToValidCharacter(PathString* string);
diff --git a/chrome/browser/sync/util/character_set_converters_posix.cc b/chrome/browser/sync/util/character_set_converters_posix.cc
index ba57214..aba56aa 100644
--- a/chrome/browser/sync/util/character_set_converters_posix.cc
+++ b/chrome/browser/sync/util/character_set_converters_posix.cc
@@ -10,54 +10,14 @@ using std::string;
namespace browser_sync {
-// Converts input_string to UTF8 and appends the result into output_string.
-void AppendPathStringToUTF8(const PathChar *wide, int size,
- string* output_string) {
- output_string->append(wide, size);
+// Returns UTF8 string from the given FilePath.
+std::string FilePathToUTF8(const FilePath& file_path) {
+ return file_path.value();
}
-bool AppendUTF8ToPathString(const char* utf8, size_t size,
- PathString* output_string) {
- output_string->append(utf8, size);
- return true;
-}
-
-void TrimPathStringToValidCharacter(PathString* string) {
- // Constants from http://en.wikipedia.org/wiki/UTF-8
- CHECK(string);
- if (string->empty())
- return;
- if (0 == (string->at(string->length() - 1) & 0x080))
- return;
- size_t partial_enc_bytes = 0;
- for (partial_enc_bytes = 0 ; true ; ++partial_enc_bytes) {
- if (4 == partial_enc_bytes || partial_enc_bytes == string->length()) {
- // original string was broken, garbage in, garbage out.
- return;
- }
- PathChar c = string->at(string->length() - 1 - partial_enc_bytes);
- if ((c & 0x0c0) == 0x080) // utf continuation char;
- continue;
- if ((c & 0x0e0) == 0x0e0) { // 2-byte encoded char.
- if (1 == partial_enc_bytes)
- return;
- else
- break;
- }
- if ((c & 0x0f0) == 0xc0) { // 3-byte encoded char.
- if (2 == partial_enc_bytes)
- return;
- else
- break;
- }
- if ((c & 0x0f8) == 0x0f0) { // 4-byte encoded char.
- if (3 == partial_enc_bytes)
- return;
- else
- break;
- }
- }
- string->resize(string->length() - 1 - partial_enc_bytes);
+// Returns FilePath from the given UTF8 string.
+FilePath UTF8ToFilePath(const std::string& utf8) {
+ return FilePath(utf8);
}
} // namespace browser_sync
diff --git a/chrome/browser/sync/util/character_set_converters_unittest.cc b/chrome/browser/sync/util/character_set_converters_unittest.cc
index 6274a1d..8e75539 100644
--- a/chrome/browser/sync/util/character_set_converters_unittest.cc
+++ b/chrome/browser/sync/util/character_set_converters_unittest.cc
@@ -6,155 +6,23 @@
#include <string>
-#include "base/basictypes.h"
-#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
-using browser_sync::ToPathString;
-using browser_sync::ToUTF8;
-using browser_sync::AppendPathStringToUTF8;
-using browser_sync::AppendUTF8ToPathString;
-using browser_sync::PathStringToUTF8;
-using browser_sync::UTF8ToPathString;
using std::string;
class CharacterSetConverterTest : public testing::Test {
};
-TEST_F(CharacterSetConverterTest, ASCIIConversionTest) {
- string ascii = "Test String";
- PathString wide = PSTR("Test String");
- ToPathString to_wide(ascii);
- ASSERT_TRUE(to_wide.good());
- ToUTF8 to_utf8(wide);
-
- // Using == as gunit doesn't handle PathString equality tests correctly (it
- // tries to print the PathString and fails).
- ASSERT_TRUE(PathString(wide) == to_wide.get_string16());
- ASSERT_EQ(string(ascii), to_utf8.get_string());
- ToPathString to_16(ascii);
- ASSERT_TRUE(to_16.good());
- ASSERT_TRUE(PathString(wide) == to_16.get_string16());
-#if defined(OS_WIN)
- // On Linux, PathString is already UTF8
- ASSERT_EQ(string(ascii), static_cast<string>(ToUTF8(wide)));
-#endif
- // The next line fails the good_checked_ test. It would be a good death test
- // but they don't work on Windows.
- // ASSERT_TRUE(wide == ToPathString(utf8).get_string16());
-}
-
-#if defined(OS_WIN)
- // On Linux, PathString is already UTF8
-TEST_F(CharacterSetConverterTest, UnicodeConversionText) {
- // Source data obtained by running od -b on files saved in utf-8 and unicode
- // from a text editor.
- const char* utf8 = "\357\273\277\150\145\154\154\157\040\303\250\303\251"
- "\302\251\342\202\254\302\243\302\245\302\256\342\204\242";
-// #ifdef IS_LITTLE_ENDIAN
- const PathChar* wide = reinterpret_cast<const PathChar*>("\377\376\150\000"
- "\145\000\154\000\154\000\157\000\040\000\350\000\351\000\251\000\254\040"
- "\243\000\245\000\256\000\042\041");
-// #else
-// // This should work, but on Windows we don't have the endian
-// // macros. Since we only do conversion between 16<->8 on Windows,
-// // it's safe to assume little endian.
-// const PathChar* wide =
-// reinterpret_cast<PathChar*>("\376\377\000\150\000\145\000"
-// "\154\000\154\000\157\000\040\000\350\000\351\000\251\040\254\000\243"
-// "\000\245\000\256\041\042");
-// #endif
-
- ToPathString to_wide(utf8);
- ASSERT_TRUE(to_wide.good());
- ToUTF8 to_utf8(wide);
-
- // Using == as gunit doesn't handle PathString equality tests correctly (it
- // tries to print the PathString and fails).
- ASSERT_TRUE(wide == to_wide.get_string16());
- ASSERT_EQ(string(utf8), to_utf8.get_string());
- ToPathString to_16(utf8);
- ASSERT_TRUE(to_16.good());
- ASSERT_TRUE(wide == to_16.get_string16());
- ASSERT_EQ(string(utf8), reinterpret_cast<const string&>(ToUTF8(wide)));
-}
-#endif // defined(OS_WIN)
-
-TEST_F(CharacterSetConverterTest, AppendUTF8Tests) {
- PathString one = PSTR("one");
- PathString two = PSTR("two");
- PathString three = PSTR("three");
- string out;
- AppendPathStringToUTF8(one.data(), one.length(), &out);
- AppendPathStringToUTF8(two.data(), two.length(), &out);
- AppendPathStringToUTF8(three.data(), three.length(), &out);
- ASSERT_EQ(out, "onetwothree");
- PathString onetwothree = PSTR("onetwothree");
- PathStringToUTF8(onetwothree.data(), onetwothree.length(), &out);
- ASSERT_EQ(out, "onetwothree");
-}
-
-TEST_F(CharacterSetConverterTest, AppendPathStringTests) {
- string one = "one";
- string two = "two";
- string three = "three";
- PathString out;
- AppendUTF8ToPathString(one.data(), one.length(), &out);
- AppendUTF8ToPathString(two.data(), two.length(), &out);
- AppendUTF8ToPathString(three.data(), three.length(), &out);
- ASSERT_TRUE(out == PathString(PSTR("onetwothree")));
- string onetwothree = "onetwothree";
- UTF8ToPathString(onetwothree.data(), onetwothree.length(), &out);
- ASSERT_TRUE(out == PathString(PSTR("onetwothree")));
-}
-
-#if defined(OS_WIN)
-namespace {
-// See http://en.wikipedia.org/wiki/UTF-16 for an explanation of UTF16.
-// For a test case we use the UTF-8 and UTF-16 encoding of char 119070
-// (hex 1D11E), which is musical G clef.
-const unsigned char utf8_test_string[] = {
- 0xEF, 0xBB, 0xBF, // BOM
- 0xE6, 0xB0, 0xB4, // water, Chinese (0x6C34)
- 0x7A, // lower case z
- 0xF0, 0x9D, 0x84, 0x9E, // musical G clef (0x1D11E)
- 0x00,
-};
-const PathChar utf16_test_string[] = {
- 0xFEFF, // BOM
- 0x6C34, // water, Chinese
- 0x007A, // lower case z
- 0xD834, 0xDD1E, // musical G clef (0x1D11E)
- 0x0000,
-};
-}
-
-TEST_F(CharacterSetConverterTest, UTF16ToUTF8Test) {
- // Avoid truncation warning.
- const char* utf8_test_string_pointer =
- reinterpret_cast<const char*>(utf8_test_string);
- ASSERT_STREQ(utf8_test_string_pointer, ToUTF8(utf16_test_string));
-}
-
-TEST_F(CharacterSetConverterTest, utf8_test_stringToUTF16Test) {
- // Avoid truncation warning.
- const char* utf8_test_string_pointer =
- reinterpret_cast<const char*>(utf8_test_string);
- ToPathString converted_utf8(utf8_test_string_pointer);
- ASSERT_TRUE(converted_utf8.good());
- ASSERT_EQ(wcscmp(utf16_test_string, converted_utf8), 0);
-}
-
TEST(NameTruncation, WindowsNameTruncation) {
using browser_sync::TrimPathStringToValidCharacter;
- PathChar array[] = {'1', '2', 0xD950, 0xDF21, '3', '4', 0};
+ PathChar array[] = {'1', '2', '\xc0', '\xe0', '3', '4', '\0'};
PathString message = array;
ASSERT_EQ(message.length(), arraysize(array) - 1);
- int old_length = message.length();
+ string::size_type old_length = message.length();
while (old_length != 0) {
TrimPathStringToValidCharacter(&message);
if (old_length == 4)
- EXPECT_EQ(3, message.length());
+ EXPECT_EQ(3u, message.length());
else
EXPECT_EQ(old_length, message.length());
message.resize(message.length() - 1);
@@ -162,8 +30,3 @@ TEST(NameTruncation, WindowsNameTruncation) {
}
TrimPathStringToValidCharacter(&message);
}
-#else
-
-// TODO(zork): Add unittests here once we're running these tests on linux.
-
-#endif
diff --git a/chrome/browser/sync/util/character_set_converters_win.cc b/chrome/browser/sync/util/character_set_converters_win.cc
index ce1b882..1032f41 100644
--- a/chrome/browser/sync/util/character_set_converters_win.cc
+++ b/chrome/browser/sync/util/character_set_converters_win.cc
@@ -2,61 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/utf_string_conversions.h"
#include "chrome/browser/sync/util/character_set_converters.h"
-#include <windows.h>
-
-#include <string>
-
-using std::string;
-
namespace browser_sync {
-// Converts input_string to UTF8 and appends the result into to output_string.
-void AppendPathStringToUTF8(const PathChar* wide, int size,
- string* output_string) {
- CHECK(output_string);
- if (0 == size)
- return;
-
- int needed_space = ::WideCharToMultiByte(CP_UTF8, 0, wide, size, 0, 0, 0, 0);
- // TODO(sync): This should flag an error when we move to an api that can let
- // utf-16 -> utf-8 fail.
- CHECK(0 != needed_space);
- string::size_type current_size = output_string->size();
- output_string->resize(current_size + needed_space);
- CHECK(0 != ::WideCharToMultiByte(CP_UTF8, 0, wide, size,
- &(*output_string)[current_size], needed_space, 0, 0));
-}
-
-bool AppendUTF8ToPathString(const char* utf8, size_t size,
- PathString* output_string) {
- CHECK(output_string);
- if (0 == size)
- return true;
- // TODO(sync): Do we want to force precomposed characters here?
- int needed_wide_chars = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
- utf8, size, 0, 0);
- if (0 == needed_wide_chars) {
- DWORD err = ::GetLastError();
- if (MB_ERR_INVALID_CHARS == err)
- return false;
- CHECK(0 == err);
- }
- PathString::size_type current_length = output_string->size();
- output_string->resize(current_length + needed_wide_chars);
- CHECK(0 != ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8, size,
- &(*output_string)[current_length], needed_wide_chars));
- return true;
+// Returns UTF8 string from the given FilePath.
+std::string FilePathToUTF8(const FilePath& file_path) {
+ return WideToUTF8(file_path.value());
}
-void TrimPathStringToValidCharacter(PathString* string) {
- CHECK(string);
- // Constants from http://en.wikipedia.org/wiki/UTF-16
- if (string->empty())
- return;
- if (0x0dc00 == (string->at(string->length() - 1) & 0x0fc00))
- string->resize(string->length() - 1);
+// Returns FilePath from the given UTF8 string.
+FilePath UTF8ToFilePath(const std::string& utf8) {
+ return FilePath(UTF8ToWide(utf8));
}
} // namespace browser_sync
diff --git a/chrome/browser/sync/util/compat_file.h b/chrome/browser/sync/util/compat_file.h
deleted file mode 100644
index 011dafe..0000000
--- a/chrome/browser/sync/util/compat_file.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2009 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.
-//
-// File compatibility routines. Useful to delete database files with.
-
-#ifndef CHROME_BROWSER_SYNC_UTIL_COMPAT_FILE_H_
-#define CHROME_BROWSER_SYNC_UTIL_COMPAT_FILE_H_
-
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include "build/build_config.h"
-#include "chrome/browser/sync/util/sync_types.h"
-
-extern const PathChar* const kPathSeparator;
-
-// Path calls for all OSes.
-// Returns 0 on success, non-zero on failure.
-int PathRemove(const PathString& path);
-
-#if defined(OS_WIN)
-inline int PathRemove(const PathString& path) {
- return _wremove(path.c_str());
-}
-#elif (defined(OS_MACOSX) || defined(OS_LINUX))
-inline int PathRemove(const PathString& path) {
- return unlink(path.c_str());
-}
-#endif
-
-#endif // CHROME_BROWSER_SYNC_UTIL_COMPAT_FILE_H_
diff --git a/chrome/browser/sync/util/compat_file_posix.cc b/chrome/browser/sync/util/compat_file_posix.cc
deleted file mode 100644
index f84a379e6..0000000
--- a/chrome/browser/sync/util/compat_file_posix.cc
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) 2009 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 "build/build_config.h"
-
-#if !defined(OS_POSIX)
-#error Compile this file on Mac OS X or Linux only.
-#endif
-
-#include "chrome/browser/sync/util/compat_file.h"
-
-const char* const kPathSeparator = "/";
diff --git a/chrome/browser/sync/util/compat_file_win.cc b/chrome/browser/sync/util/compat_file_win.cc
deleted file mode 100644
index 0c34cd8..0000000
--- a/chrome/browser/sync/util/compat_file_win.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) 2009 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 "chrome/browser/sync/util/compat_file.h"
-
-#include "build/build_config.h"
-
-#ifndef OS_WIN
-#error Compile this file on Windows only.
-#endif
-
-const wchar_t* const kPathSeparator = L"\\";
-
diff --git a/chrome/browser/sync/util/path_helpers.cc b/chrome/browser/sync/util/path_helpers.cc
index a132086..e947e21 100644
--- a/chrome/browser/sync/util/path_helpers.cc
+++ b/chrome/browser/sync/util/path_helpers.cc
@@ -4,151 +4,4 @@
#include "chrome/browser/sync/util/path_helpers.h"
-#include <Shlwapi.h>
-#include <stdlib.h>
-
-#include "base/logging.h"
-#include "base/port.h"
-#include "build/build_config.h"
-#include "chrome/browser/sync/syncable/syncable.h"
-
-#ifndef OS_WIN
-#error Compile this file on Windows only.
-#endif
-
-using std::string;
-
-#if OS_WIN
-const char PATH_SEPARATOR = '\\';
-#else
-const char PATH_SEPARATOR = '/';
-#endif // OS_WIN
-
-
-static PathString RemoveTrailingSlashes16(PathString str) {
- while ((str.length() > 0) && (str.at(str.length() - 1) == kPathSeparator[0]))
- str.resize(str.length() - 1);
- return str;
-}
-
-static string RemoveTrailingSlashes(string str) {
- while ((str.length() > 0) && (str.at(str.length() - 1) == PATH_SEPARATOR))
- str.resize(str.length() - 1);
- return str;
-}
-
-PathString LastPathSegment(const PathString& path) {
- return RemoveTrailingSlashes16(PathFindFileNameW(path.c_str()));
-}
-
-string LastPathSegment(const string& path) {
- return RemoveTrailingSlashes(PathFindFileNameA(path.c_str()));
-}
-
-PathString GetFullPath(const PathString& path) {
- PathChar buffer[MAX_PATH];
- PathChar* file_part;
- DWORD const size = GetFullPathName(path.c_str(), ARRAYSIZE(buffer), buffer,
- &file_part);
- return PathString(buffer, size);
-}
-
-PathString AppendSlash(const PathString& path) {
- PathString result(path);
- if (!result.empty()) {
- if (*result.rbegin() == '/')
- *result.rbegin() = '\\';
- else if (*result.rbegin() != '\\')
- result.push_back('\\');
- }
- return result;
-}
-
-PathString ExpandTilde(const PathString& path) {
- // Do nothing on windows.
- return path;
-}
-
-// Returns a string with length or fewer elements, careful to not truncate a
-// string mid-surrogate pair.
-PathString TruncatePathString(const PathString& original, int length) {
- if (original.size() <= static_cast<size_t>(length))
- return original;
- if (length <= 0)
- return original;
- PathString ret(original.begin(), original.begin() + length);
- COMPILE_ASSERT(sizeof(PathChar) == sizeof(uint16), PathStringNotUTF16);
- PathChar last_char = *ret.rbegin();
-
- // Values taken from
- // http://en.wikipedia.org/w/index.php?title=UTF-16/UCS-2&oldid=248072840
- if (last_char >= 0xD800 && last_char <= 0xDBFF)
- ret.resize(ret.size() - 1);
- return ret;
-}
-
-namespace {
-const PathString kWindowsIllegalBaseFilenames[] = {
- L"CON", L"PRN", L"AUX", L"NUL", L"COM1", L"COM2",
- L"COM3", L"COM4", L"COM5", L"COM6", L"COM7",
- L"COM8", L"COM9", L"LPT1", L"LPT2", L"LPT3",
- L"LPT4", L"LPT5", L"LPT6", L"LPT7", L"LPT8",
- L"LPT9" };
-}
-
-// See: http://msdn.microsoft.com/library/default.asp?url=/library/
-// en-us/fileio/fs/naming_a_file.asp
-// note that * and ? are not listed on the page as illegal characters,
-// but they are.
-PathString MakePathComponentOSLegal(const PathString& component) {
- CHECK(!component.empty());
- PathString mutable_component = component;
-
- // Remove illegal characters.
- for (PathString::iterator i = mutable_component.begin();
- i != mutable_component.end();) {
- if ((PathString::npos != PathString(L"<>:\"/\\|*?").find(*i)) ||
- ((static_cast<unsigned short>(*i) >= 0) &&
- (static_cast<unsigned short>(*i) <= 31))) {
- mutable_component.erase(i);
- } else {
- ++i;
- }
- }
-
- // Remove trailing spaces or periods.
- while (mutable_component.size() &&
- ((mutable_component.at(mutable_component.size() - 1) == L' ') ||
- (mutable_component.at(mutable_component.size() - 1) == L'.')))
- mutable_component.resize(mutable_component.size() - 1, L' ');
-
- // Remove a bunch of forbidden names. windows only seems to mind if
- // a forbidden name matches our name exactly (e.g. "prn") or if the name is
- // the forbidden name, followed by a dot, followed by anything
- // (e.g., "prn.anything.foo.bar")
-
- // From this point out, we break mutable_component into two strings, and use
- // them this way: we save anything after and including the first dot (usually
- // the extension) and only mess with stuff before the first dot.
- PathString::size_type first_dot = mutable_component.find_first_of(L'.');
- if (PathString::npos == first_dot)
- first_dot = mutable_component.size();
- PathString sub = mutable_component.substr(0, first_dot);
- PathString postsub = mutable_component.substr(first_dot);
- CHECK(sub + postsub == mutable_component);
- for (int i = 0; i < ARRAYSIZE(kWindowsIllegalBaseFilenames); i++) {
- // ComparePathNames(a, b) == 0 -> same
- if (syncable::ComparePathNames(kWindowsIllegalBaseFilenames[i], sub) == 0) {
- sub.append(L"~1");
- break;
- }
- }
- if ((L"" == sub) && (L"" == postsub)) {
- sub = L"~1";
- }
-
- // Return the new name, only if it differs from the original.
- if ((sub + postsub) == component)
- return L"";
- return (sub + postsub);
-}
+const char kPathSeparator[] = "/";
diff --git a/chrome/browser/sync/util/path_helpers.h b/chrome/browser/sync/util/path_helpers.h
index b370fbd..5ebf465 100644
--- a/chrome/browser/sync/util/path_helpers.h
+++ b/chrome/browser/sync/util/path_helpers.h
@@ -9,9 +9,11 @@
#include <iterator>
#include <string>
-#include "chrome/browser/sync/util/compat_file.h"
+#include "base/file_path.h"
#include "chrome/browser/sync/util/sync_types.h"
+extern const char kPathSeparator[];
+
template <typename StringType>
class PathSegmentIterator : public std::iterator<std::forward_iterator_tag,
StringType> {
@@ -66,32 +68,6 @@ class PathSegmentIterator : public std::iterator<std::forward_iterator_tag,
StringType value_;
};
-// NOTE: The functions (Strip)LastPathSegment always return values without a
-// trailing slash.
-PathString LastPathSegment(const PathString& path);
-std::string LastPathSegment(const std::string& path);
-PathString AppendSlash(const PathString& path);
-PathString GetFullPath(const PathString& path);
-PathString ExpandTilde(const PathString& path);
-
-inline bool HasSuffixPathString(const PathString& str,
- const PathString& suffix) {
- return str.find(suffix, str.size() - suffix.size()) != PathString::npos;
-}
-
-inline PathString StripSuffixPathString(const PathString& str,
- const PathString& suffix) {
- PathString ret(str);
- if (HasSuffixPathString(str, suffix)) {
- ret.resize(str.size() - suffix.size());
- }
- return ret;
-}
-
-// Returns a string with length or fewer elements, careful to not truncate a
-// string mid-surrogate pair.
-PathString TruncatePathString(const PathString& original, int length);
-
// Makes a path component legal for your OS, but doesn't handle collisions
// with other files in the same directory. it can do this by removing
// illegal characters and adding ~1 before the first '.' in the filename.
diff --git a/chrome/browser/sync/util/path_helpers_linux.cc b/chrome/browser/sync/util/path_helpers_linux.cc
index 157fa48..c256d5c 100644
--- a/chrome/browser/sync/util/path_helpers_linux.cc
+++ b/chrome/browser/sync/util/path_helpers_linux.cc
@@ -8,9 +8,3 @@
#ifndef OS_LINUX
#error Compile this file on Linux only.
#endif
-
-PathString GetFullPath(const PathString& path) {
- // TODO(sync): Not sure what the base of the relative path should be on
- // linux.
- return path;
-}
diff --git a/chrome/browser/sync/util/path_helpers_mac.cc b/chrome/browser/sync/util/path_helpers_mac.cc
index 3b1c84a..d4f84c8 100644
--- a/chrome/browser/sync/util/path_helpers_mac.cc
+++ b/chrome/browser/sync/util/path_helpers_mac.cc
@@ -8,10 +8,3 @@
#ifndef OS_MACOSX
#error Compile this file on Mac only.
#endif
-
-PathString GetFullPath(const PathString& path) {
- // TODO(sync): Not sure what the base of the relative path should be on
- // OS X.
- return path;
-}
-
diff --git a/chrome/browser/sync/util/path_helpers_posix.cc b/chrome/browser/sync/util/path_helpers_posix.cc
index f613f44..c954271 100644
--- a/chrome/browser/sync/util/path_helpers_posix.cc
+++ b/chrome/browser/sync/util/path_helpers_posix.cc
@@ -2,95 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <sys/types.h>
-
-#include <algorithm>
-#include <pwd.h>
-#include <string.h>
-
-#include "base/logging.h"
-#include "base/port.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
#include "chrome/browser/sync/util/path_helpers.h"
+#include "build/build_config.h"
+
#if ((!defined(OS_LINUX)) && (!defined(OS_MACOSX)))
#error Compile this file on Mac OS X or Linux only.
#endif
-PathString ExpandTilde(const PathString& path) {
- if (path.empty())
- return path;
- if ('~' != path[0])
- return path;
- PathString ret;
- // TODO(sync): Consider using getpwuid_r.
- ret.insert(0, getpwuid(getuid())->pw_dir);
- ret.append(++path.begin(), path.end());
- return ret;
-}
-
-namespace {
-// TODO(sync): We really should use char[].
- std::string cache_dir_;
-}
-
-void set_cache_dir(std::string cache_dir) {
- CHECK(cache_dir_.empty());
- cache_dir_ = cache_dir;
-}
-
-std::string get_cache_dir() {
- CHECK(!cache_dir_.empty());
- return cache_dir_;
-}
-
-// On Posix, PathStrings are UTF-8, not UTF-16 as they are on Windows. Thus,
-// this function is different from the Windows version.
-PathString TruncatePathString(const PathString& original, int length) {
- if (original.size() <= static_cast<size_t>(length))
- return original;
- if (length <= 0)
- return original;
- PathString ret(original.begin(), original.begin() + length);
- COMPILE_ASSERT(sizeof(PathChar) == sizeof(uint8), PathStringNotUTF8);
- PathString::reverse_iterator last_char = ret.rbegin();
-
- // Values taken from
- // http://en.wikipedia.org/w/index.php?title=UTF-8&oldid=252875566
- if (0 == (*last_char & 0x80))
- return ret;
-
- for (; last_char != ret.rend(); ++last_char) {
- if (0 == (*last_char & 0x80)) {
- // Got malformed UTF-8; bail.
- return ret;
- }
- if (0 == (*last_char & 0x40)) {
- // Got another trailing byte.
- continue;
- }
- break;
- }
-
- if (ret.rend() == last_char) {
- // We hit the beginning of the string. bail.
- return ret;
- }
-
- int last_codepoint_len = last_char - ret.rbegin() + 1;
-
- if (((0xC0 == (*last_char & 0xE0)) && (2 == last_codepoint_len)) ||
- ((0xE0 == (*last_char & 0xF0)) && (3 == last_codepoint_len)) ||
- ((0xF0 == (*last_char & 0xF8)) && (4 == last_codepoint_len))) {
- // Valid utf-8.
- return ret;
- }
-
- // Invalid utf-8. chop off last "codepoint" and return.
- ret.resize(ret.size() - last_codepoint_len);
- return ret;
-}
-
// Convert /s to :s.
PathString MakePathComponentOSLegal(const PathString& component) {
if (PathString::npos == component.find("/"))
@@ -99,25 +18,3 @@ PathString MakePathComponentOSLegal(const PathString& component) {
std::replace(new_name.begin(), new_name.end(), '/', ':');
return new_name;
}
-
-string LastPathSegment(const string& path) {
- string str(path);
- string::size_type final_slash = str.find_last_of('/');
- if (string::npos != final_slash && final_slash == str.length() - 1
- && str.length() > 1) {
- str.erase(final_slash);
- final_slash = str.find_last_of('/');
- }
- if (string::npos == final_slash)
- return str;
- str.erase(0, final_slash + 1);
- return str;
-}
-
-PathString AppendSlash(const PathString& path) {
- if ((!path.empty()) && (*path.rbegin() != '/')) {
- return path + '/';
- }
- return path;
-}
-
diff --git a/chrome/browser/sync/util/path_helpers_unittest.cc b/chrome/browser/sync/util/path_helpers_unittest.cc
index 62359e1..e38a5a0 100644
--- a/chrome/browser/sync/util/path_helpers_unittest.cc
+++ b/chrome/browser/sync/util/path_helpers_unittest.cc
@@ -15,117 +15,66 @@ namespace syncable {
class PathHelpersTest : public testing::Test {
};
-TEST(PathHelpersTest, TruncatePathStringTest) {
- // Simple case.
- PathString str = PSTR("12345");
- EXPECT_EQ(PSTR("123"), TruncatePathString(str, 3));
- EXPECT_EQ(str, TruncatePathString(str, str.size()));
-
- // abcg is "abc" + musical g clef U+1D11E
-#if PATHSTRING_IS_STD_STRING
- // UTF-8
- PathChar abcg[] = {'a', 'b', 'c', 0xF0, 0x9D, 0x84, 0x9E, '\0'};
-#else // PATHSTRING_IS_STD_STRING
- // UTF-16
- PathChar abcg[] = {'a', 'b', 'c', 0xD834, 0xDD1E, '\0'};
-#endif // PATHSTRING_IS_STD_STRING
-
- EXPECT_EQ(PSTR("abc"), TruncatePathString(abcg, 4));
-
- // Further utf-8 tests.
-#if PATHSTRING_IS_STD_STRING
- // UTF-8
-
- EXPECT_EQ(PSTR("abc"), TruncatePathString(abcg, 4));
- EXPECT_EQ(PSTR("abc"), TruncatePathString(abcg, 5));
- EXPECT_EQ(PSTR("abc"), TruncatePathString(abcg, 6));
- EXPECT_EQ(PathString(abcg), TruncatePathString(abcg, 7));
-
- PathChar abc2[] = {'a', 'b', 'c', 0xC3, 0xB1, '\0'}; // abc(n w/ tilde)
- EXPECT_EQ(PSTR("abc"), TruncatePathString(abc2, 3));
- EXPECT_EQ(PSTR("abc"), TruncatePathString(abc2, 4));
- EXPECT_EQ(PathString(abc2), TruncatePathString(abc2, 5));
-
- PathChar abc3[] = {'a', 'b', 'c', 0xE2, 0x82, 0xAC, '\0'}; // abc(euro)
- EXPECT_EQ(PSTR("abc"), TruncatePathString(abc3, 3));
- EXPECT_EQ(PSTR("abc"), TruncatePathString(abc3, 4));
- EXPECT_EQ(PSTR("abc"), TruncatePathString(abc3, 5));
- EXPECT_EQ(PathString(abc3), TruncatePathString(abc3, 6));
-#endif
-}
-
-TEST(PathHelpersTest, PathStrutil) {
- PathString big = PSTR("abcdef");
- PathString suffix = PSTR("def");
- PathString other = PSTR("x");
- EXPECT_TRUE(HasSuffixPathString(big, suffix));
- EXPECT_FALSE(HasSuffixPathString(suffix, big));
- EXPECT_FALSE(HasSuffixPathString(big, other));
- EXPECT_EQ(PSTR("abc"), StripSuffixPathString(big, suffix));
-}
-
TEST(PathHelpersTest, SanitizePathComponent) {
#if defined(OS_WIN)
- EXPECT_EQ(MakePathComponentOSLegal(L"bar"), L"");
- EXPECT_EQ(MakePathComponentOSLegal(L"bar <"), L"bar");
- EXPECT_EQ(MakePathComponentOSLegal(L"bar.<"), L"bar");
- EXPECT_EQ(MakePathComponentOSLegal(L"prn"), L"prn~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"pr>n"), L"prn~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"ab:c"), L"abc");
- EXPECT_EQ(MakePathComponentOSLegal(L"a|bc"), L"abc");
- EXPECT_EQ(MakePathComponentOSLegal(L"baz~9"), L"");
- EXPECT_EQ(MakePathComponentOSLegal(L"\007"), L"~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"com1.txt.bat"), L"com1~1.txt.bat");
- EXPECT_EQ(MakePathComponentOSLegal(L"foo.com1.bat"), L"");
- EXPECT_EQ(MakePathComponentOSLegal(L"\010gg"), L"gg");
- EXPECT_EQ(MakePathComponentOSLegal(L"<"), L"~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"col:on"), L"colon");
- EXPECT_EQ(MakePathComponentOSLegal(L"q\""), L"q");
- EXPECT_EQ(MakePathComponentOSLegal(L"back\\slAsh"), L"backslAsh");
- EXPECT_EQ(MakePathComponentOSLegal(L"sla/sh "), L"slash");
- EXPECT_EQ(MakePathComponentOSLegal(L"s|laSh"), L"slaSh");
- EXPECT_EQ(MakePathComponentOSLegal(L"CON"), L"CON~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"PRN"), L"PRN~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"AUX"), L"AUX~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"NUL"), L"NUL~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"COM1"), L"COM1~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"COM2"), L"COM2~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"COM3"), L"COM3~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"COM4"), L"COM4~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"COM5"), L"COM5~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"COM6"), L"COM6~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"COM7"), L"COM7~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"COM8"), L"COM8~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"COM9"), L"COM9~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"LPT1"), L"LPT1~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"LPT2"), L"LPT2~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"LPT3"), L"LPT3~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"LPT4"), L"LPT4~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"LPT5"), L"LPT5~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"LPT6"), L"LPT6~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"LPT7"), L"LPT7~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"LPT8"), L"LPT8~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"LPT9"), L"LPT9~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"bar~bar"), L"");
- EXPECT_EQ(MakePathComponentOSLegal(L"adlr~-3"), L"");
- EXPECT_EQ(MakePathComponentOSLegal(L"tilde~"), L"");
- EXPECT_EQ(MakePathComponentOSLegal(L"mytext.txt"), L"");
- EXPECT_EQ(MakePathComponentOSLegal(L"mytext|.txt"), L"mytext.txt");
- EXPECT_EQ(MakePathComponentOSLegal(L"okay.com1.txt"), L"");
- EXPECT_EQ(MakePathComponentOSLegal(L"software-3.tar.gz"), L"");
- EXPECT_EQ(MakePathComponentOSLegal(L"<"), L"~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"<.<"), L"~1");
- EXPECT_EQ(MakePathComponentOSLegal(L"<.<txt"), L".txt");
- EXPECT_EQ(MakePathComponentOSLegal(L"txt<.<"), L"txt");
+ EXPECT_EQ(MakePathComponentOSLegal("bar"), "");
+ EXPECT_EQ(MakePathComponentOSLegal("bar <"), "bar");
+ EXPECT_EQ(MakePathComponentOSLegal("bar.<"), "bar");
+ EXPECT_EQ(MakePathComponentOSLegal("prn"), "prn~1");
+ EXPECT_EQ(MakePathComponentOSLegal("pr>n"), "prn~1");
+ EXPECT_EQ(MakePathComponentOSLegal("ab:c"), "abc");
+ EXPECT_EQ(MakePathComponentOSLegal("a|bc"), "abc");
+ EXPECT_EQ(MakePathComponentOSLegal("baz~9"), "");
+ EXPECT_EQ(MakePathComponentOSLegal("\007"), "~1");
+ EXPECT_EQ(MakePathComponentOSLegal("com1.txt.bat"), "com1~1.txt.bat");
+ EXPECT_EQ(MakePathComponentOSLegal("foo.com1.bat"), "");
+ EXPECT_EQ(MakePathComponentOSLegal("\010gg"), "gg");
+ EXPECT_EQ(MakePathComponentOSLegal("<"), "~1");
+ EXPECT_EQ(MakePathComponentOSLegal("col:on"), "colon");
+ EXPECT_EQ(MakePathComponentOSLegal("q\""), "q");
+ EXPECT_EQ(MakePathComponentOSLegal("back\\slAsh"), "backslAsh");
+ EXPECT_EQ(MakePathComponentOSLegal("sla/sh "), "slash");
+ EXPECT_EQ(MakePathComponentOSLegal("s|laSh"), "slaSh");
+ EXPECT_EQ(MakePathComponentOSLegal("CON"), "CON~1");
+ EXPECT_EQ(MakePathComponentOSLegal("PRN"), "PRN~1");
+ EXPECT_EQ(MakePathComponentOSLegal("AUX"), "AUX~1");
+ EXPECT_EQ(MakePathComponentOSLegal("NUL"), "NUL~1");
+ EXPECT_EQ(MakePathComponentOSLegal("COM1"), "COM1~1");
+ EXPECT_EQ(MakePathComponentOSLegal("COM2"), "COM2~1");
+ EXPECT_EQ(MakePathComponentOSLegal("COM3"), "COM3~1");
+ EXPECT_EQ(MakePathComponentOSLegal("COM4"), "COM4~1");
+ EXPECT_EQ(MakePathComponentOSLegal("COM5"), "COM5~1");
+ EXPECT_EQ(MakePathComponentOSLegal("COM6"), "COM6~1");
+ EXPECT_EQ(MakePathComponentOSLegal("COM7"), "COM7~1");
+ EXPECT_EQ(MakePathComponentOSLegal("COM8"), "COM8~1");
+ EXPECT_EQ(MakePathComponentOSLegal("COM9"), "COM9~1");
+ EXPECT_EQ(MakePathComponentOSLegal("LPT1"), "LPT1~1");
+ EXPECT_EQ(MakePathComponentOSLegal("LPT2"), "LPT2~1");
+ EXPECT_EQ(MakePathComponentOSLegal("LPT3"), "LPT3~1");
+ EXPECT_EQ(MakePathComponentOSLegal("LPT4"), "LPT4~1");
+ EXPECT_EQ(MakePathComponentOSLegal("LPT5"), "LPT5~1");
+ EXPECT_EQ(MakePathComponentOSLegal("LPT6"), "LPT6~1");
+ EXPECT_EQ(MakePathComponentOSLegal("LPT7"), "LPT7~1");
+ EXPECT_EQ(MakePathComponentOSLegal("LPT8"), "LPT8~1");
+ EXPECT_EQ(MakePathComponentOSLegal("LPT9"), "LPT9~1");
+ EXPECT_EQ(MakePathComponentOSLegal("bar~bar"), "");
+ EXPECT_EQ(MakePathComponentOSLegal("adlr~-3"), "");
+ EXPECT_EQ(MakePathComponentOSLegal("tilde~"), "");
+ EXPECT_EQ(MakePathComponentOSLegal("mytext.txt"), "");
+ EXPECT_EQ(MakePathComponentOSLegal("mytext|.txt"), "mytext.txt");
+ EXPECT_EQ(MakePathComponentOSLegal("okay.com1.txt"), "");
+ EXPECT_EQ(MakePathComponentOSLegal("software-3.tar.gz"), "");
+ EXPECT_EQ(MakePathComponentOSLegal("<"), "~1");
+ EXPECT_EQ(MakePathComponentOSLegal("<.<"), "~1");
+ EXPECT_EQ(MakePathComponentOSLegal("<.<txt"), ".txt");
+ EXPECT_EQ(MakePathComponentOSLegal("txt<.<"), "txt");
#else // !defined(OS_WIN)
-
EXPECT_EQ(MakePathComponentOSLegal("bar"), "");
EXPECT_EQ(MakePathComponentOSLegal("b"), "");
EXPECT_EQ(MakePathComponentOSLegal("A"), "");
EXPECT_EQ(MakePathComponentOSLegal("<'|"), "");
EXPECT_EQ(MakePathComponentOSLegal("/"), ":");
EXPECT_EQ(MakePathComponentOSLegal(":"), "");
-
#endif // defined(OS_WIN)
}
diff --git a/chrome/browser/sync/util/path_helpers_win.cc b/chrome/browser/sync/util/path_helpers_win.cc
new file mode 100644
index 0000000..8fe60df
--- /dev/null
+++ b/chrome/browser/sync/util/path_helpers_win.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 2009 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 "chrome/browser/sync/util/path_helpers.h"
+
+#include <Shlwapi.h>
+#include <stdlib.h>
+
+#include "base/logging.h"
+#include "base/port.h"
+#include "build/build_config.h"
+#include "chrome/browser/sync/syncable/syncable.h"
+
+#ifndef OS_WIN
+#error Compile this file on Windows only.
+#endif
+
+using std::string;
+
+namespace {
+const PathString kWindowsIllegalBaseFilenames[] = {
+ "CON", "PRN", "AUX", "NUL", "COM1", "COM2",
+ "COM3", "COM4", "COM5", "COM6", "COM7",
+ "COM8", "COM9", "LPT1", "LPT2", "LPT3",
+ "LPT4", "LPT5", "LPT6", "LPT7", "LPT8",
+ "LPT9" };
+}
+
+// See: http://msdn.microsoft.com/library/default.asp?url=/library/
+// en-us/fileio/fs/naming_a_file.asp
+// note that * and ? are not listed on the page as illegal characters,
+// but they are.
+PathString MakePathComponentOSLegal(const PathString& component) {
+ CHECK(!component.empty());
+ PathString mutable_component = component;
+
+ // Remove illegal characters.
+ for (PathString::iterator i = mutable_component.begin();
+ i != mutable_component.end();) {
+ if ((PathString::npos != PathString("<>:\"/\\|*?").find(*i)) ||
+ ((static_cast<unsigned short>(*i) >= 0) &&
+ (static_cast<unsigned short>(*i) <= 31))) {
+ mutable_component.erase(i);
+ } else {
+ ++i;
+ }
+ }
+
+ // Remove trailing spaces or periods.
+ while (mutable_component.size() &&
+ ((mutable_component.at(mutable_component.size() - 1) == ' ') ||
+ (mutable_component.at(mutable_component.size() - 1) == '.')))
+ mutable_component.resize(mutable_component.size() - 1, ' ');
+
+ // Remove a bunch of forbidden names. windows only seems to mind if
+ // a forbidden name matches our name exactly (e.g. "prn") or if the name is
+ // the forbidden name, followed by a dot, followed by anything
+ // (e.g., "prn.anything.foo.bar")
+
+ // From this point out, we break mutable_component into two strings, and use
+ // them this way: we save anything after and including the first dot (usually
+ // the extension) and only mess with stuff before the first dot.
+ PathString::size_type first_dot = mutable_component.find_first_of('.');
+ if (PathString::npos == first_dot)
+ first_dot = mutable_component.size();
+ PathString sub = mutable_component.substr(0, first_dot);
+ PathString postsub = mutable_component.substr(first_dot);
+ CHECK(sub + postsub == mutable_component);
+ for (int i = 0; i < ARRAYSIZE(kWindowsIllegalBaseFilenames); i++) {
+ // ComparePathNames(a, b) == 0 -> same
+ if (syncable::ComparePathNames(kWindowsIllegalBaseFilenames[i], sub) == 0) {
+ sub.append("~1");
+ break;
+ }
+ }
+ if (("" == sub) && ("" == postsub)) {
+ sub = "~1";
+ }
+
+ // Return the new name, only if it differs from the original.
+ if ((sub + postsub) == component)
+ return "";
+ return (sub + postsub);
+}
diff --git a/chrome/browser/sync/util/query_helpers.cc b/chrome/browser/sync/util/query_helpers.cc
index c27a877..46e8ee0 100644
--- a/chrome/browser/sync/util/query_helpers.cc
+++ b/chrome/browser/sync/util/query_helpers.cc
@@ -13,6 +13,7 @@
#include <vector>
#include "chrome/browser/sync/util/sync_types.h"
+#include "chrome/common/sqlite_utils.h"
using std::numeric_limits;
using std::string;
@@ -55,26 +56,21 @@ int Exec(sqlite3* dbhandle, const char* query, sqlite3_stmt* statement) {
return SQLITE_OK == finalize_result ? result : finalize_result;
}
-int SqliteOpen(PathString filename, sqlite3** db) {
- int result =
-#if PATHSTRING_IS_STD_STRING
- sqlite3_open
-#else
- sqlite3_open16
-#endif
- (filename.c_str(), db);
- LOG_IF(ERROR, SQLITE_OK != result) << "Error opening " << filename << ": "
+int SqliteOpen(const FilePath& filename, sqlite3** db) {
+ int result = OpenSqliteDb(filename, db);
+ LOG_IF(ERROR, SQLITE_OK != result) << "Error opening "
+ << filename.value() << ": "
<< result;
#if defined(OS_WIN)
if (SQLITE_OK == result) {
// Make sure we mark the db file as not indexed so since if any other app
// opens it, it can break our db locking.
- DWORD attrs = GetFileAttributes(filename.c_str());
+ DWORD attrs = GetFileAttributesW(filename.value().c_str());
if (FILE_ATTRIBUTE_NORMAL == attrs)
attrs = FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
else
attrs = attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
- SetFileAttributes(filename.c_str(), attrs);
+ SetFileAttributesW(filename.value().c_str(), attrs);
}
#endif // defined(OS_WIN)
// Be patient as we set pragmas.
@@ -87,27 +83,6 @@ int SqliteOpen(PathString filename, sqlite3** db) {
return SQLITE_OK;
}
-#if !PATHSTRING_IS_STD_STRING
-sqlite3_stmt* BindArg(sqlite3_stmt* statement, const PathString& s, int index) {
- if (NULL == statement)
- return statement;
- CHECK(SQLITE_OK == sqlite3_bind_text16(statement, index, s.data(),
- CountBytes(s), SQLITE_TRANSIENT));
- return statement;
-}
-
-sqlite3_stmt* BindArg(sqlite3_stmt* statement, const PathChar* s, int index) {
- if (NULL == statement)
- return statement;
- CHECK(SQLITE_OK == sqlite3_bind_text16(statement,
- index,
- s,
- -1, // -1 means s is zero-terminated
- SQLITE_TRANSIENT));
- return statement;
-}
-#endif // !PATHSTRING_IS_STD_STRING
-
sqlite3_stmt* BindArg(sqlite3_stmt* statement, const string& s, int index) {
if (NULL == statement)
return statement;
@@ -179,17 +154,15 @@ sqlite3_stmt* BindArg(sqlite3_stmt* statement, SqliteNullType, int index) {
return statement;
}
-#if !PATHSTRING_IS_STD_STRING
-void GetColumn(sqlite3_stmt* statement, int index, PathString* value) {
+void GetColumn(sqlite3_stmt* statement, int index, string16* value) {
if (sqlite3_column_type(statement, index) == SQLITE_NULL) {
value->clear();
} else {
value->assign(
- static_cast<const PathChar*>(sqlite3_column_text16(statement, index)),
- sqlite3_column_bytes16(statement, index) / sizeof(PathChar));
+ static_cast<const char16*>(sqlite3_column_text16(statement, index)),
+ sqlite3_column_bytes16(statement, index) / sizeof(char16));
}
}
-#endif // !PATHSTRING_IS_STD_STRING
void GetColumn(sqlite3_stmt* statement, int index, string* value) {
if (sqlite3_column_type(statement, index) == SQLITE_NULL) {
diff --git a/chrome/browser/sync/util/query_helpers.h b/chrome/browser/sync/util/query_helpers.h
index 54cda1f..66b1d81 100644
--- a/chrome/browser/sync/util/query_helpers.h
+++ b/chrome/browser/sync/util/query_helpers.h
@@ -12,7 +12,9 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/file_path.h"
#include "base/logging.h"
+#include "base/string16.h"
#include "build/build_config.h"
#include "chrome/browser/sync/util/sync_types.h"
#include "third_party/sqlite/preprocessed/sqlite3.h"
@@ -21,13 +23,9 @@ enum SqliteNullType {
SQLITE_NULL_VALUE
};
-int SqliteOpen(PathString filename, sqlite3** ppDb);
+int SqliteOpen(const FilePath& filename, sqlite3** ppDb);
sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query);
-#if !PATHSTRING_IS_STD_STRING
-sqlite3_stmt* BindArg(sqlite3_stmt*, const PathString&, int index);
-sqlite3_stmt* BindArg(sqlite3_stmt*, const PathChar*, int index);
-#endif
sqlite3_stmt* BindArg(sqlite3_stmt*, const std::string&, int index);
sqlite3_stmt* BindArg(sqlite3_stmt*, const char*, int index);
sqlite3_stmt* BindArg(sqlite3_stmt*, int32, int index);
@@ -37,9 +35,7 @@ sqlite3_stmt* BindArg(sqlite3_stmt*, bool, int index);
sqlite3_stmt* BindArg(sqlite3_stmt*, const std::vector<uint8>&, int index);
sqlite3_stmt* BindArg(sqlite3_stmt*, SqliteNullType, int index);
-#if !PATHSTRING_IS_STD_STRING
-void GetColumn(sqlite3_stmt*, int index, PathString* value);
-#endif
+void GetColumn(sqlite3_stmt*, int index, string16* value);
void GetColumn(sqlite3_stmt*, int index, std::string* value);
void GetColumn(sqlite3_stmt*, int index, int32* value);
void GetColumn(sqlite3_stmt*, int index, int64* value);
diff --git a/chrome/browser/sync/util/query_helpers_unittest.cc b/chrome/browser/sync/util/query_helpers_unittest.cc
index 0fb86e2..43c0488 100644
--- a/chrome/browser/sync/util/query_helpers_unittest.cc
+++ b/chrome/browser/sync/util/query_helpers_unittest.cc
@@ -7,7 +7,9 @@
#include <limits>
#include <string>
-#include "chrome/browser/sync/util/compat_file.h"
+#include "base/file_util.h"
+#include "chrome/common/sqlite_utils.h"
+#include "chrome/test/file_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
using std::numeric_limits;
@@ -25,12 +27,19 @@ TEST(QueryHelpers, APEncode) {
}
TEST(QueryHelpers, TestExecFailure) {
- sqlite3* database;
- const PathString test_database(PSTR("queryhelper_test.sqlite3"));
- PathRemove(test_database);
- ASSERT_EQ(SQLITE_OK, SqliteOpen(test_database, &database));
- EXPECT_EQ(SQLITE_DONE, Exec(database, "CREATE TABLE test_table (idx int)"));
- EXPECT_NE(SQLITE_DONE, Exec(database, "ALTER TABLE test_table ADD COLUMN "
- "broken int32 default ?", -1));
- PathRemove(test_database);
+ FilePath test_database;
+ file_util::GetCurrentDirectory(&test_database);
+ test_database = test_database.Append(
+ FILE_PATH_LITERAL("queryhelper_test.sqlite3"));
+ // Cleanup left-over file, if present.
+ file_util::Delete(test_database, true);
+ FileAutoDeleter file_deleter(test_database);
+ {
+ sqlite3* database = NULL;
+ ASSERT_EQ(SQLITE_OK, SqliteOpen(test_database, &database));
+ sqlite_utils::scoped_sqlite_db_ptr database_deleter(database);
+ EXPECT_EQ(SQLITE_DONE, Exec(database, "CREATE TABLE test_table (idx int)"));
+ EXPECT_NE(SQLITE_DONE, Exec(database, "ALTER TABLE test_table ADD COLUMN "
+ "broken int32 default ?", -1));
+ }
}
diff --git a/chrome/browser/sync/util/sync_types.h b/chrome/browser/sync/util/sync_types.h
index 71b9c42..429033b 100644
--- a/chrome/browser/sync/util/sync_types.h
+++ b/chrome/browser/sync/util/sync_types.h
@@ -12,34 +12,11 @@
#include "base/string_util.h"
#include "build/build_config.h"
-// TODO(timsteele): Use base/file_path.h instead of PathString.
-#if defined(OS_WIN)
-#define PATHSTRING_IS_STD_STRING 0
-typedef std::wstring PathString;
-
-// This ugly double define hack is needed to allow the following pattern on
-// Windows:
-//
-// #define FOO "Foo"
-// #define FOO_PATH_STRING PSTR("Foo")
-//
-// TODO(sync): find out if we can avoid this.
-#define PSTR_UGLY_DOUBLE_DEFINE_HACK(s) L##s
-#define PSTR(s) PSTR_UGLY_DOUBLE_DEFINE_HACK(s)
-#define PSTR_CHAR wchar_t
-
-inline size_t PathLen(const wchar_t* s) {
- return wcslen(s);
-}
-
-#else // Mac and Linux
-#define PATHSTRING_IS_STD_STRING 1
+#define PSTR(s) s
#define PSTR_CHAR char
typedef std::string PathString;
-#define PSTR(s) s
-inline size_t PathLen(const char* s) {
- return strlen(s);
-}
+
+#if !defined(OS_WIN)
// Mac OS X typedef's BOOL to signed char, so we do that on Linux too.
typedef signed char BOOL;
typedef int32 LONG;
diff --git a/chrome/browser/sync/util/user_settings.cc b/chrome/browser/sync/util/user_settings.cc
index 1c867a6..bb60af2 100644
--- a/chrome/browser/sync/util/user_settings.cc
+++ b/chrome/browser/sync/util/user_settings.cc
@@ -84,12 +84,12 @@ void UserSettings::MigrateOldVersionsAsNeeded(sqlite3* const handle,
"SELECT share_name, file_name FROM shares"));
int query_result = sqlite3_step(share_query.get());
CHECK(SQLITE_ROW == query_result);
- PathString share_name, file_name;
+ FilePath::StringType share_name, file_name;
GetColumn(share_query.get(), 0, &share_name);
GetColumn(share_query.get(), 1, &file_name);
if (!file_util::Move(FilePath(file_name),
- FilePath(DirectoryManager::GetSyncDataDatabaseFilename()))) {
+ DirectoryManager::GetSyncDataDatabaseFilename())) {
LOG(WARNING) << "Unable to upgrade UserSettings from v10";
return;
}
@@ -128,12 +128,12 @@ static void MakeClientIDTable(sqlite3* const dbhandle) {
Generate128BitRandomHexString());
}
-bool UserSettings::Init(const PathString& settings_path) {
- { // Scope the handle
+bool UserSettings::Init(const FilePath& settings_path) {
+ { // Scope the handle.
ScopedDBHandle dbhandle(this);
if (dbhandle_)
sqlite3_close(dbhandle_);
- CHECK(SQLITE_OK == SqliteOpen(settings_path.c_str(), &dbhandle_));
+ CHECK(SQLITE_OK == SqliteOpen(settings_path, &dbhandle_));
// In the worst case scenario, the user may hibernate his computer during
// one of our transactions.
sqlite3_busy_timeout(dbhandle_, numeric_limits<int>::max());
@@ -183,9 +183,9 @@ bool UserSettings::Init(const PathString& settings_path) {
#if defined(OS_WIN)
// Do not index this file. Scanning can occur every time we close the file,
// which causes long delays in SQLite's file locking.
- const DWORD attrs = GetFileAttributes(settings_path.c_str());
+ const DWORD attrs = GetFileAttributes(settings_path.value().c_str());
const BOOL attrs_set =
- SetFileAttributes(settings_path.c_str(),
+ SetFileAttributes(settings_path.value().c_str(),
attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
#endif
return true;
diff --git a/chrome/browser/sync/util/user_settings.h b/chrome/browser/sync/util/user_settings.h
index 60ad1a9..8f7197d 100644
--- a/chrome/browser/sync/util/user_settings.h
+++ b/chrome/browser/sync/util/user_settings.h
@@ -9,6 +9,7 @@
#include <set>
#include <string>
+#include "base/file_path.h"
#include "base/lock.h"
#include "build/build_config.h"
#include "chrome/browser/sync/util/signin.h"
@@ -27,7 +28,7 @@ class UserSettings {
UserSettings();
~UserSettings();
// Returns false (failure) if the db is a newer version.
- bool Init(const PathString& settings_path);
+ bool Init(const FilePath& settings_path);
void StoreHashedPassword(const std::string& email,
const std::string& password);
bool VerifyAgainstStoredHash(const std::string& email,
@@ -59,8 +60,6 @@ class UserSettings {
void RemoveAllGuestSettings();
- void RemoveShare(const PathString& share_path);
-
void StoreEmailForSignin(const std::string& signin,
const std::string& primary_email);
diff --git a/chrome/browser/sync/util/user_settings_unittest.cc b/chrome/browser/sync/util/user_settings_unittest.cc
index 02f3fd8..ec7676b 100644
--- a/chrome/browser/sync/util/user_settings_unittest.cc
+++ b/chrome/browser/sync/util/user_settings_unittest.cc
@@ -12,10 +12,15 @@
#include "chrome/browser/sync/util/query_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
+using browser_sync::FilePathToUTF8;
using browser_sync::UserSettings;
-static const PathChar* kV10UserSettingsDB = PSTR("Version10Settings.sqlite3");
-static const PathChar* kOldStyleSyncDataDB = PSTR("OldStyleSyncData.sqlite3");
+static const FilePath::CharType kV10UserSettingsDB[] =
+ FILE_PATH_LITERAL("Version10Settings.sqlite3");
+static const FilePath::CharType kOldStyleSyncDataDB[] =
+ FILE_PATH_LITERAL("OldStyleSyncData.sqlite3");
+static const FilePath::CharType kSyncDataDB[] =
+ FILE_PATH_LITERAL("SyncData.sqlite3");
class UserSettingsTest : public testing::Test {
public:
@@ -23,7 +28,7 @@ class UserSettingsTest : public testing::Test {
void SetUpVersion10Databases() {
CleanUpVersion10Databases();
sqlite3* primer_handle = NULL;
- ASSERT_TRUE(SQLITE_OK == SqliteOpen(kV10UserSettingsDB,
+ ASSERT_TRUE(SQLITE_OK == SqliteOpen(FilePath(kV10UserSettingsDB),
&primer_handle));
FilePath old_sync_data(kOldStyleSyncDataDB);
@@ -45,16 +50,14 @@ class UserSettingsTest : public testing::Test {
" PRIMARY KEY(email, share_name) ON CONFLICT REPLACE)");
// Populate a share.
ExecOrDie(primer_handle, "INSERT INTO shares values ( ?, ?, ?)",
- "foo@foo.com", "foo@foo.com",
- browser_sync::PathStringToUTF8Quick(kOldStyleSyncDataDB));
+ "foo@foo.com", "foo@foo.com", FilePathToUTF8(old_sync_data));
sqlite3_close(primer_handle);
}
void CleanUpVersion10Databases() {
ASSERT_TRUE(file_util::DieFileDie(FilePath(kV10UserSettingsDB), false));
ASSERT_TRUE(file_util::DieFileDie(FilePath(kOldStyleSyncDataDB), false));
- ASSERT_TRUE(file_util::DieFileDie(FilePath(PSTR("SyncData.sqlite3")),
- false));
+ ASSERT_TRUE(file_util::DieFileDie(FilePath(kSyncDataDB), false));
}
const std::string& sync_data() const { return sync_data_; }
@@ -70,21 +73,22 @@ TEST_F(UserSettingsTest, MigrateFromV10ToV11) {
// inside a scoped block so it closes itself and we can poke around to see
// what happened later.
UserSettings settings;
- settings.Init(kV10UserSettingsDB);
+ settings.Init(FilePath(kV10UserSettingsDB));
}
// Now poke around using sqlite to see if UserSettings migrated properly.
sqlite3* handle = NULL;
- ASSERT_TRUE(SQLITE_OK == SqliteOpen(kV10UserSettingsDB, &handle));
+ ASSERT_TRUE(SQLITE_OK == SqliteOpen(FilePath(kV10UserSettingsDB), &handle));
ScopedStatement version_query(PrepareQuery(handle,
"SELECT version FROM db_version"));
ASSERT_TRUE(SQLITE_ROW == sqlite3_step(version_query.get()));
const int version = sqlite3_column_int(version_query.get(), 0);
- EXPECT_TRUE(11 == version);
+ EXPECT_EQ(11, version);
EXPECT_FALSE(file_util::PathExists(FilePath(kOldStyleSyncDataDB)));
- PathString path(syncable::DirectoryManager::GetSyncDataDatabaseFilename());
+ const FilePath& path =
+ syncable::DirectoryManager::GetSyncDataDatabaseFilename();
std::string contents;
ASSERT_TRUE(file_util::ReadFileToString(FilePath(path), &contents));
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 436d5dd..02c8668 100755
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -5304,6 +5304,7 @@
'browser/sync/util/path_helpers_unittest.cc',
'browser/sync/util/query_helpers_unittest.cc',
'browser/sync/util/user_settings_unittest.cc',
+ 'test/file_test_utils.cc',
'test/sync/engine/mock_gaia_authenticator.cc',
'test/sync/engine/mock_gaia_authenticator.h',
'test/sync/engine/mock_gaia_authenticator_unittest.cc',
@@ -5459,9 +5460,6 @@
'browser/sync/util/character_set_converters_posix.cc',
'browser/sync/util/character_set_converters_win.cc',
'browser/sync/util/closure.h',
- 'browser/sync/util/compat_file.h',
- 'browser/sync/util/compat_file_posix.cc',
- 'browser/sync/util/compat_file_win.cc',
'browser/sync/util/crypto_helpers.cc',
'browser/sync/util/crypto_helpers.h',
'browser/sync/util/dbgq.h',
@@ -5477,10 +5475,12 @@
'browser/sync/util/highres_timer_mac.h',
'browser/sync/util/highres_timer_win.cc',
'browser/sync/util/highres_timer_win.h',
+ 'browser/sync/util/path_helpers.cc',
'browser/sync/util/path_helpers.h',
'browser/sync/util/path_helpers_linux.cc',
'browser/sync/util/path_helpers_mac.cc',
'browser/sync/util/path_helpers_posix.cc',
+ 'browser/sync/util/path_helpers_win.cc',
'browser/sync/util/query_helpers.cc',
'browser/sync/util/query_helpers.h',
'browser/sync/util/row_iterator.h',
@@ -5510,7 +5510,6 @@
'sources' : [
'browser/sync/util/data_encryption.cc',
'browser/sync/util/data_encryption.h',
- 'browser/sync/util/path_helpers.cc',
],
}],
['OS=="linux"', {
diff --git a/chrome/test/sync/engine/mock_server_connection.cc b/chrome/test/sync/engine/mock_server_connection.cc
index e4fd70a..c9e3be5 100644
--- a/chrome/test/sync/engine/mock_server_connection.cc
+++ b/chrome/test/sync/engine/mock_server_connection.cc
@@ -381,8 +381,7 @@ void MockConnectionManager::AddUpdateExtendedAttributes(SyncEntity* ent,
for (int i = 0; i < xattr_count; i++) {
sync_pb::ExtendedAttributes_ExtendedAttribute* extended_attribute =
mutable_extended_attributes->add_extendedattribute();
- extended_attribute->set_key(static_cast<const string&>
- (browser_sync::ToUTF8(xattr_key[i])));
+ extended_attribute->set_key(xattr_key[i]);
SyncerProtoUtil::CopyBlobIntoProtoBytes(xattr_value[i],
extended_attribute->mutable_value());
}
diff --git a/chrome/test/sync/engine/test_directory_setter_upper.cc b/chrome/test/sync/engine/test_directory_setter_upper.cc
index 9e910f0..a41f160 100644
--- a/chrome/test/sync/engine/test_directory_setter_upper.cc
+++ b/chrome/test/sync/engine/test_directory_setter_upper.cc
@@ -4,11 +4,10 @@
#include "chrome/test/sync/engine/test_directory_setter_upper.h"
+#include "base/file_util.h"
#include "base/string_util.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/sync/util/character_set_converters.h"
-#include "chrome/browser/sync/util/compat_file.h"
#include "chrome/browser/sync/util/event_sys-inl.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -25,10 +24,10 @@ TestDirectorySetterUpper::TestDirectorySetterUpper(const PathString& name)
TestDirectorySetterUpper::~TestDirectorySetterUpper() {}
void TestDirectorySetterUpper::Init() {
- PathString test_data_dir_ = PSTR(".");
+ FilePath test_data_dir_(FILE_PATH_LITERAL("."));
manager_.reset(new DirectoryManager(test_data_dir_));
file_path_ = manager_->GetSyncDataDatabasePath();
- PathRemove(file_path_.c_str());
+ file_util::Delete(file_path_, false);
}
void TestDirectorySetterUpper::SetUp() {
@@ -54,8 +53,8 @@ void TestDirectorySetterUpper::TearDown() {
manager()->FinalSaveChangesForAll();
manager()->Close(name());
manager_.reset();
- EXPECT_EQ(0, PathRemove(file_path_.c_str()));
- file_path_.clear();
+ EXPECT_TRUE(file_util::Delete(file_path_, false));
+ file_path_ = FilePath(FILE_PATH_LITERAL(""));
}
void TestDirectorySetterUpper::RunInvariantCheck(const ScopedDirLookup& dir) {
@@ -88,7 +87,7 @@ void ManuallyOpenedTestDirectorySetterUpper::TearDown() {
TriggeredOpenTestDirectorySetterUpper::TriggeredOpenTestDirectorySetterUpper(
const std::string& name)
- : TestDirectorySetterUpper(UTF8ToPathStringQuick(name)) {
+ : TestDirectorySetterUpper(name) {
}
void TriggeredOpenTestDirectorySetterUpper::SetUp() {
diff --git a/chrome/test/sync/engine/test_directory_setter_upper.h b/chrome/test/sync/engine/test_directory_setter_upper.h
index 3c8936a..7e2cf48 100644
--- a/chrome/test/sync/engine/test_directory_setter_upper.h
+++ b/chrome/test/sync/engine/test_directory_setter_upper.h
@@ -68,7 +68,7 @@ class TestDirectorySetterUpper {
scoped_ptr<syncable::DirectoryManager> manager_;
const PathString name_;
- PathString file_path_;
+ FilePath file_path_;
};
// A variant of the above where SetUp does not actually open the directory.