void-packages/srcpkgs/mozc/patches/protobuf-370.patch

328 lines
14 KiB
Diff
Raw Normal View History

--- mozc/src/dictionary/user_dictionary.cc
+++ mozc/src/dictionary/user_dictionary.cc
@@ -289,7 +289,7 @@ class UserDictionary::UserDictionaryReloader : public Thread {
}
auto_register_mode_ = false;
- dic_->Load(*(storage.get()));
+ dic_->Load(*(storage->storage()));
}
private:
--- mozc/src/dictionary/user_dictionary_session.cc
+++ mozc/src/dictionary/user_dictionary_session.cc
@@ -144,7 +144,7 @@ class UndoRenameDictionaryCommand : public UserDictionarySession::UndoCommand {
virtual bool RunUndo(mozc::UserDictionaryStorage *storage) {
UserDictionary *dictionary =
UserDictionaryUtil::GetMutableUserDictionaryById(
- storage, dictionary_id_);
+ storage->storage(), dictionary_id_);
if (dictionary == NULL) {
return false;
}
@@ -169,7 +169,7 @@ class UndoAddEntryCommand : public UserDictionarySession::UndoCommand {
virtual bool RunUndo(mozc::UserDictionaryStorage *storage) {
UserDictionary *dictionary =
UserDictionaryUtil::GetMutableUserDictionaryById(
- storage, dictionary_id_);
+ storage->storage(), dictionary_id_);
if (dictionary == NULL || dictionary->entries_size() == 0) {
return false;
}
@@ -195,7 +195,7 @@ class UndoEditEntryCommand : public UserDictionarySession::UndoCommand {
virtual bool RunUndo(mozc::UserDictionaryStorage *storage) {
UserDictionary *dictionary =
UserDictionaryUtil::GetMutableUserDictionaryById(
- storage, dictionary_id_);
+ storage->storage(), dictionary_id_);
if (dictionary == NULL ||
index_ < 0 || dictionary->entries_size() <= index_) {
return false;
@@ -240,7 +240,7 @@ class UndoDeleteEntryCommand : public UserDictionarySession::UndoCommand {
virtual bool RunUndo(mozc::UserDictionaryStorage *storage) {
UserDictionary *dictionary =
UserDictionaryUtil::GetMutableUserDictionaryById(
- storage, dictionary_id_);
+ storage->storage(), dictionary_id_);
if (dictionary == NULL) {
return false;
}
@@ -306,7 +306,7 @@ class UndoImportFromStringCommand : public UserDictionarySession::UndoCommand {
virtual bool RunUndo(mozc::UserDictionaryStorage *storage) {
UserDictionary *dictionary =
UserDictionaryUtil::GetMutableUserDictionaryById(
- storage, dictionary_id_);
+ storage->storage(), dictionary_id_);
if (dictionary == NULL) {
return false;
}
@@ -345,7 +345,7 @@ UserDictionarySession::~UserDictionarySession() {
// TODO(hidehiko) move this to header.
const UserDictionaryStorage &UserDictionarySession::storage() const {
- return *storage_;
+ return *storage_->storage();
}
mozc::UserDictionaryStorage *UserDictionarySession::mutable_storage() {
return storage_.get();
@@ -464,7 +464,7 @@ UserDictionaryCommandStatus::Status UserDictionarySession::CreateDictionary(
const string &dictionary_name, uint64 *new_dictionary_id) {
UserDictionaryCommandStatus::Status status =
UserDictionaryUtil::CreateDictionary(
- storage_.get(), dictionary_name, new_dictionary_id);
+ storage_->storage(), dictionary_name, new_dictionary_id);
if (status == UserDictionaryCommandStatus::USER_DICTIONARY_COMMAND_SUCCESS) {
AddUndoCommand(new UndoCreateDictionaryCommand);
}
@@ -488,7 +488,7 @@ UserDictionarySession::DeleteDictionaryInternal(
int original_index;
UserDictionary *deleted_dictionary;
if (!UserDictionaryUtil::DeleteDictionary(
- storage_.get(), dictionary_id,
+ storage_->storage(), dictionary_id,
&original_index, &deleted_dictionary)) {
// Failed to delete the dictionary.
return UserDictionaryCommandStatus::UNKNOWN_DICTIONARY_ID;
@@ -510,7 +510,7 @@ UserDictionaryCommandStatus::Status UserDictionarySession::RenameDictionary(
uint64 dictionary_id, const string &dictionary_name) {
string original_name;
const UserDictionary *dictionary =
- UserDictionaryUtil::GetUserDictionaryById(*storage_, dictionary_id);
+ UserDictionaryUtil::GetUserDictionaryById(*storage_->storage(), dictionary_id);
if (dictionary != NULL) {
// Note that if dictionary is null, it means the dictionary_id is invalid
// so following RenameDictionary will fail, and error handling is done
@@ -547,7 +547,7 @@ UserDictionaryCommandStatus::Status UserDictionarySession::AddEntry(
uint64 dictionary_id, const UserDictionary::Entry &entry) {
UserDictionary *dictionary =
UserDictionaryUtil::GetMutableUserDictionaryById(
- storage_.get(), dictionary_id);
+ storage_->storage(), dictionary_id);
if (dictionary == NULL) {
return UserDictionaryCommandStatus::UNKNOWN_DICTIONARY_ID;
}
@@ -575,7 +575,7 @@ UserDictionaryCommandStatus::Status UserDictionarySession::EditEntry(
uint64 dictionary_id, int index, const UserDictionary::Entry &entry) {
UserDictionary *dictionary =
UserDictionaryUtil::GetMutableUserDictionaryById(
- storage_.get(), dictionary_id);
+ storage_->storage(), dictionary_id);
if (dictionary == NULL) {
return UserDictionaryCommandStatus::UNKNOWN_DICTIONARY_ID;
}
@@ -604,7 +604,7 @@ UserDictionaryCommandStatus::Status UserDictionarySession::DeleteEntry(
uint64 dictionary_id, const std::vector<int> &index_list) {
UserDictionary *dictionary =
UserDictionaryUtil::GetMutableUserDictionaryById(
- storage_.get(), dictionary_id);
+ storage_->storage(), dictionary_id);
if (dictionary == NULL) {
return UserDictionaryCommandStatus::UNKNOWN_DICTIONARY_ID;
}
@@ -644,7 +644,7 @@ UserDictionaryCommandStatus::Status UserDictionarySession::ImportFromString(
uint64 dictionary_id, const string &data) {
UserDictionary *dictionary =
UserDictionaryUtil::GetMutableUserDictionaryById(
- storage_.get(), dictionary_id);
+ storage_->storage(), dictionary_id);
if (dictionary == NULL) {
return UserDictionaryCommandStatus::UNKNOWN_DICTIONARY_ID;
}
@@ -699,7 +699,7 @@ UserDictionarySession::ImportToNewDictionaryFromString(
uint64 *new_dictionary_id) {
UserDictionaryCommandStatus::Status status =
UserDictionaryUtil::CreateDictionary(
- storage_.get(), dictionary_name, new_dictionary_id);
+ storage_->storage(), dictionary_name, new_dictionary_id);
if (status != UserDictionaryCommandStatus::USER_DICTIONARY_COMMAND_SUCCESS) {
return status;
}
@@ -709,7 +709,7 @@ UserDictionarySession::ImportToNewDictionaryFromString(
UserDictionary *dictionary =
UserDictionaryUtil::GetMutableUserDictionaryById(
- storage_.get(), *new_dictionary_id);
+ storage_->storage(), *new_dictionary_id);
if (dictionary == NULL) {
// The dictionary should be always found.
return UserDictionaryCommandStatus::UNKNOWN_ERROR;
@@ -728,7 +728,7 @@ bool UserDictionarySession::EnsureNonEmptyStorage() {
uint64 new_dictionary_id;
UserDictionaryCommandStatus::Status status =
UserDictionaryUtil::CreateDictionary(
- storage_.get(), default_dictionary_name_, &new_dictionary_id);
+ storage_->storage(), default_dictionary_name_, &new_dictionary_id);
CHECK_EQ(
status, UserDictionaryCommandStatus::USER_DICTIONARY_COMMAND_SUCCESS);
return true;
--- mozc/src/dictionary/user_dictionary_storage.cc
+++ mozc/src/dictionary/user_dictionary_storage.cc
@@ -109,7 +109,7 @@ bool UserDictionaryStorage::LoadInternal() {
mozc::protobuf::io::IstreamInputStream zero_copy_input(&ifs);
mozc::protobuf::io::CodedInputStream decoder(&zero_copy_input);
decoder.SetTotalBytesLimit(kDefaultTotalBytesLimit, -1);
- if (!ParseFromCodedStream(&decoder)) {
+ if (!storage_.ParseFromCodedStream(&decoder)) {
LOG(ERROR) << "Failed to parse";
if (!decoder.ConsumedEntireMessage() || !ifs.eof()) {
LOG(ERROR) << "ParseFromStream failed: file seems broken";
@@ -141,7 +141,7 @@ bool UserDictionaryStorage::Load() {
const UserDictionary &dict = dictionaries(i);
if (dict.id() == 0) {
mutable_dictionaries(i)->set_id(
- UserDictionaryUtil::CreateNewDictionaryId(*this));
+ UserDictionaryUtil::CreateNewDictionaryId(storage_));
}
}
@@ -171,7 +171,7 @@ bool UserDictionaryStorage::Save() {
return false;
}
- if (!SerializeToOstream(&ofs)) {
+ if (!storage_.SerializeToOstream(&ofs)) {
LOG(ERROR) << "SerializeToString failed";
last_error_type_ = SYNC_FAILURE;
return false;
@@ -241,7 +241,7 @@ bool UserDictionaryStorage::ExportDictionary(
bool UserDictionaryStorage::CreateDictionary(
const string &dic_name, uint64 *new_dic_id) {
UserDictionaryCommandStatus::Status status =
- UserDictionaryUtil::CreateDictionary(this, dic_name, new_dic_id);
+ UserDictionaryUtil::CreateDictionary(&storage_, dic_name, new_dic_id);
// Update last_error_type_
switch (status) {
case UserDictionaryCommandStatus::DICTIONARY_NAME_EMPTY:
@@ -273,7 +273,7 @@ bool UserDictionaryStorage::CreateDictionary(
}
bool UserDictionaryStorage::DeleteDictionary(uint64 dic_id) {
- if (!UserDictionaryUtil::DeleteDictionary(this, dic_id, NULL, NULL)) {
+ if (!UserDictionaryUtil::DeleteDictionary(&storage_, dic_id, NULL, NULL)) {
// Failed to delete dictionary.
last_error_type_ = INVALID_DICTIONARY_ID;
return false;
@@ -318,7 +318,7 @@ bool UserDictionaryStorage::RenameDictionary(uint64 dic_id,
}
int UserDictionaryStorage::GetUserDictionaryIndex(uint64 dic_id) const {
- return UserDictionaryUtil::GetUserDictionaryIndexById(*this, dic_id);
+ return UserDictionaryUtil::GetUserDictionaryIndexById(storage_, dic_id);
}
bool UserDictionaryStorage::GetUserDictionaryId(const string &dic_name,
@@ -335,7 +335,7 @@ bool UserDictionaryStorage::GetUserDictionaryId(const string &dic_name,
user_dictionary::UserDictionary *UserDictionaryStorage::GetUserDictionary(
uint64 dic_id) {
- return UserDictionaryUtil::GetMutableUserDictionaryById(this, dic_id);
+ return UserDictionaryUtil::GetMutableUserDictionaryById(&storage_, dic_id);
}
UserDictionaryStorage::UserDictionaryStorageErrorType
@@ -361,14 +361,14 @@ bool UserDictionaryStorage::AddToAutoRegisteredDictionary(
UserDictionary *dic = NULL;
if (auto_index == -1) {
- if (UserDictionaryUtil::IsStorageFull(*this)) {
+ if (UserDictionaryUtil::IsStorageFull(storage_)) {
last_error_type_ = TOO_MANY_DICTIONARIES;
LOG(ERROR) << "too many dictionaries";
UnLock();
return false;
}
dic = add_dictionaries();
- dic->set_id(UserDictionaryUtil::CreateNewDictionaryId(*this));
+ dic->set_id(UserDictionaryUtil::CreateNewDictionaryId(storage_));
dic->set_name(kAutoRegisteredDictionaryName);
} else {
dic = mutable_dictionaries(auto_index);
@@ -410,7 +410,7 @@ bool UserDictionaryStorage::AddToAutoRegisteredDictionary(
}
bool UserDictionaryStorage::ConvertSyncDictionariesToNormalDictionaries() {
- if (CountSyncableDictionaries(*this) == 0) {
+ if (CountSyncableDictionaries(storage_) == 0) {
return false;
}
@@ -445,7 +445,7 @@ bool UserDictionaryStorage::ConvertSyncDictionariesToNormalDictionaries() {
kDictionaryNameConvertedFromSyncableDictionary;
int index = 0;
while (UserDictionaryUtil::ValidateDictionaryName(
- *this, new_dictionary_name)
+ storage_, new_dictionary_name)
!= UserDictionaryCommandStatus::USER_DICTIONARY_COMMAND_SUCCESS) {
++index;
new_dictionary_name = Util::StringPrintf(
@@ -456,7 +456,7 @@ bool UserDictionaryStorage::ConvertSyncDictionariesToNormalDictionaries() {
dic->set_syncable(false);
}
- DCHECK_EQ(0, CountSyncableDictionaries(*this));
+ DCHECK_EQ(0, CountSyncableDictionaries(storage_));
return true;
}
--- mozc/src/dictionary/user_dictionary_storage.h
+++ mozc/src/dictionary/user_dictionary_storage.h
@@ -74,8 +74,20 @@ class ProcessMutex;
// Inherit from ProtocolBuffer
// TODO(hidehiko): Get rid of this implementation.
-class UserDictionaryStorage : public user_dictionary::UserDictionaryStorage {
+class UserDictionaryStorage {
+ private:
+ user_dictionary::UserDictionaryStorage storage_;
public:
+ static const user_dictionary::UserDictionaryStorage& default_instance() { return user_dictionary::UserDictionaryStorage::default_instance(); }
+ user_dictionary::UserDictionaryStorage *storage() { return &storage_; }
+ int dictionaries_size() const { return storage_.dictionaries_size(); }
+ void clear_dictionaries() { storage_.clear_dictionaries(); }
+ user_dictionary::UserDictionary* mutable_dictionaries(int index) { return storage_.mutable_dictionaries(index); }
+ ::google::protobuf::RepeatedPtrField<user_dictionary::UserDictionary >* mutable_dictionaries() { return storage_.mutable_dictionaries(); }
+ const ::google::protobuf::RepeatedPtrField<user_dictionary::UserDictionary >& dictionaries() const { return storage_.dictionaries(); }
+ const user_dictionary::UserDictionary& dictionaries(int index) const { return storage_.dictionaries(index); }
+ user_dictionary::UserDictionary* add_dictionaries() { return storage_.add_dictionaries(); }
+
typedef user_dictionary::UserDictionary UserDictionary;
typedef user_dictionary::UserDictionary::Entry UserDictionaryEntry;
--- mozc/src/prediction/user_history_predictor.cc
+++ mozc/src/prediction/user_history_predictor.cc
@@ -291,7 +291,7 @@ bool UserHistoryStorage::Load() {
return false;
}
- if (!ParseFromString(input)) {
+ if (!userHistory_.ParseFromString(input)) {
LOG(ERROR) << "ParseFromString failed. message looks broken";
return false;
}
@@ -307,7 +307,7 @@ bool UserHistoryStorage::Save() const {
}
string output;
- if (!AppendToString(&output)) {
+ if (!userHistory_.AppendToString(&output)) {
LOG(ERROR) << "AppendToString failed";
return false;
}
--- mozc/src/prediction/user_history_predictor.h
+++ mozc/src/prediction/user_history_predictor.h
@@ -61,8 +61,13 @@ class Segments;
class UserHistoryPredictorSyncer;
// Added serialization method for UserHistory.
-class UserHistoryStorage : public mozc::user_history_predictor::UserHistory {
+class UserHistoryStorage {
+ private:
+ user_history_predictor::UserHistory userHistory_;
public:
+ int entries_size() const { return userHistory_.entries_size(); }
+ const user_history_predictor::UserHistory_Entry& entries(int index) const { return userHistory_.entries(index); }
+ user_history_predictor::UserHistory_Entry* add_entries() { return userHistory_.add_entries(); }
explicit UserHistoryStorage(const string &filename);
~UserHistoryStorage();