Skip to content

Commit 9f48abd

Browse files
taku910hiroyuki-komatsu
authored andcommitted
Remvoed dictionary sync features. They are no longer used and mantained.
PiperOrigin-RevId: 734589342
1 parent d00b225 commit 9f48abd

7 files changed

+5
-264
lines changed

src/dictionary/user_dictionary.cc

-10
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,6 @@ class UserDictionary::UserDictionaryReloader {
279279
return;
280280
}
281281

282-
if (storage.ConvertSyncDictionariesToNormalDictionaries()) {
283-
LOG(INFO) << "Syncable dictionaries are converted to normal dictionaries";
284-
if (storage.Lock()) {
285-
if (absl::Status s = storage.Save(); !s.ok()) {
286-
LOG(ERROR) << "Failed to save to storage: " << s;
287-
}
288-
storage.UnLock();
289-
}
290-
}
291-
292282
dic_->Load(storage.GetProto());
293283
}
294284

src/dictionary/user_dictionary_storage.cc

-72
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ constexpr size_t kDefaultTotalBytesLimit = 512 << 20;
6464
// saved correctly. Please make the dictionary size smaller"
6565
constexpr size_t kDefaultWarningTotalBytesLimit = 256 << 20;
6666

67-
constexpr char kDefaultSyncDictionaryName[] = "Sync Dictionary";
68-
constexpr char kDictionaryNameConvertedFromSyncableDictionary[] = "同期用辞書";
69-
7067
using ::mozc::user_dictionary::UserDictionaryCommandStatus;
7168

7269
} // namespace
@@ -363,71 +360,6 @@ UserDictionaryStorage::GetLastError() const {
363360
return last_error_type_;
364361
}
365362

366-
bool UserDictionaryStorage::ConvertSyncDictionariesToNormalDictionaries() {
367-
if (CountSyncableDictionaries(proto_) == 0) {
368-
return false;
369-
}
370-
371-
for (int dictionary_index = proto_.dictionaries_size() - 1;
372-
dictionary_index >= 0; --dictionary_index) {
373-
UserDictionary *dic = proto_.mutable_dictionaries(dictionary_index);
374-
if (!dic->syncable()) {
375-
continue;
376-
}
377-
378-
// Delete removed entries.
379-
for (int i = dic->entries_size() - 1; i >= 0; --i) {
380-
if (dic->entries(i).removed()) {
381-
for (int j = i + 1; j < dic->entries_size(); ++j) {
382-
dic->mutable_entries()->SwapElements(j - 1, j);
383-
}
384-
dic->mutable_entries()->RemoveLast();
385-
}
386-
}
387-
388-
// Delete removed or unused sync dictionaries.
389-
if (dic->removed() || dic->entries_size() == 0) {
390-
for (int i = dictionary_index + 1; i < proto_.dictionaries_size(); ++i) {
391-
proto_.mutable_dictionaries()->SwapElements(i - 1, i);
392-
}
393-
proto_.mutable_dictionaries()->RemoveLast();
394-
continue;
395-
}
396-
397-
if (dic->name() == default_sync_dictionary_name()) {
398-
std::string new_dictionary_name =
399-
kDictionaryNameConvertedFromSyncableDictionary;
400-
int index = 0;
401-
while (UserDictionaryUtil::ValidateDictionaryName(proto_,
402-
new_dictionary_name) !=
403-
UserDictionaryCommandStatus::USER_DICTIONARY_COMMAND_SUCCESS) {
404-
++index;
405-
new_dictionary_name = absl::StrFormat(
406-
"%s_%d", kDictionaryNameConvertedFromSyncableDictionary, index);
407-
}
408-
dic->set_name(new_dictionary_name);
409-
}
410-
dic->set_syncable(false);
411-
}
412-
413-
DCHECK_EQ(0, CountSyncableDictionaries(proto_));
414-
415-
return true;
416-
}
417-
418-
// static
419-
int UserDictionaryStorage::CountSyncableDictionaries(
420-
const user_dictionary::UserDictionaryStorage &storage) {
421-
int num_syncable_dictionaries = 0;
422-
for (int i = 0; i < storage.dictionaries_size(); ++i) {
423-
const UserDictionary &dict = storage.dictionaries(i);
424-
if (dict.syncable()) {
425-
++num_syncable_dictionaries;
426-
}
427-
}
428-
return num_syncable_dictionaries;
429-
}
430-
431363
// static
432364
size_t UserDictionaryStorage::max_entry_size() {
433365
return UserDictionaryUtil::max_entry_size();
@@ -468,8 +400,4 @@ bool UserDictionaryStorage::IsValidDictionaryName(
468400
ABSL_UNREACHABLE();
469401
}
470402

471-
std::string UserDictionaryStorage::default_sync_dictionary_name() {
472-
return std::string(kDefaultSyncDictionaryName);
473-
}
474-
475403
} // namespace mozc

