| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 !static_cast<DictionaryValue*>(bookmarks_.get())->Get( | 107 !static_cast<DictionaryValue*>(bookmarks_.get())->Get( |
| 108 BookmarkCodec::kRootsKey, &roots) || | 108 BookmarkCodec::kRootsKey, &roots) || |
| 109 roots->GetType() != Value::TYPE_DICTIONARY) { | 109 roots->GetType() != Value::TYPE_DICTIONARY) { |
| 110 NOTREACHED(); | 110 NOTREACHED(); |
| 111 return; | 111 return; |
| 112 } | 112 } |
| 113 | 113 |
| 114 DictionaryValue* roots_d_value = static_cast<DictionaryValue*>(roots); | 114 DictionaryValue* roots_d_value = static_cast<DictionaryValue*>(roots); |
| 115 Value* root_folder_value; | 115 Value* root_folder_value; |
| 116 Value* other_folder_value; | 116 Value* other_folder_value; |
| 117 Value* synced_folder_value; | 117 Value* mobile_folder_value; |
| 118 if (!roots_d_value->Get(BookmarkCodec::kRootFolderNameKey, | 118 if (!roots_d_value->Get(BookmarkCodec::kRootFolderNameKey, |
| 119 &root_folder_value) || | 119 &root_folder_value) || |
| 120 root_folder_value->GetType() != Value::TYPE_DICTIONARY || | 120 root_folder_value->GetType() != Value::TYPE_DICTIONARY || |
| 121 !roots_d_value->Get(BookmarkCodec::kOtherBookmarkFolderNameKey, | 121 !roots_d_value->Get(BookmarkCodec::kOtherBookmarkFolderNameKey, |
| 122 &other_folder_value) || | 122 &other_folder_value) || |
| 123 other_folder_value->GetType() != Value::TYPE_DICTIONARY || | 123 other_folder_value->GetType() != Value::TYPE_DICTIONARY || |
| 124 !roots_d_value->Get(BookmarkCodec::kSyncedBookmarkFolderNameKey, | 124 !roots_d_value->Get(BookmarkCodec::kMobileBookmarkFolderNameKey, |
| 125 &synced_folder_value) || | 125 &mobile_folder_value) || |
| 126 synced_folder_value->GetType() != Value::TYPE_DICTIONARY) { | 126 mobile_folder_value->GetType() != Value::TYPE_DICTIONARY) { |
| 127 NOTREACHED(); | 127 NOTREACHED(); |
| 128 return; // Invalid type for root folder and/or other folder. | 128 return; // Invalid type for root folder and/or other folder. |
| 129 } | 129 } |
| 130 | 130 |
| 131 IncrementIndent(); | 131 IncrementIndent(); |
| 132 | 132 |
| 133 if (!WriteNode(*static_cast<DictionaryValue*>(root_folder_value), | 133 if (!WriteNode(*static_cast<DictionaryValue*>(root_folder_value), |
| 134 BookmarkNode::BOOKMARK_BAR) || | 134 BookmarkNode::BOOKMARK_BAR) || |
| 135 !WriteNode(*static_cast<DictionaryValue*>(other_folder_value), | 135 !WriteNode(*static_cast<DictionaryValue*>(other_folder_value), |
| 136 BookmarkNode::OTHER_NODE) || | 136 BookmarkNode::OTHER_NODE) || |
| 137 !WriteNode(*static_cast<DictionaryValue*>(synced_folder_value), | 137 !WriteNode(*static_cast<DictionaryValue*>(mobile_folder_value), |
| 138 BookmarkNode::SYNCED)) { | 138 BookmarkNode::MOBILE)) { |
| 139 return; | 139 return; |
| 140 } | 140 } |
| 141 | 141 |
| 142 DecrementIndent(); | 142 DecrementIndent(); |
| 143 | 143 |
| 144 Write(kFolderChildrenEnd); | 144 Write(kFolderChildrenEnd); |
| 145 Write(kNewline); | 145 Write(kNewline); |
| 146 // File stream close is forced so that unit test could read it. | 146 // File stream close is forced so that unit test could read it. |
| 147 file_stream_.Close(); | 147 file_stream_.Close(); |
| 148 | 148 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 std::string last_modified_date; | 289 std::string last_modified_date; |
| 290 Value* child_values; | 290 Value* child_values; |
| 291 if (!value.GetString(BookmarkCodec::kDateModifiedKey, | 291 if (!value.GetString(BookmarkCodec::kDateModifiedKey, |
| 292 &last_modified_date) || | 292 &last_modified_date) || |
| 293 !value.Get(BookmarkCodec::kChildrenKey, &child_values) || | 293 !value.Get(BookmarkCodec::kChildrenKey, &child_values) || |
| 294 child_values->GetType() != Value::TYPE_LIST) { | 294 child_values->GetType() != Value::TYPE_LIST) { |
| 295 NOTREACHED(); | 295 NOTREACHED(); |
| 296 return false; | 296 return false; |
| 297 } | 297 } |
| 298 if (folder_type != BookmarkNode::OTHER_NODE && | 298 if (folder_type != BookmarkNode::OTHER_NODE && |
| 299 folder_type != BookmarkNode::SYNCED) { | 299 folder_type != BookmarkNode::MOBILE) { |
| 300 // The other/synced folder name are not written out. This gives the effect | 300 // The other/mobile folder name are not written out. This gives the effect |
| 301 // of making the contents of the 'other folder' be a sibling to the | 301 // of making the contents of the 'other folder' be a sibling to the |
| 302 // bookmark bar folder. | 302 // bookmark bar folder. |
| 303 if (!WriteIndent() || | 303 if (!WriteIndent() || |
| 304 !Write(kFolderStart) || | 304 !Write(kFolderStart) || |
| 305 !WriteTime(date_added_string) || | 305 !WriteTime(date_added_string) || |
| 306 !Write(kLastModified) || | 306 !Write(kLastModified) || |
| 307 !WriteTime(last_modified_date)) { | 307 !WriteTime(last_modified_date)) { |
| 308 return false; | 308 return false; |
| 309 } | 309 } |
| 310 if (folder_type == BookmarkNode::BOOKMARK_BAR) { | 310 if (folder_type == BookmarkNode::BOOKMARK_BAR) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 333 child_value->GetType() != Value::TYPE_DICTIONARY) { | 333 child_value->GetType() != Value::TYPE_DICTIONARY) { |
| 334 NOTREACHED(); | 334 NOTREACHED(); |
| 335 return false; | 335 return false; |
| 336 } | 336 } |
| 337 if (!WriteNode(*static_cast<DictionaryValue*>(child_value), | 337 if (!WriteNode(*static_cast<DictionaryValue*>(child_value), |
| 338 BookmarkNode::FOLDER)) { | 338 BookmarkNode::FOLDER)) { |
| 339 return false; | 339 return false; |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 if (folder_type != BookmarkNode::OTHER_NODE && | 342 if (folder_type != BookmarkNode::OTHER_NODE && |
| 343 folder_type != BookmarkNode::SYNCED) { | 343 folder_type != BookmarkNode::MOBILE) { |
| 344 // Close out the folder. | 344 // Close out the folder. |
| 345 DecrementIndent(); | 345 DecrementIndent(); |
| 346 if (!WriteIndent() || | 346 if (!WriteIndent() || |
| 347 !Write(kFolderChildrenEnd) || | 347 !Write(kFolderChildrenEnd) || |
| 348 !Write(kNewline)) { | 348 !Write(kNewline)) { |
| 349 return false; | 349 return false; |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 return true; | 352 return true; |
| 353 } | 353 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 chrome::NOTIFICATION_PROFILE_DESTROYED, | 389 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 390 content::Source<Profile>(profile_)); | 390 content::Source<Profile>(profile_)); |
| 391 } | 391 } |
| 392 | 392 |
| 393 BookmarkFaviconFetcher::~BookmarkFaviconFetcher() { | 393 BookmarkFaviconFetcher::~BookmarkFaviconFetcher() { |
| 394 } | 394 } |
| 395 | 395 |
| 396 void BookmarkFaviconFetcher::ExportBookmarks() { | 396 void BookmarkFaviconFetcher::ExportBookmarks() { |
| 397 ExtractUrls(profile_->GetBookmarkModel()->bookmark_bar_node()); | 397 ExtractUrls(profile_->GetBookmarkModel()->bookmark_bar_node()); |
| 398 ExtractUrls(profile_->GetBookmarkModel()->other_node()); | 398 ExtractUrls(profile_->GetBookmarkModel()->other_node()); |
| 399 ExtractUrls(profile_->GetBookmarkModel()->synced_node()); | 399 ExtractUrls(profile_->GetBookmarkModel()->mobile_node()); |
| 400 if (!bookmark_urls_.empty()) | 400 if (!bookmark_urls_.empty()) |
| 401 FetchNextFavicon(); | 401 FetchNextFavicon(); |
| 402 else | 402 else |
| 403 ExecuteWriter(); | 403 ExecuteWriter(); |
| 404 } | 404 } |
| 405 | 405 |
| 406 void BookmarkFaviconFetcher::Observe( | 406 void BookmarkFaviconFetcher::Observe( |
| 407 int type, | 407 int type, |
| 408 const content::NotificationSource& source, | 408 const content::NotificationSource& source, |
| 409 const content::NotificationDetails& details) { | 409 const content::NotificationDetails& details) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 // BookmarkModel isn't thread safe (nor would we want to lock it down | 489 // BookmarkModel isn't thread safe (nor would we want to lock it down |
| 490 // for the duration of the write), as such we make a copy of the | 490 // for the duration of the write), as such we make a copy of the |
| 491 // BookmarkModel using BookmarkCodec then write from that. | 491 // BookmarkModel using BookmarkCodec then write from that. |
| 492 if (fetcher == NULL) { | 492 if (fetcher == NULL) { |
| 493 fetcher = new BookmarkFaviconFetcher(profile, path, observer); | 493 fetcher = new BookmarkFaviconFetcher(profile, path, observer); |
| 494 fetcher->ExportBookmarks(); | 494 fetcher->ExportBookmarks(); |
| 495 } | 495 } |
| 496 } | 496 } |
| 497 | 497 |
| 498 } // namespace bookmark_html_writer | 498 } // namespace bookmark_html_writer |
| OLD | NEW |