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/session_model_associator.h" | 5 #include "chrome/browser/sync/glue/session_model_associator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 553 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
554 tab_link->url(), history::FAVICON, &load_consumer_, | 554 tab_link->url(), history::FAVICON, &load_consumer_, |
555 base::Bind(&SessionModelAssociator::OnFaviconDataAvailable, | 555 base::Bind(&SessionModelAssociator::OnFaviconDataAvailable, |
556 AsWeakPtr())); | 556 AsWeakPtr())); |
557 load_consumer_.SetClientData(favicon_service, handle, tab_id); | 557 load_consumer_.SetClientData(favicon_service, handle, tab_id); |
558 tab_link->set_favicon_load_handle(handle); | 558 tab_link->set_favicon_load_handle(handle); |
559 } | 559 } |
560 | 560 |
561 void SessionModelAssociator::OnFaviconDataAvailable( | 561 void SessionModelAssociator::OnFaviconDataAvailable( |
562 FaviconService::Handle handle, | 562 FaviconService::Handle handle, |
563 history::FaviconData favicon) { | 563 history::FaviconData favicon_data, |
| 564 std::vector<GURL> icon_urls_in_db) { |
564 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 565 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
565 if (!command_line.HasSwitch(switches::kSyncTabFavicons)) | 566 if (!command_line.HasSwitch(switches::kSyncTabFavicons)) |
566 return; | 567 return; |
567 SessionID::id_type tab_id = | 568 SessionID::id_type tab_id = |
568 load_consumer_.GetClientData( | 569 load_consumer_.GetClientData( |
569 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), handle); | 570 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), handle); |
570 TabLinksMap::iterator iter = tab_map_.find(tab_id); | 571 TabLinksMap::iterator iter = tab_map_.find(tab_id); |
571 if (iter == tab_map_.end()) { | 572 if (iter == tab_map_.end()) { |
572 DVLOG(1) << "Ignoring favicon for closed tab " << tab_id; | 573 DVLOG(1) << "Ignoring favicon for closed tab " << tab_id; |
573 return; | 574 return; |
574 } | 575 } |
575 TabLink* tab_link = iter->second.get(); | 576 TabLink* tab_link = iter->second.get(); |
576 DCHECK(tab_link); | 577 DCHECK(tab_link); |
577 DCHECK(tab_link->url().is_valid()); | 578 DCHECK(tab_link->url().is_valid()); |
578 // The tab_link holds the current url. Because this load request would have | 579 // The tab_link holds the current url. Because this load request would have |
579 // been canceled if the url had changed, we know the url must still be | 580 // been canceled if the url had changed, we know the url must still be |
580 // up to date. | 581 // up to date. |
581 | 582 |
582 if (favicon.is_valid()) { | 583 if (favicon_data.has_valid_bitmaps()) { |
583 DCHECK_EQ(handle, tab_link->favicon_load_handle()); | 584 DCHECK_EQ(handle, tab_link->favicon_load_handle()); |
584 tab_link->set_favicon_load_handle(0); | 585 tab_link->set_favicon_load_handle(0); |
585 DCHECK_EQ(favicon.icon_type, history::FAVICON); | 586 DCHECK_EQ(favicon_data.icon_type, history::FAVICON); |
586 DCHECK_NE(tab_link->sync_id(), syncer::kInvalidId); | 587 DCHECK_NE(tab_link->sync_id(), syncer::kInvalidId); |
587 // Load the sync tab node and update the favicon data. | 588 // Load the sync tab node and update the favicon data. |
588 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 589 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
589 syncer::WriteNode tab_node(&trans); | 590 syncer::WriteNode tab_node(&trans); |
590 if (tab_node.InitByIdLookup(tab_link->sync_id()) != | 591 if (tab_node.InitByIdLookup(tab_link->sync_id()) != |
591 syncer::BaseNode::INIT_OK) { | 592 syncer::BaseNode::INIT_OK) { |
592 LOG(WARNING) << "Failed to load sync tab node for tab id " << tab_id | 593 LOG(WARNING) << "Failed to load sync tab node for tab id " << tab_id |
593 << " and url " << tab_link->url().spec(); | 594 << " and url " << tab_link->url().spec(); |
594 return; | 595 return; |
595 } | 596 } |
596 sync_pb::SessionSpecifics session_specifics = | 597 sync_pb::SessionSpecifics session_specifics = |
597 tab_node.GetSessionSpecifics(); | 598 tab_node.GetSessionSpecifics(); |
598 DCHECK(session_specifics.has_tab()); | 599 DCHECK(session_specifics.has_tab()); |
599 sync_pb::SessionTab* tab = session_specifics.mutable_tab(); | 600 sync_pb::SessionTab* tab = session_specifics.mutable_tab(); |
600 if (favicon.image_data->size() > 0) { | 601 scoped_refptr<base::RefCountedMemory> bitmap_data( |
| 602 favicon_data.first_bitmap()); |
| 603 if (bitmap_data->size() > 0) { |
601 DVLOG(1) << "Storing session favicon for " | 604 DVLOG(1) << "Storing session favicon for " |
602 << tab_link->url() << " with size " | 605 << tab_link->url() << " with size " |
603 << favicon.image_data->size() << " bytes."; | 606 << bitmap_data->size() << " bytes."; |
604 tab->set_favicon(favicon.image_data->front(), | 607 tab->set_favicon(bitmap_data->front(), |
605 favicon.image_data->size()); | 608 bitmap_data->size()); |
606 tab->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); | 609 tab->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); |
607 tab->set_favicon_source(favicon.icon_url.spec()); | 610 tab->set_favicon_source(favicon_data.icon_url.spec()); |
608 } else { | 611 } else { |
609 LOG(WARNING) << "Null favicon stored for url " << tab_link->url().spec(); | 612 LOG(WARNING) << "Null favicon stored for url " << tab_link->url().spec(); |
610 } | 613 } |
611 tab_node.SetSessionSpecifics(session_specifics); | 614 tab_node.SetSessionSpecifics(session_specifics); |
612 } else { | 615 } else { |
613 // Else the favicon either isn't loaded yet or there is no favicon. We | 616 // Else the favicon either isn't loaded yet or there is no favicon. We |
614 // deliberately don't clear the tab_link's favicon_load_handle so we know | 617 // deliberately don't clear the tab_link's favicon_load_handle so we know |
615 // that we're still waiting for a favicon. ReceivedFavicons(..) below will | 618 // that we're still waiting for a favicon. ReceivedFavicons(..) below will |
616 // trigger another favicon load once/if the favicon for the current url | 619 // trigger another favicon load once/if the favicon for the current url |
617 // becomes available. | 620 // becomes available. |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1596 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
1594 // We only access the cryptographer while holding a transaction. | 1597 // We only access the cryptographer while holding a transaction. |
1595 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1598 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1596 const syncer::ModelTypeSet encrypted_types = | 1599 const syncer::ModelTypeSet encrypted_types = |
1597 syncer::GetEncryptedTypes(&trans); | 1600 syncer::GetEncryptedTypes(&trans); |
1598 return !encrypted_types.Has(SESSIONS) || | 1601 return !encrypted_types.Has(SESSIONS) || |
1599 sync_service_->IsCryptographerReady(&trans); | 1602 sync_service_->IsCryptographerReady(&trans); |
1600 } | 1603 } |
1601 | 1604 |
1602 } // namespace browser_sync | 1605 } // namespace browser_sync |
OLD | NEW |