src/dictionary/user_dictionary_storage.h

+1-15
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class UserDictionaryStorage {
128128
bool UnLock();
129129

130130
// Export a dictionary to a file in TSV format.
131-
bool ExportDictionary(uint64_t dic_id, const std::string & file_name);
131+
bool ExportDictionary(uint64_t dic_id, const std::string &file_name);
132132

133133
// Create a new dictionary with a specified name. Returns the id of
134134
// the new instance via new_dic_id.
@@ -157,26 +157,12 @@ class UserDictionaryStorage {
157157
// You can obtain the reason of the error of dictionary operation.
158158
UserDictionaryStorageErrorType GetLastError() const;
159159

160-
// Converts syncable dictionaries to unsyncable dictionaries.
161-
// The name of default sync dictionary is renamed to locale-independent name
162-
// like other unsyncable dictionaries.
163-
// This method deletes syncable dictionaries which are marked as removed or
164-
// don't have any dictionary entries.
165-
// Returns true if this method converts some dictionaries.
166-
bool ConvertSyncDictionariesToNormalDictionaries();
167-
168-
// return the number of dictionaries with "synclbe" being true.
169-
static int CountSyncableDictionaries(
170-
const user_dictionary::UserDictionaryStorage &storage);
171-
172160
// maximum number of dictionaries this storage can hold
173161
static size_t max_dictionary_size();
174162

175163
// maximum number of entries one dictionary can hold
176164
static size_t max_entry_size();
177165

178-
static std::string default_sync_dictionary_name();
179-
180166
user_dictionary::UserDictionaryStorage &GetProto() { return proto_; }
181167

182168
const user_dictionary::UserDictionaryStorage &GetProto() const {

src/dictionary/user_dictionary_storage_test.cc

-126
Original file line numberDiff line numberDiff line change
@@ -295,132 +295,6 @@ TEST_F(UserDictionaryStorageTest, GetUserDictionaryIdTest) {
295295
EXPECT_EQ(ret_id[1], id[1]);
296296
}
297297

298-
TEST_F(UserDictionaryStorageTest, ConvertSyncDictionariesToNormalDictionaries) {
299-
// "名詞"
300-
const UserDictionary::PosType kPos = UserDictionary::NOUN;
301-
302-
const struct TestData {
303-
bool is_sync_dictionary;
304-
bool is_removed_dictionary;
305-
bool has_normal_entry;
306-
bool has_removed_entry;
307-
std::string dictionary_name;
308-
} test_data[] = {
309-
{false, false, false, false, "non-sync dictionary (empty)"},
310-
{false, false, true, false, "non-sync dictionary (normal entry)"},
311-
{true, false, false, false, "sync dictionary (empty)"},
312-
{true, false, false, true, "sync dictionary (removed entry)"},
313-
{true, false, true, false, "sync dictionary (normal entry)"},
314-
{true, false, true, true, "sync dictionary (normal & removed entries)"},
315-
{true, true, false, false, "removed sync dictionary (empty)"},
316-
{true, true, false, true, "removed sync dictionary (removed entry)"},
317-
{true, true, true, false, "removed sync dictionary (normal entry)"},
318-
{true, true, true, true,
319-
"removed sync dictionary (normal & removed entries)"},
320-
{true, false, true, false,
321-
UserDictionaryStorage::default_sync_dictionary_name()},
322-
};
323-
324-
UserDictionaryStorage storage(GetUserDictionaryFile());
325-
EXPECT_FALSE(storage.Load().ok())
326-
<< "At first, we expect there is not user dictionary file.";
327-
EXPECT_FALSE(storage.ConvertSyncDictionariesToNormalDictionaries())
328-
<< "No sync dictionary available.";
329-
330-
for (size_t i = 0; i < std::size(test_data); ++i) {
331-
SCOPED_TRACE(absl::StrFormat("add %d", static_cast<int>(i)));
332-
const TestData &data = test_data[i];
333-
CHECK(data.is_sync_dictionary ||
334-
!(data.is_removed_dictionary || data.has_removed_entry))
335-
<< "Non-sync dictionary should NOT have removed dictionary / entry.";
336-
337-
uint64_t dict_id = 0;
338-
ASSERT_TRUE(storage.CreateDictionary(data.dictionary_name, &dict_id));
339-
UserDictionaryStorage::UserDictionary *dict =
340-
storage.GetProto().mutable_dictionaries(
341-
storage.GetUserDictionaryIndex(dict_id));
342-
dict->set_syncable(data.is_sync_dictionary);
343-
dict->set_removed(data.is_removed_dictionary);
344-
if (data.has_normal_entry) {
345-
UserDictionaryStorage::UserDictionaryEntry *entry = dict->add_entries();
346-
entry->set_key("normal");
347-
entry->set_value("normal entry");
348-
entry->set_pos(kPos);
349-
}
350-
if (data.has_removed_entry) {
351-
UserDictionaryStorage::UserDictionaryEntry *entry = dict->add_entries();
352-
entry->set_key("removed");
353-
entry->set_value("removed entry");
354-
entry->set_pos(kPos);
355-
entry->set_removed(true);
356-
}
357-
}
358-
EXPECT_EQ(
359-
UserDictionaryStorage::CountSyncableDictionaries(storage.GetProto()), 9);
360-
361-
ASSERT_TRUE(storage.ConvertSyncDictionariesToNormalDictionaries());
362-
363-
constexpr char kDictionaryNameConvertedFromSyncableDictionary[] =
364-
"同期用辞書";
365-
const struct ExpectedData {
366-
bool has_normal_entry;
367-
std::string dictionary_name;
368-
} expected_data[] = {
369-
{false, "non-sync dictionary (empty)"},
370-
{true, "non-sync dictionary (normal entry)"},
371-
{true, "sync dictionary (normal entry)"},
372-
{true, "sync dictionary (normal & removed entries)"},
373-
{true, kDictionaryNameConvertedFromSyncableDictionary},
374-
};
375-
376-
EXPECT_EQ(
377-
0, UserDictionaryStorage::CountSyncableDictionaries(storage.GetProto()));
378-
ASSERT_EQ(std::size(expected_data), storage.GetProto().dictionaries_size());
379-
for (size_t i = 0; i < std::size(expected_data); ++i) {
380-
SCOPED_TRACE(absl::StrFormat("verify %d", static_cast<int>(i)));
381-
const ExpectedData &expected = expected_data[i];
382-
const UserDictionaryStorage::UserDictionary &dict =
383-
storage.GetProto().dictionaries(i);
384-
385-
EXPECT_EQ(dict.name(), expected.dictionary_name);
386-
EXPECT_FALSE(dict.syncable());
387-
EXPECT_FALSE(dict.removed());
388-
if (expected.has_normal_entry) {
389-
ASSERT_EQ(dict.entries_size(), 1);
390-
EXPECT_EQ(dict.entries(0).key(), "normal");
391-
} else {
392-
EXPECT_EQ(dict.entries_size(), 0);
393-
}
394-
}
395-
396-
// Test duplicated dictionary name.
397-
storage.GetProto().Clear();
398-
{
399-
uint64_t dict_id = 0;
400-
storage.CreateDictionary(
401-
UserDictionaryStorage::default_sync_dictionary_name(), &dict_id);
402-
storage.CreateDictionary(kDictionaryNameConvertedFromSyncableDictionary,
403-
&dict_id);
404-
ASSERT_EQ(2, storage.GetProto().dictionaries_size());
405-
UserDictionaryStorage::UserDictionary *dict;
406-
dict = storage.GetProto().mutable_dictionaries(0);
407-
dict->set_syncable(true);
408-
dict->add_entries()->set_key("0");
409-
dict = storage.GetProto().mutable_dictionaries(1);
410-
dict->set_syncable(false);
411-
dict->add_entries()->set_key("1");
412-
}
413-
ASSERT_TRUE(storage.ConvertSyncDictionariesToNormalDictionaries());
414-
EXPECT_EQ(
415-
UserDictionaryStorage::CountSyncableDictionaries(storage.GetProto()), 0);
416-
EXPECT_EQ(storage.GetProto().dictionaries_size(), 2);
417-
EXPECT_EQ(
418-
storage.GetProto().dictionaries(0).name(),
419-
absl::StrFormat("%s_1", kDictionaryNameConvertedFromSyncableDictionary));
420-
EXPECT_EQ(storage.GetProto().dictionaries(1).name(),
421-
kDictionaryNameConvertedFromSyncableDictionary);
422-
}
423-
424298
TEST_F(UserDictionaryStorageTest, Export) {
425299
constexpr int kDummyDictionaryId = 10;
426300
TempDirectory temp_dir = testing::MakeTempDirectoryOrDie();

src/gui/dictionary_tool/dictionary_tool.cc

-10
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,6 @@ DictionaryTool::DictionaryTool(QWidget *parent)
358358
return;
359359
}
360360

361-
#ifndef ENABLE_CLOUD_SYNC
362-
if (session_->mutable_storage()
363-
->ConvertSyncDictionariesToNormalDictionaries()) {
364-
LOG(INFO) << "Syncable dictionaries are converted to normal dictionaries";
365-
if (absl::Status s = session_->mutable_storage()->Save(); !s.ok()) {
366-
LOG(ERROR) << "Failed to save the storage: " << s;
367-
}
368-
}
369-
#endif // !ENABLE_CLOUD_SYNC
370-
371361
// main window
372362
#ifndef __linux__
373363
// For some reason setCentralWidget crashes the dictionary_tool on Linux

src/gui/word_register_dialog/word_register_dialog.cc

-10
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,6 @@ WordRegisterDialog::WordRegisterDialog()
144144
return;
145145
}
146146

147-
#ifndef ENABLE_CLOUD_SYNC
148-
if (session_->mutable_storage()
149-
->ConvertSyncDictionariesToNormalDictionaries()) {
150-
LOG(INFO) << "Syncable dictionaries are converted to normal dictionaries";
151-
if (absl::Status s = session_->mutable_storage()->Save(); !s.ok()) {
152-
LOG(ERROR) << "Failed to save the storage: " << s;
153-
}
154-
}
155-
#endif // !ENABLE_CLOUD_SYNC
156-
157147
// Initialize ComboBox
158148
const std::vector<std::string> pos_set = pos_list_provider_.GetPosList();
159149
CHECK(!pos_set.empty());

src/protocol/user_dictionary_storage.proto

+4-21
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,7 @@ message UserDictionary {
128128
// "名詞:ja".
129129
optional string locale = 12 [default = ""];
130130

131-
// set true if this entry is removed.
132-
// This flag is used for cloud sync feature.
133-
// Cloud sync feature is already deprecated and this flag is only
134-
// used to convert sync dictionary to normal dictionary.
135-
optional bool removed = 10 [default = false];
131+
reserved 10; // deprecated removed
136132

137133
// set true if this entry is automatically registered
138134
// by converter.
@@ -141,16 +137,8 @@ message UserDictionary {
141137

142138
repeated Entry entries = 4;
143139

144-
// set true if this dictionary is removed.
145-
// This flag is used for cloud sync feature.
146-
// Cloud sync feature is already deprecated and this flag is only
147-
// used to convert sync dictionary to normal dictionary.
148-
optional bool removed = 5 [default = false];
149-
150-
// This flag is used for cloud sync feature.
151-
// Cloud sync feature is already deprecated and this flag is only
152-
// used to convert sync dictionary to normal dictionary.
153-
optional bool syncable = 6 [default = false];
140+
reserved 5; // deprecated removed
141+
reserved 6; // deprecated syncable
154142
}
155143

156144
message UserDictionaryStorage {
@@ -160,12 +148,7 @@ message UserDictionaryStorage {
160148
// dictionary body
161149
repeated UserDictionary dictionaries = 2;
162150

163-
enum StorageType {
164-
SNAPSHOT = 1; // This storage is a snapshot.
165-
UPDATE = 2; // This storage is a diff of some snapshots.
166-
}
167-
168-
optional StorageType storage_type = 10 [default = SNAPSHOT];
151+
reserved 10; // deprecated storage_type
169152
}
170153

171154
message UserDictionaryCommand {

0 commit comments

Comments
 (0)