| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync/glue/bookmark_change_processor.h" | 5 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
| 6 | 6 |
| 7 #include <stack> | 7 #include <stack> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 void BookmarkChangeProcessor::StartImpl(Profile* profile) { | 53 void BookmarkChangeProcessor::StartImpl(Profile* profile) { |
| 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 55 DCHECK(!bookmark_model_); | 55 DCHECK(!bookmark_model_); |
| 56 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile); | 56 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile); |
| 57 DCHECK(bookmark_model_->IsLoaded()); | 57 DCHECK(bookmark_model_->IsLoaded()); |
| 58 bookmark_model_->AddObserver(this); | 58 bookmark_model_->AddObserver(this); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void BookmarkChangeProcessor::UpdateSyncNodeProperties( | 61 void BookmarkChangeProcessor::UpdateSyncNodeProperties( |
| 62 const BookmarkNode* src, BookmarkModel* model, syncer::WriteNode* dst) { | 62 const BookmarkNode* src, |
| 63 BookmarkModel* model, |
| 64 syncer::WriteNode* dst) { |
| 63 // Set the properties of the item. | 65 // Set the properties of the item. |
| 64 dst->SetIsFolder(src->is_folder()); | 66 dst->SetIsFolder(src->is_folder()); |
| 65 dst->SetTitle(UTF16ToWideHack(src->GetTitle())); | 67 dst->SetTitle(UTF16ToWideHack(src->GetTitle())); |
| 68 sync_pb::BookmarkSpecifics bookmark_specifics(dst->GetBookmarkSpecifics()); |
| 66 if (!src->is_folder()) | 69 if (!src->is_folder()) |
| 67 dst->SetURL(src->url()); | 70 bookmark_specifics.set_url(src->url().spec()); |
| 71 bookmark_specifics.set_creation_time_us(src->date_added().ToInternalValue()); |
| 72 dst->SetBookmarkSpecifics(bookmark_specifics); |
| 68 SetSyncNodeFavicon(src, model, dst); | 73 SetSyncNodeFavicon(src, model, dst); |
| 69 } | 74 } |
| 70 | 75 |
| 71 // static | 76 // static |
| 72 void BookmarkChangeProcessor::EncodeFavicon(const BookmarkNode* src, | 77 void BookmarkChangeProcessor::EncodeFavicon(const BookmarkNode* src, |
| 73 BookmarkModel* model, | 78 BookmarkModel* model, |
| 74 std::vector<unsigned char>* dst) { | 79 std::vector<unsigned char>* dst) { |
| 75 const gfx::Image& favicon = model->GetFavicon(src); | 80 const gfx::Image& favicon = model->GetFavicon(src); |
| 76 | 81 |
| 77 dst->clear(); | 82 dst->clear(); |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 BookmarkModel* model, | 585 BookmarkModel* model, |
| 581 int index) { | 586 int index) { |
| 582 DCHECK(parent); | 587 DCHECK(parent); |
| 583 DCHECK(index >= 0 && index <= parent->child_count()); | 588 DCHECK(index >= 0 && index <= parent->child_count()); |
| 584 | 589 |
| 585 const BookmarkNode* node; | 590 const BookmarkNode* node; |
| 586 if (sync_node->GetIsFolder()) { | 591 if (sync_node->GetIsFolder()) { |
| 587 node = model->AddFolder(parent, index, | 592 node = model->AddFolder(parent, index, |
| 588 UTF8ToUTF16(sync_node->GetTitle())); | 593 UTF8ToUTF16(sync_node->GetTitle())); |
| 589 } else { | 594 } else { |
| 590 node = model->AddURL(parent, index, | 595 // 'creation_time_us' was added in m24. Assume a time of 0 means now. |
| 591 UTF8ToUTF16(sync_node->GetTitle()), | 596 const int64 create_time_internal = |
| 592 sync_node->GetURL()); | 597 sync_node->GetBookmarkSpecifics().creation_time_us(); |
| 598 base::Time create_time = (create_time_internal == 0) ? |
| 599 base::Time::Now() : base::Time::FromInternalValue(create_time_internal); |
| 600 node = model->AddURLWithCreationTime(parent, index, |
| 601 UTF8ToUTF16(sync_node->GetTitle()), |
| 602 sync_node->GetURL(), create_time); |
| 593 if (node) | 603 if (node) |
| 594 SetBookmarkFavicon(sync_node, node, model); | 604 SetBookmarkFavicon(sync_node, node, model); |
| 595 } | 605 } |
| 596 return node; | 606 return node; |
| 597 } | 607 } |
| 598 | 608 |
| 599 // static | 609 // static |
| 600 // Sets the favicon of the given bookmark node from the given sync node. | 610 // Sets the favicon of the given bookmark node from the given sync node. |
| 601 bool BookmarkChangeProcessor::SetBookmarkFavicon( | 611 bool BookmarkChangeProcessor::SetBookmarkFavicon( |
| 602 syncer::BaseNode* sync_node, | 612 syncer::BaseNode* sync_node, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 const BookmarkNode* bookmark_node, | 654 const BookmarkNode* bookmark_node, |
| 645 BookmarkModel* model, | 655 BookmarkModel* model, |
| 646 syncer::WriteNode* sync_node) { | 656 syncer::WriteNode* sync_node) { |
| 647 std::vector<unsigned char> favicon_bytes; | 657 std::vector<unsigned char> favicon_bytes; |
| 648 EncodeFavicon(bookmark_node, model, &favicon_bytes); | 658 EncodeFavicon(bookmark_node, model, &favicon_bytes); |
| 649 if (!favicon_bytes.empty()) | 659 if (!favicon_bytes.empty()) |
| 650 sync_node->SetFaviconBytes(favicon_bytes); | 660 sync_node->SetFaviconBytes(favicon_bytes); |
| 651 } | 661 } |
| 652 | 662 |
| 653 } // namespace browser_sync | 663 } // namespace browser_sync |
| OLD | NEW |