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