aboutsummaryrefslogtreecommitdiff
path: root/japanese/mozc-server/files/patch-src_dictionary_user__dictionary__storage.cc
blob: ffcff76f194a54e3a7d273b5ae70f5815faf04c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
--- src/dictionary/user_dictionary_storage.cc.orig	2019-03-04 18:35:55 UTC
+++ 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 (!user_dictionary_storage_base.ParseFromCodedStream(&decoder)) {
     LOG(ERROR) << "Failed to parse";
     if (!decoder.ConsumedEntireMessage() || !ifs.eof()) {
       LOG(ERROR) << "ParseFromStream failed: file seems broken";
@@ -137,11 +137,11 @@ bool UserDictionaryStorage::Load() {
   }
 
   // Check dictionary id here. if id is 0, assign random ID.
-  for (int i = 0; i < dictionaries_size(); ++i) {
-    const UserDictionary &dict = dictionaries(i);
+  for (int i = 0; i < user_dictionary_storage_base.dictionaries_size(); ++i) {
+    const UserDictionary &dict = user_dictionary_storage_base.dictionaries(i);
     if (dict.id() == 0) {
-      mutable_dictionaries(i)->set_id(
-          UserDictionaryUtil::CreateNewDictionaryId(*this));
+      user_dictionary_storage_base.mutable_dictionaries(i)->set_id(
+          UserDictionaryUtil::CreateNewDictionaryId(this->user_dictionary_storage_base));
     }
   }
 
@@ -171,7 +171,7 @@ bool UserDictionaryStorage::Save() {
       return false;
     }
 
-    if (!SerializeToOstream(&ofs)) {
+    if (!user_dictionary_storage_base.SerializeToOstream(&ofs)) {
       LOG(ERROR) << "SerializeToString failed";
       last_error_type_ = SYNC_FAILURE;
       return false;
@@ -227,7 +227,7 @@ bool UserDictionaryStorage::ExportDictio
     return false;
   }
 
-  const UserDictionary &dic = dictionaries(index);
+  const UserDictionary &dic = user_dictionary_storage_base.dictionaries(index);
   for (size_t i = 0; i < dic.entries_size(); ++i) {
     const UserDictionaryEntry &entry = dic.entries(i);
     ofs << entry.key() << "\t" << entry.value() << "\t"
@@ -241,7 +241,7 @@ bool UserDictionaryStorage::ExportDictio
 bool UserDictionaryStorage::CreateDictionary(
     const string &dic_name, uint64 *new_dic_id) {
   UserDictionaryCommandStatus::Status status =
-      UserDictionaryUtil::CreateDictionary(this, dic_name, new_dic_id);
+      UserDictionaryUtil::CreateDictionary(&this->user_dictionary_storage_base, dic_name, new_dic_id);
   // Update last_error_type_
   switch (status) {
     case UserDictionaryCommandStatus::DICTIONARY_NAME_EMPTY:
@@ -273,7 +273,7 @@ bool UserDictionaryStorage::CreateDictio
 }
 
 bool UserDictionaryStorage::DeleteDictionary(uint64 dic_id) {
-  if (!UserDictionaryUtil::DeleteDictionary(this, dic_id, NULL, NULL)) {
+  if (!UserDictionaryUtil::DeleteDictionary(&this->user_dictionary_storage_base, dic_id, NULL, NULL)) {
     // Failed to delete dictionary.
     last_error_type_ = INVALID_DICTIONARY_ID;
     return false;
@@ -304,8 +304,8 @@ bool UserDictionaryStorage::RenameDictio
     return true;
   }
 
-  for (int i = 0; i < dictionaries_size(); ++i) {
-    if (dic_name == dictionaries(i).name()) {
+  for (int i = 0; i < user_dictionary_storage_base.dictionaries_size(); ++i) {
+    if (dic_name == user_dictionary_storage_base.dictionaries(i).name()) {
       last_error_type_ = DUPLICATED_DICTIONARY_NAME;
       LOG(ERROR) << "duplicated dictionary name";
       return false;
@@ -318,14 +318,14 @@ bool UserDictionaryStorage::RenameDictio
 }
 
 int UserDictionaryStorage::GetUserDictionaryIndex(uint64 dic_id) const {
-  return UserDictionaryUtil::GetUserDictionaryIndexById(*this, dic_id);
+  return UserDictionaryUtil::GetUserDictionaryIndexById(this->user_dictionary_storage_base, dic_id);
 }
 
 bool UserDictionaryStorage::GetUserDictionaryId(const string &dic_name,
                                                 uint64 *dic_id) {
-  for (size_t i = 0; i < dictionaries_size(); ++i) {
-    if (dic_name == dictionaries(i).name()) {
-      *dic_id = dictionaries(i).id();
+  for (size_t i = 0; i < user_dictionary_storage_base.dictionaries_size(); ++i) {
+    if (dic_name == user_dictionary_storage_base.dictionaries(i).name()) {
+      *dic_id = user_dictionary_storage_base.dictionaries(i).id();
       return true;
     }
   }
@@ -335,7 +335,7 @@ bool UserDictionaryStorage::GetUserDicti
 
 user_dictionary::UserDictionary *UserDictionaryStorage::GetUserDictionary(
     uint64 dic_id) {
-  return UserDictionaryUtil::GetMutableUserDictionaryById(this, dic_id);
+  return UserDictionaryUtil::GetMutableUserDictionaryById(&this->user_dictionary_storage_base, dic_id);
 }
 
 UserDictionaryStorage::UserDictionaryStorageErrorType
@@ -352,8 +352,8 @@ bool UserDictionaryStorage::AddToAutoReg
   }
 
   int auto_index = -1;
-  for (int i = 0; i < dictionaries_size(); ++i) {
-    if (dictionaries(i).name() == kAutoRegisteredDictionaryName) {
+  for (int i = 0; i < user_dictionary_storage_base.dictionaries_size(); ++i) {
+    if (user_dictionary_storage_base.dictionaries(i).name() == kAutoRegisteredDictionaryName) {
       auto_index = i;
       break;
     }
@@ -361,17 +361,17 @@ bool UserDictionaryStorage::AddToAutoReg
 
   UserDictionary *dic = NULL;
   if (auto_index == -1) {
-    if (UserDictionaryUtil::IsStorageFull(*this)) {
+    if (UserDictionaryUtil::IsStorageFull(this->user_dictionary_storage_base)) {
       last_error_type_ = TOO_MANY_DICTIONARIES;
       LOG(ERROR) << "too many dictionaries";
       UnLock();
       return false;
     }
-    dic = add_dictionaries();
-    dic->set_id(UserDictionaryUtil::CreateNewDictionaryId(*this));
+    dic = user_dictionary_storage_base.add_dictionaries();
+    dic->set_id(UserDictionaryUtil::CreateNewDictionaryId(this->user_dictionary_storage_base));
     dic->set_name(kAutoRegisteredDictionaryName);
   } else {
-    dic = mutable_dictionaries(auto_index);
+    dic = user_dictionary_storage_base.mutable_dictionaries(auto_index);
   }
 
   if (dic == NULL) {
@@ -410,13 +410,13 @@ bool UserDictionaryStorage::AddToAutoReg
 }
 
 bool UserDictionaryStorage::ConvertSyncDictionariesToNormalDictionaries() {
-  if (CountSyncableDictionaries(*this) == 0) {
+  if (CountSyncableDictionaries(this->user_dictionary_storage_base) == 0) {
     return false;
   }
 
-  for (int dictionary_index = dictionaries_size() - 1;
+  for (int dictionary_index = user_dictionary_storage_base.dictionaries_size() - 1;
        dictionary_index >= 0; --dictionary_index) {
-    UserDictionary *dic = mutable_dictionaries(dictionary_index);
+    UserDictionary *dic = user_dictionary_storage_base.mutable_dictionaries(dictionary_index);
     if (!dic->syncable()) {
       continue;
     }
@@ -433,10 +433,10 @@ bool UserDictionaryStorage::ConvertSyncD
 
     // Delete removed or unused sync dictionaries.
     if (dic->removed() || dic->entries_size() == 0) {
-      for (int i = dictionary_index + 1; i < dictionaries_size(); ++i) {
-        mutable_dictionaries()->SwapElements(i - 1, i);
+      for (int i = dictionary_index + 1; i < user_dictionary_storage_base.dictionaries_size(); ++i) {
+        user_dictionary_storage_base.mutable_dictionaries()->SwapElements(i - 1, i);
       }
-      mutable_dictionaries()->RemoveLast();
+      user_dictionary_storage_base.mutable_dictionaries()->RemoveLast();
       continue;
     }
 
@@ -445,7 +445,7 @@ bool UserDictionaryStorage::ConvertSyncD
           kDictionaryNameConvertedFromSyncableDictionary;
       int index = 0;
       while (UserDictionaryUtil::ValidateDictionaryName(
-                 *this, new_dictionary_name)
+                 this->user_dictionary_storage_base, new_dictionary_name)
              != UserDictionaryCommandStatus::USER_DICTIONARY_COMMAND_SUCCESS) {
         ++index;
         new_dictionary_name = Util::StringPrintf(
@@ -456,7 +456,7 @@ bool UserDictionaryStorage::ConvertSyncD
     dic->set_syncable(false);
   }
 
-  DCHECK_EQ(0, CountSyncableDictionaries(*this));
+  DCHECK_EQ(0, CountSyncableDictionaries(this->user_dictionary_storage_base));
 
   return true;
 }
@@ -487,7 +487,7 @@ size_t UserDictionaryStorage::max_dictio
 bool UserDictionaryStorage::IsValidDictionaryName(const string &name) {
   UserDictionaryCommandStatus::Status status =
       UserDictionaryUtil::ValidateDictionaryName(
-          UserDictionaryStorage::default_instance(), name);
+          user_dictionary::UserDictionaryStorage::default_instance(), name);
 
   // Update last_error_type_.
   switch (status) {