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

Side by Side Diff: chrome/browser/sync/glue/session_model_associator.cc

Issue 10870022: Change FaviconData to be able to return data for multiple bitmaps for same icon URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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) 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 24 matching lines...) Expand all
35 #include "sync/internal_api/public/read_node.h" 35 #include "sync/internal_api/public/read_node.h"
36 #include "sync/internal_api/public/read_transaction.h" 36 #include "sync/internal_api/public/read_transaction.h"
37 #include "sync/internal_api/public/write_node.h" 37 #include "sync/internal_api/public/write_node.h"
38 #include "sync/internal_api/public/write_transaction.h" 38 #include "sync/internal_api/public/write_transaction.h"
39 #include "sync/protocol/session_specifics.pb.h" 39 #include "sync/protocol/session_specifics.pb.h"
40 #include "sync/syncable/directory.h" 40 #include "sync/syncable/directory.h"
41 #include "sync/syncable/read_transaction.h" 41 #include "sync/syncable/read_transaction.h"
42 #include "sync/syncable/write_transaction.h" 42 #include "sync/syncable/write_transaction.h"
43 #include "sync/util/get_session_name.h" 43 #include "sync/util/get_session_name.h"
44 #include "sync/util/time.h" 44 #include "sync/util/time.h"
45 #include "ui/gfx/favicon_size.h"
45 #if defined(OS_LINUX) 46 #if defined(OS_LINUX)
46 #include "base/linux_util.h" 47 #include "base/linux_util.h"
47 #elif defined(OS_WIN) 48 #elif defined(OS_WIN)
48 #include <windows.h> 49 #include <windows.h>
49 #elif defined(OS_ANDROID) 50 #elif defined(OS_ANDROID)
50 #include "sync/util/session_utils_android.h" 51 #include "sync/util/session_utils_android.h"
51 #endif 52 #endif
52 53
53 using content::BrowserThread; 54 using content::BrowserThread;
54 using content::NavigationEntry; 55 using content::NavigationEntry;
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 FaviconService* favicon_service = 545 FaviconService* favicon_service =
545 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 546 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
546 if (!favicon_service) 547 if (!favicon_service)
547 return; 548 return;
548 SessionID::id_type tab_id = tab_link->tab()->GetSessionId(); 549 SessionID::id_type tab_id = tab_link->tab()->GetSessionId();
549 if (tab_link->favicon_load_handle()) { 550 if (tab_link->favicon_load_handle()) {
550 // We have an outstanding favicon load for this tab. Cancel it. 551 // We have an outstanding favicon load for this tab. Cancel it.
551 load_consumer_.CancelAllRequestsForClientData(tab_id); 552 load_consumer_.CancelAllRequestsForClientData(tab_id);
552 } 553 }
553 DVLOG(1) << "Triggering favicon load for url " << tab_link->url().spec(); 554 DVLOG(1) << "Triggering favicon load for url " << tab_link->url().spec();
554 FaviconService::Handle handle = favicon_service->GetFaviconForURL( 555 FaviconService::Handle handle = favicon_service->GetRawFaviconForURL(
555 profile_, tab_link->url(), history::FAVICON, &load_consumer_, 556 profile_, tab_link->url(), history::FAVICON, gfx::kFaviconSize,
557 ui::SCALE_FACTOR_100P, &load_consumer_,
556 base::Bind(&SessionModelAssociator::OnFaviconDataAvailable, 558 base::Bind(&SessionModelAssociator::OnFaviconDataAvailable,
557 AsWeakPtr())); 559 AsWeakPtr()));
558 load_consumer_.SetClientData(favicon_service, handle, tab_id); 560 load_consumer_.SetClientData(favicon_service, handle, tab_id);
559 tab_link->set_favicon_load_handle(handle); 561 tab_link->set_favicon_load_handle(handle);
560 } 562 }
561 563
562 void SessionModelAssociator::OnFaviconDataAvailable( 564 void SessionModelAssociator::OnFaviconDataAvailable(
563 FaviconService::Handle handle, 565 FaviconService::Handle handle,
564 history::FaviconData favicon) { 566 const history::FaviconBitmapResult& bitmap_result) {
565 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 567 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
566 if (!command_line.HasSwitch(switches::kSyncTabFavicons)) 568 if (!command_line.HasSwitch(switches::kSyncTabFavicons))
567 return; 569 return;
568 SessionID::id_type tab_id = 570 SessionID::id_type tab_id =
569 load_consumer_.GetClientData( 571 load_consumer_.GetClientData(
570 FaviconServiceFactory::GetForProfile( 572 FaviconServiceFactory::GetForProfile(
571 profile_, Profile::EXPLICIT_ACCESS), handle); 573 profile_, Profile::EXPLICIT_ACCESS), handle);
572 TabLinksMap::iterator iter = tab_map_.find(tab_id); 574 TabLinksMap::iterator iter = tab_map_.find(tab_id);
573 if (iter == tab_map_.end()) { 575 if (iter == tab_map_.end()) {
574 DVLOG(1) << "Ignoring favicon for closed tab " << tab_id; 576 DVLOG(1) << "Ignoring favicon for closed tab " << tab_id;
575 return; 577 return;
576 } 578 }
577 TabLink* tab_link = iter->second.get(); 579 TabLink* tab_link = iter->second.get();
578 DCHECK(tab_link); 580 DCHECK(tab_link);
579 DCHECK(tab_link->url().is_valid()); 581 DCHECK(tab_link->url().is_valid());
580 // The tab_link holds the current url. Because this load request would have 582 // The tab_link holds the current url. Because this load request would have
581 // been canceled if the url had changed, we know the url must still be 583 // been canceled if the url had changed, we know the url must still be
582 // up to date. 584 // up to date.
583 585
584 if (favicon.is_valid()) { 586 if (bitmap_result.is_valid()) {
585 DCHECK_EQ(handle, tab_link->favicon_load_handle()); 587 DCHECK_EQ(handle, tab_link->favicon_load_handle());
586 tab_link->set_favicon_load_handle(0); 588 tab_link->set_favicon_load_handle(0);
587 DCHECK_EQ(favicon.icon_type, history::FAVICON); 589 DCHECK_EQ(bitmap_result.icon_type, history::FAVICON);
588 DCHECK_NE(tab_link->sync_id(), syncer::kInvalidId); 590 DCHECK_NE(tab_link->sync_id(), syncer::kInvalidId);
589 // Load the sync tab node and update the favicon data. 591 // Load the sync tab node and update the favicon data.
590 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 592 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
591 syncer::WriteNode tab_node(&trans); 593 syncer::WriteNode tab_node(&trans);
592 if (tab_node.InitByIdLookup(tab_link->sync_id()) != 594 if (tab_node.InitByIdLookup(tab_link->sync_id()) !=
593 syncer::BaseNode::INIT_OK) { 595 syncer::BaseNode::INIT_OK) {
594 LOG(WARNING) << "Failed to load sync tab node for tab id " << tab_id 596 LOG(WARNING) << "Failed to load sync tab node for tab id " << tab_id
595 << " and url " << tab_link->url().spec(); 597 << " and url " << tab_link->url().spec();
596 return; 598 return;
597 } 599 }
598 sync_pb::SessionSpecifics session_specifics = 600 sync_pb::SessionSpecifics session_specifics =
599 tab_node.GetSessionSpecifics(); 601 tab_node.GetSessionSpecifics();
600 DCHECK(session_specifics.has_tab()); 602 DCHECK(session_specifics.has_tab());
601 sync_pb::SessionTab* tab = session_specifics.mutable_tab(); 603 sync_pb::SessionTab* tab = session_specifics.mutable_tab();
602 if (favicon.image_data->size() > 0) { 604 if (bitmap_result.bitmap_data->size() > 0) {
603 DVLOG(1) << "Storing session favicon for " 605 DVLOG(1) << "Storing session favicon for "
604 << tab_link->url() << " with size " 606 << tab_link->url() << " with size "
605 << favicon.image_data->size() << " bytes."; 607 << bitmap_result.bitmap_data->size() << " bytes.";
606 tab->set_favicon(favicon.image_data->front(), 608 tab->set_favicon(bitmap_result.bitmap_data->front(),
607 favicon.image_data->size()); 609 bitmap_result.bitmap_data->size());
608 tab->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON); 610 tab->set_favicon_type(sync_pb::SessionTab::TYPE_WEB_FAVICON);
609 tab->set_favicon_source(favicon.icon_url.spec()); 611 tab->set_favicon_source(bitmap_result.icon_url.spec());
610 } else { 612 } else {
611 LOG(WARNING) << "Null favicon stored for url " << tab_link->url().spec(); 613 LOG(WARNING) << "Null favicon stored for url " << tab_link->url().spec();
612 } 614 }
613 tab_node.SetSessionSpecifics(session_specifics); 615 tab_node.SetSessionSpecifics(session_specifics);
614 } else { 616 } else {
615 // Else the favicon either isn't loaded yet or there is no favicon. We 617 // Else the favicon either isn't loaded yet or there is no favicon. We
616 // deliberately don't clear the tab_link's favicon_load_handle so we know 618 // deliberately don't clear the tab_link's favicon_load_handle so we know
617 // that we're still waiting for a favicon. ReceivedFavicons(..) below will 619 // that we're still waiting for a favicon. ReceivedFavicons(..) below will
618 // trigger another favicon load once/if the favicon for the current url 620 // trigger another favicon load once/if the favicon for the current url
619 // becomes available. 621 // becomes available.
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 1596
1595 bool SessionModelAssociator::CryptoReadyIfNecessary() { 1597 bool SessionModelAssociator::CryptoReadyIfNecessary() {
1596 // We only access the cryptographer while holding a transaction. 1598 // We only access the cryptographer while holding a transaction.
1597 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 1599 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1598 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); 1600 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes();
1599 return !encrypted_types.Has(SESSIONS) || 1601 return !encrypted_types.Has(SESSIONS) ||
1600 sync_service_->IsCryptographerReady(&trans); 1602 sync_service_->IsCryptographerReady(&trans);
1601 } 1603 }
1602 1604
1603 } // namespace browser_sync 1605 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698