| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 16 #include "chrome/browser/history/history.h" | 17 #include "chrome/browser/history/history.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/sessions/session_id.h" | 20 #include "chrome/browser/sessions/session_id.h" |
| 20 #include "chrome/browser/sync/glue/synced_session.h" | 21 #include "chrome/browser/sync/glue/synced_session.h" |
| 21 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 22 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
| 22 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 23 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
| 23 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
| 24 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 PopulateSessionTabFromSpecifics(*sync_tab, | 535 PopulateSessionTabFromSpecifics(*sync_tab, |
| 535 base::Time::Now(), | 536 base::Time::Now(), |
| 536 prev_tab); | 537 prev_tab); |
| 537 } | 538 } |
| 538 | 539 |
| 539 void SessionModelAssociator::LoadFaviconForTab(TabLink* tab_link) { | 540 void SessionModelAssociator::LoadFaviconForTab(TabLink* tab_link) { |
| 540 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 541 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 541 if (!command_line.HasSwitch(switches::kSyncTabFavicons)) | 542 if (!command_line.HasSwitch(switches::kSyncTabFavicons)) |
| 542 return; | 543 return; |
| 543 FaviconService* favicon_service = | 544 FaviconService* favicon_service = |
| 544 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 545 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 545 if (!favicon_service) | 546 if (!favicon_service) |
| 546 return; | 547 return; |
| 547 SessionID::id_type tab_id = tab_link->tab()->GetSessionId(); | 548 SessionID::id_type tab_id = tab_link->tab()->GetSessionId(); |
| 548 if (tab_link->favicon_load_handle()) { | 549 if (tab_link->favicon_load_handle()) { |
| 549 // We have an outstanding favicon load for this tab. Cancel it. | 550 // We have an outstanding favicon load for this tab. Cancel it. |
| 550 load_consumer_.CancelAllRequestsForClientData(tab_id); | 551 load_consumer_.CancelAllRequestsForClientData(tab_id); |
| 551 } | 552 } |
| 552 DVLOG(1) << "Triggering favicon load for url " << tab_link->url().spec(); | 553 DVLOG(1) << "Triggering favicon load for url " << tab_link->url().spec(); |
| 553 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 554 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
| 554 tab_link->url(), history::FAVICON, &load_consumer_, | 555 profile_, tab_link->url(), history::FAVICON, &load_consumer_, |
| 555 base::Bind(&SessionModelAssociator::OnFaviconDataAvailable, | 556 base::Bind(&SessionModelAssociator::OnFaviconDataAvailable, |
| 556 AsWeakPtr())); | 557 AsWeakPtr())); |
| 557 load_consumer_.SetClientData(favicon_service, handle, tab_id); | 558 load_consumer_.SetClientData(favicon_service, handle, tab_id); |
| 558 tab_link->set_favicon_load_handle(handle); | 559 tab_link->set_favicon_load_handle(handle); |
| 559 } | 560 } |
| 560 | 561 |
| 561 void SessionModelAssociator::OnFaviconDataAvailable( | 562 void SessionModelAssociator::OnFaviconDataAvailable( |
| 562 FaviconService::Handle handle, | 563 FaviconService::Handle handle, |
| 563 history::FaviconData favicon) { | 564 history::FaviconData favicon) { |
| 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 FaviconServiceFactory::GetForProfile( |
| 571 profile_, Profile::EXPLICIT_ACCESS), handle); |
| 570 TabLinksMap::iterator iter = tab_map_.find(tab_id); | 572 TabLinksMap::iterator iter = tab_map_.find(tab_id); |
| 571 if (iter == tab_map_.end()) { | 573 if (iter == tab_map_.end()) { |
| 572 DVLOG(1) << "Ignoring favicon for closed tab " << tab_id; | 574 DVLOG(1) << "Ignoring favicon for closed tab " << tab_id; |
| 573 return; | 575 return; |
| 574 } | 576 } |
| 575 TabLink* tab_link = iter->second.get(); | 577 TabLink* tab_link = iter->second.get(); |
| 576 DCHECK(tab_link); | 578 DCHECK(tab_link); |
| 577 DCHECK(tab_link->url().is_valid()); | 579 DCHECK(tab_link->url().is_valid()); |
| 578 // The tab_link holds the current url. Because this load request would have | 580 // 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 | 581 // been canceled if the url had changed, we know the url must still be |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1593 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1595 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
| 1594 // We only access the cryptographer while holding a transaction. | 1596 // We only access the cryptographer while holding a transaction. |
| 1595 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1597 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1596 const syncer::ModelTypeSet encrypted_types = | 1598 const syncer::ModelTypeSet encrypted_types = |
| 1597 syncer::GetEncryptedTypes(&trans); | 1599 syncer::GetEncryptedTypes(&trans); |
| 1598 return !encrypted_types.Has(SESSIONS) || | 1600 return !encrypted_types.Has(SESSIONS) || |
| 1599 sync_service_->IsCryptographerReady(&trans); | 1601 sync_service_->IsCryptographerReady(&trans); |
| 1600 } | 1602 } |
| 1601 | 1603 |
| 1602 } // namespace browser_sync | 1604 } // namespace browser_sync |
| OLD | NEW |