OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/bookmarks/bookmark_html_writer.h" | 5 #include "chrome/browser/bookmarks/bookmark_html_writer.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 !roots_d_value->Get(BookmarkCodec::kOtherBookmarkFolderNameKey, | 102 !roots_d_value->Get(BookmarkCodec::kOtherBookmarkFolderNameKey, |
103 &other_folder_value) || | 103 &other_folder_value) || |
104 other_folder_value->GetType() != Value::TYPE_DICTIONARY) { | 104 other_folder_value->GetType() != Value::TYPE_DICTIONARY) { |
105 NOTREACHED(); | 105 NOTREACHED(); |
106 return; // Invalid type for root folder and/or other folder. | 106 return; // Invalid type for root folder and/or other folder. |
107 } | 107 } |
108 | 108 |
109 IncrementIndent(); | 109 IncrementIndent(); |
110 | 110 |
111 if (!WriteNode(*static_cast<DictionaryValue*>(root_folder_value), | 111 if (!WriteNode(*static_cast<DictionaryValue*>(root_folder_value), |
112 history::StarredEntry::BOOKMARK_BAR) || | 112 BookmarkNode::BOOKMARK_BAR) || |
113 !WriteNode(*static_cast<DictionaryValue*>(other_folder_value), | 113 !WriteNode(*static_cast<DictionaryValue*>(other_folder_value), |
114 history::StarredEntry::OTHER)) { | 114 BookmarkNode::OTHER_NODE)) { |
115 return; | 115 return; |
116 } | 116 } |
117 | 117 |
118 DecrementIndent(); | 118 DecrementIndent(); |
119 | 119 |
120 Write(kFolderChildrenEnd); | 120 Write(kFolderChildrenEnd); |
121 Write(kNewline); | 121 Write(kNewline); |
122 } | 122 } |
123 | 123 |
124 private: | 124 private: |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // Converts a time string written to the JSON codec into a time_t string | 197 // Converts a time string written to the JSON codec into a time_t string |
198 // (used by bookmarks.html) and writes it. | 198 // (used by bookmarks.html) and writes it. |
199 bool WriteTime(const std::wstring& time_string) { | 199 bool WriteTime(const std::wstring& time_string) { |
200 base::Time time = base::Time::FromInternalValue( | 200 base::Time time = base::Time::FromInternalValue( |
201 StringToInt64(WideToUTF16Hack(time_string))); | 201 StringToInt64(WideToUTF16Hack(time_string))); |
202 return Write(Int64ToString(time.ToTimeT())); | 202 return Write(Int64ToString(time.ToTimeT())); |
203 } | 203 } |
204 | 204 |
205 // Writes the node and all its children, returning true on success. | 205 // Writes the node and all its children, returning true on success. |
206 bool WriteNode(const DictionaryValue& value, | 206 bool WriteNode(const DictionaryValue& value, |
207 history::StarredEntry::Type folder_type) { | 207 BookmarkNode::Type folder_type) { |
208 std::wstring title, date_added_string, type_string; | 208 std::wstring title, date_added_string, type_string; |
209 if (!value.GetString(BookmarkCodec::kNameKey, &title) || | 209 if (!value.GetString(BookmarkCodec::kNameKey, &title) || |
210 !value.GetString(BookmarkCodec::kDateAddedKey, &date_added_string) || | 210 !value.GetString(BookmarkCodec::kDateAddedKey, &date_added_string) || |
211 !value.GetString(BookmarkCodec::kTypeKey, &type_string) || | 211 !value.GetString(BookmarkCodec::kTypeKey, &type_string) || |
212 (type_string != BookmarkCodec::kTypeURL && | 212 (type_string != BookmarkCodec::kTypeURL && |
213 type_string != BookmarkCodec::kTypeFolder)) { | 213 type_string != BookmarkCodec::kTypeFolder)) { |
214 NOTREACHED(); | 214 NOTREACHED(); |
215 return false; | 215 return false; |
216 } | 216 } |
217 | 217 |
(...skipping 20 matching lines...) Expand all Loading... |
238 // Folder. | 238 // Folder. |
239 std::wstring last_modified_date; | 239 std::wstring last_modified_date; |
240 Value* child_values; | 240 Value* child_values; |
241 if (!value.GetString(BookmarkCodec::kDateModifiedKey, | 241 if (!value.GetString(BookmarkCodec::kDateModifiedKey, |
242 &last_modified_date) || | 242 &last_modified_date) || |
243 !value.Get(BookmarkCodec::kChildrenKey, &child_values) || | 243 !value.Get(BookmarkCodec::kChildrenKey, &child_values) || |
244 child_values->GetType() != Value::TYPE_LIST) { | 244 child_values->GetType() != Value::TYPE_LIST) { |
245 NOTREACHED(); | 245 NOTREACHED(); |
246 return false; | 246 return false; |
247 } | 247 } |
248 if (folder_type != history::StarredEntry::OTHER) { | 248 if (folder_type != BookmarkNode::OTHER_NODE) { |
249 // The other folder name is not written out. This gives the effect of | 249 // The other folder name is not written out. This gives the effect of |
250 // making the contents of the 'other folder' be a sibling to the bookmark | 250 // making the contents of the 'other folder' be a sibling to the bookmark |
251 // bar folder. | 251 // bar folder. |
252 if (!WriteIndent() || | 252 if (!WriteIndent() || |
253 !Write(kFolderStart) || | 253 !Write(kFolderStart) || |
254 !WriteTime(date_added_string) || | 254 !WriteTime(date_added_string) || |
255 !Write(kLastModified) || | 255 !Write(kLastModified) || |
256 !WriteTime(last_modified_date)) { | 256 !WriteTime(last_modified_date)) { |
257 return false; | 257 return false; |
258 } | 258 } |
259 if (folder_type == history::StarredEntry::BOOKMARK_BAR) { | 259 if (folder_type == BookmarkNode::BOOKMARK_BAR) { |
260 if (!Write(kBookmarkBar)) | 260 if (!Write(kBookmarkBar)) |
261 return false; | 261 return false; |
262 title = l10n_util::GetString(IDS_BOOMARK_BAR_FOLDER_NAME); | 262 title = l10n_util::GetString(IDS_BOOMARK_BAR_FOLDER_NAME); |
263 } else if (!Write(kFolderAttributeEnd)) { | 263 } else if (!Write(kFolderAttributeEnd)) { |
264 return false; | 264 return false; |
265 } | 265 } |
266 if (!Write(title, CONTENT) || | 266 if (!Write(title, CONTENT) || |
267 !Write(kFolderEnd) || | 267 !Write(kFolderEnd) || |
268 !Write(kNewline) || | 268 !Write(kNewline) || |
269 !WriteIndent() || | 269 !WriteIndent() || |
270 !Write(kFolderChildren) || | 270 !Write(kFolderChildren) || |
271 !Write(kNewline)) { | 271 !Write(kNewline)) { |
272 return false; | 272 return false; |
273 } | 273 } |
274 IncrementIndent(); | 274 IncrementIndent(); |
275 } | 275 } |
276 | 276 |
277 // Write the children. | 277 // Write the children. |
278 ListValue* children = static_cast<ListValue*>(child_values); | 278 ListValue* children = static_cast<ListValue*>(child_values); |
279 for (size_t i = 0; i < children->GetSize(); ++i) { | 279 for (size_t i = 0; i < children->GetSize(); ++i) { |
280 Value* child_value; | 280 Value* child_value; |
281 if (!children->Get(i, &child_value) || | 281 if (!children->Get(i, &child_value) || |
282 child_value->GetType() != Value::TYPE_DICTIONARY) { | 282 child_value->GetType() != Value::TYPE_DICTIONARY) { |
283 NOTREACHED(); | 283 NOTREACHED(); |
284 return false; | 284 return false; |
285 } | 285 } |
286 if (!WriteNode(*static_cast<DictionaryValue*>(child_value), | 286 if (!WriteNode(*static_cast<DictionaryValue*>(child_value), |
287 history::StarredEntry::USER_GROUP)) { | 287 BookmarkNode::FOLDER)) { |
288 return false; | 288 return false; |
289 } | 289 } |
290 } | 290 } |
291 if (folder_type != history::StarredEntry::OTHER) { | 291 if (folder_type != BookmarkNode::OTHER_NODE) { |
292 // Close out the folder. | 292 // Close out the folder. |
293 DecrementIndent(); | 293 DecrementIndent(); |
294 if (!WriteIndent() || | 294 if (!WriteIndent() || |
295 !Write(kFolderChildrenEnd) || | 295 !Write(kFolderChildrenEnd) || |
296 !Write(kNewline)) { | 296 !Write(kNewline)) { |
297 return false; | 297 return false; |
298 } | 298 } |
299 } | 299 } |
300 return true; | 300 return true; |
301 } | 301 } |
(...skipping 24 matching lines...) Expand all Loading... |
326 BookmarkCodec codec; | 326 BookmarkCodec codec; |
327 scoped_ptr<Writer> writer(new Writer(codec.Encode(model), | 327 scoped_ptr<Writer> writer(new Writer(codec.Encode(model), |
328 FilePath::FromWStringHack(path))); | 328 FilePath::FromWStringHack(path))); |
329 if (thread) | 329 if (thread) |
330 thread->PostTask(FROM_HERE, writer.release()); | 330 thread->PostTask(FROM_HERE, writer.release()); |
331 else | 331 else |
332 writer->Run(); | 332 writer->Run(); |
333 } | 333 } |
334 | 334 |
335 } // namespace bookmark_html_writer | 335 } // namespace bookmark_html_writer |
OLD | NEW |