Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/bookmarks/bookmark_html_writer.cc

Issue 7012005: Revert "Revert 84829 - Initial implementation of "Synced Bookmarks" folder." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Trying to set .json eol-style Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/callback.h" 8 #include "base/callback.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (!roots_d_value->Get(BookmarkCodec::kRootFolderNameKey, 118 if (!roots_d_value->Get(BookmarkCodec::kRootFolderNameKey,
118 &root_folder_value) || 119 &root_folder_value) ||
119 root_folder_value->GetType() != Value::TYPE_DICTIONARY || 120 root_folder_value->GetType() != Value::TYPE_DICTIONARY ||
120 !roots_d_value->Get(BookmarkCodec::kOtherBookmarkFolderNameKey, 121 !roots_d_value->Get(BookmarkCodec::kOtherBookmarkFolderNameKey,
121 &other_folder_value) || 122 &other_folder_value) ||
122 other_folder_value->GetType() != Value::TYPE_DICTIONARY) { 123 other_folder_value->GetType() != Value::TYPE_DICTIONARY ||
124 !roots_d_value->Get(BookmarkCodec::kSyncedBookmarkFolderNameKey,
125 &synced_folder_value) ||
126 synced_folder_value->GetType() != Value::TYPE_DICTIONARY) {
123 NOTREACHED(); 127 NOTREACHED();
124 return; // Invalid type for root folder and/or other folder. 128 return; // Invalid type for root folder and/or other folder.
125 } 129 }
126 130
127 IncrementIndent(); 131 IncrementIndent();
128 132
129 if (!WriteNode(*static_cast<DictionaryValue*>(root_folder_value), 133 if (!WriteNode(*static_cast<DictionaryValue*>(root_folder_value),
130 BookmarkNode::BOOKMARK_BAR) || 134 BookmarkNode::BOOKMARK_BAR) ||
131 !WriteNode(*static_cast<DictionaryValue*>(other_folder_value), 135 !WriteNode(*static_cast<DictionaryValue*>(other_folder_value),
132 BookmarkNode::OTHER_NODE)) { 136 BookmarkNode::OTHER_NODE) ||
137 !WriteNode(*static_cast<DictionaryValue*>(synced_folder_value),
138 BookmarkNode::SYNCED)) {
133 return; 139 return;
134 } 140 }
135 141
136 DecrementIndent(); 142 DecrementIndent();
137 143
138 Write(kFolderChildrenEnd); 144 Write(kFolderChildrenEnd);
139 Write(kNewline); 145 Write(kNewline);
140 // 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.
141 file_stream_.Close(); 147 file_stream_.Close();
142 } 148 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // Folder. 285 // Folder.
280 std::string last_modified_date; 286 std::string last_modified_date;
281 Value* child_values; 287 Value* child_values;
282 if (!value.GetString(BookmarkCodec::kDateModifiedKey, 288 if (!value.GetString(BookmarkCodec::kDateModifiedKey,
283 &last_modified_date) || 289 &last_modified_date) ||
284 !value.Get(BookmarkCodec::kChildrenKey, &child_values) || 290 !value.Get(BookmarkCodec::kChildrenKey, &child_values) ||
285 child_values->GetType() != Value::TYPE_LIST) { 291 child_values->GetType() != Value::TYPE_LIST) {
286 NOTREACHED(); 292 NOTREACHED();
287 return false; 293 return false;
288 } 294 }
289 if (folder_type != BookmarkNode::OTHER_NODE) { 295 if (folder_type != BookmarkNode::OTHER_NODE &&
290 // The other folder name is not written out. This gives the effect of 296 folder_type != BookmarkNode::SYNCED) {
291 // making the contents of the 'other folder' be a sibling to the bookmark 297 // The other/synced folder name are not written out. This gives the effect
292 // bar folder. 298 // of making the contents of the 'other folder' be a sibling to the
299 // bookmark bar folder.
293 if (!WriteIndent() || 300 if (!WriteIndent() ||
294 !Write(kFolderStart) || 301 !Write(kFolderStart) ||
295 !WriteTime(date_added_string) || 302 !WriteTime(date_added_string) ||
296 !Write(kLastModified) || 303 !Write(kLastModified) ||
297 !WriteTime(last_modified_date)) { 304 !WriteTime(last_modified_date)) {
298 return false; 305 return false;
299 } 306 }
300 if (folder_type == BookmarkNode::BOOKMARK_BAR) { 307 if (folder_type == BookmarkNode::BOOKMARK_BAR) {
301 if (!Write(kBookmarkBar)) 308 if (!Write(kBookmarkBar))
302 return false; 309 return false;
(...skipping 19 matching lines...) Expand all
322 if (!children->Get(i, &child_value) || 329 if (!children->Get(i, &child_value) ||
323 child_value->GetType() != Value::TYPE_DICTIONARY) { 330 child_value->GetType() != Value::TYPE_DICTIONARY) {
324 NOTREACHED(); 331 NOTREACHED();
325 return false; 332 return false;
326 } 333 }
327 if (!WriteNode(*static_cast<DictionaryValue*>(child_value), 334 if (!WriteNode(*static_cast<DictionaryValue*>(child_value),
328 BookmarkNode::FOLDER)) { 335 BookmarkNode::FOLDER)) {
329 return false; 336 return false;
330 } 337 }
331 } 338 }
332 if (folder_type != BookmarkNode::OTHER_NODE) { 339 if (folder_type != BookmarkNode::OTHER_NODE &&
340 folder_type != BookmarkNode::SYNCED) {
333 // Close out the folder. 341 // Close out the folder.
334 DecrementIndent(); 342 DecrementIndent();
335 if (!WriteIndent() || 343 if (!WriteIndent() ||
336 !Write(kFolderChildrenEnd) || 344 !Write(kFolderChildrenEnd) ||
337 !Write(kNewline)) { 345 !Write(kNewline)) {
338 return false; 346 return false;
339 } 347 }
340 } 348 }
341 return true; 349 return true;
342 } 350 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 NotificationType::PROFILE_DESTROYED, 384 NotificationType::PROFILE_DESTROYED,
377 Source<Profile>(profile_)); 385 Source<Profile>(profile_));
378 } 386 }
379 387
380 BookmarkFaviconFetcher::~BookmarkFaviconFetcher() { 388 BookmarkFaviconFetcher::~BookmarkFaviconFetcher() {
381 } 389 }
382 390
383 void BookmarkFaviconFetcher::ExportBookmarks() { 391 void BookmarkFaviconFetcher::ExportBookmarks() {
384 ExtractUrls(profile_->GetBookmarkModel()->GetBookmarkBarNode()); 392 ExtractUrls(profile_->GetBookmarkModel()->GetBookmarkBarNode());
385 ExtractUrls(profile_->GetBookmarkModel()->other_node()); 393 ExtractUrls(profile_->GetBookmarkModel()->other_node());
394 ExtractUrls(profile_->GetBookmarkModel()->synced_node());
386 if (!bookmark_urls_.empty()) { 395 if (!bookmark_urls_.empty()) {
387 FetchNextFavicon(); 396 FetchNextFavicon();
388 } else { 397 } else {
389 ExecuteWriter(); 398 ExecuteWriter();
390 } 399 }
391 } 400 }
392 401
393 void BookmarkFaviconFetcher::Observe(NotificationType type, 402 void BookmarkFaviconFetcher::Observe(NotificationType type,
394 const NotificationSource& source, 403 const NotificationSource& source,
395 const NotificationDetails& details) { 404 const NotificationDetails& details) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // BookmarkModel isn't thread safe (nor would we want to lock it down 485 // BookmarkModel isn't thread safe (nor would we want to lock it down
477 // for the duration of the write), as such we make a copy of the 486 // for the duration of the write), as such we make a copy of the
478 // BookmarkModel using BookmarkCodec then write from that. 487 // BookmarkModel using BookmarkCodec then write from that.
479 if (fetcher == NULL) { 488 if (fetcher == NULL) {
480 fetcher = new BookmarkFaviconFetcher(profile, path, observer); 489 fetcher = new BookmarkFaviconFetcher(profile, path, observer);
481 fetcher->ExportBookmarks(); 490 fetcher->ExportBookmarks();
482 } 491 }
483 } 492 }
484 493
485 } // namespace bookmark_html_writer 494 } // namespace bookmark_html_writer
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_codec_unittest.cc ('k') | chrome/browser/bookmarks/bookmark_html_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698