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

Side by Side Diff: chrome/browser/history/history_backend.h

Issue 10802066: Adds support for saving favicon size into history database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 #ifndef CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ 5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_
6 #define CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ 6 #define CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_
7 7
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // 241 //
242 // Exposed for testing reasons. 242 // Exposed for testing reasons.
243 void GetPageThumbnailDirectly( 243 void GetPageThumbnailDirectly(
244 const GURL& page_url, 244 const GURL& page_url,
245 scoped_refptr<base::RefCountedBytes>* data); 245 scoped_refptr<base::RefCountedBytes>* data);
246 246
247 void MigrateThumbnailsDatabase(); 247 void MigrateThumbnailsDatabase();
248 248
249 // Favicon ------------------------------------------------------------------- 249 // Favicon -------------------------------------------------------------------
250 250
251 void GetFavicon(scoped_refptr<GetFaviconRequest> request, 251 void GetFavicons(scoped_refptr<GetFaviconRequest> request,
252 const GURL& icon_url, 252 const std::vector<GURL>& icon_urls,
253 int icon_types); 253 int icon_types);
254 254
255 void GetFaviconForURL(scoped_refptr<GetFaviconRequest> request, 255 void GetFaviconsForURL(scoped_refptr<GetFaviconRequest> request,
256 const GURL& page_url, 256 const GURL& page_url,
257 int icon_types); 257 int icon_types);
258 258
259 void GetFaviconForID(scoped_refptr<GetFaviconRequest> request, FaviconID id); 259 void UpdateFaviconMappingsAndFetch(scoped_refptr<GetFaviconRequest> request,
260 const GURL& page_url,
261 const std::vector<GURL>& icon_urls,
262 IconType icon_type);
260 263
261 void SetFavicon(const GURL& page_url, 264 void AddFavicons(const GURL& page_url,
262 const GURL& icon_url, 265 IconType icon_type,
263 scoped_refptr<base::RefCountedMemory> data, 266 const std::vector<FaviconDataElement>& elements);
264 IconType icon_type);
265 267
266 void UpdateFaviconMappingAndFetch(scoped_refptr<GetFaviconRequest> request, 268 void SetFavicons(const GURL& page_url,
267 const GURL& page_url, 269 IconType icon_type,
268 const GURL& icon_url, 270 const std::vector<FaviconDataElement>& elements,
269 IconType icon_type); 271 const IconURLSizesMap& icon_url_sizes);
270 272
271 void SetFaviconOutOfDateForPage(const GURL& page_url); 273 void SetFaviconsOutOfDateForPage(const GURL& page_url);
272 274
273 void CloneFavicon(const GURL& old_page_url, const GURL& new_page_url); 275 void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url);
274 276
275 void SetImportedFavicons( 277 void SetImportedFavicons(
276 const std::vector<ImportedFaviconUsage>& favicon_usage); 278 const std::vector<ImportedFaviconUsage>& favicon_usage);
277 279
278 // Downloads ----------------------------------------------------------------- 280 // Downloads -----------------------------------------------------------------
279 281
280 void GetNextDownloadId(scoped_refptr<DownloadNextIdRequest> request); 282 void GetNextDownloadId(scoped_refptr<DownloadNextIdRequest> request);
281 void QueryDownloads(scoped_refptr<DownloadQueryRequest> request); 283 void QueryDownloads(scoped_refptr<DownloadQueryRequest> request);
282 void CleanUpInProgressEntries(); 284 void CleanUpInProgressEntries();
283 void UpdateDownload(const content::DownloadPersistentStoreInfo& data); 285 void UpdateDownload(const content::DownloadPersistentStoreInfo& data);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 #if defined(UNIT_TEST) 437 #if defined(UNIT_TEST)
436 HistoryDatabase* db() const { return db_.get(); } 438 HistoryDatabase* db() const { return db_.get(); }
437 439
438 ExpireHistoryBackend* expire_backend() { return &expirer_; } 440 ExpireHistoryBackend* expire_backend() { return &expirer_; }
439 #endif 441 #endif
440 442
441 // Returns true if the passed visit time is already expired (used by the sync 443 // Returns true if the passed visit time is already expired (used by the sync
442 // code to avoid syncing visits that would immediately be expired). 444 // code to avoid syncing visits that would immediately be expired).
443 virtual bool IsExpiredVisitTime(const base::Time& time); 445 virtual bool IsExpiredVisitTime(const base::Time& time);
444 446
447 // Set whether HistoryBackend::SetFavicon is cripled such that it can only be
448 // used to set favicon bitmaps of size 0 0 for a single URL.
449 // TODO(pkotwicz): Remove this restriction.
450 void set_single_favicon_bitmap_per_icon_type(
451 bool single_favicon_bitmap_per_icon_type) {
452 single_favicon_bitmap_per_icon_type_ = single_favicon_bitmap_per_icon_type;
453 }
454
445 protected: 455 protected:
446 virtual ~HistoryBackend(); 456 virtual ~HistoryBackend();
447 457
448 private: 458 private:
449 friend class base::RefCountedThreadSafe<HistoryBackend>; 459 friend class base::RefCountedThreadSafe<HistoryBackend>;
450 friend class CommitLaterTask; // The commit task needs to call Commit(). 460 friend class CommitLaterTask; // The commit task needs to call Commit().
451 friend class HistoryBackendTest; 461 friend class HistoryBackendTest;
452 friend class HistoryTest; // So the unit tests can poke our innards. 462 friend class HistoryTest; // So the unit tests can poke our innards.
453 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll); 463 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll);
454 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAllThenAddData); 464 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAllThenAddData);
455 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, ImportedFaviconsTest); 465 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, ImportedFaviconsTest);
456 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, URLsNoLongerBookmarked); 466 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, URLsNoLongerBookmarked);
457 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, StripUsernamePasswordTest); 467 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, StripUsernamePasswordTest);
458 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteThumbnailsDatabaseTest); 468 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteThumbnailsDatabaseTest);
459 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddPageVisitSource); 469 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddPageVisitSource);
460 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddPageArgsSource); 470 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddPageArgsSource);
461 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddVisitsSource); 471 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddVisitsSource);
462 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsSource); 472 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsSource);
463 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsTransitions); 473 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsTransitions);
464 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationVisitSource); 474 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationVisitSource);
465 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); 475 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping);
466 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconMapping); 476 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
467 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddOrUpdateIconMapping); 477 SetFaviconMappingsForPageAndRedirects);
478 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
479 SetFaviconMappingsForPageDuplicates);
480 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFavicons);
481 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsDeleteBitmaps);
482 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsReplaceBitmapData);
468 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetMostRecentVisits); 483 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetMostRecentVisits);
469 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconForURL); 484 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDB);
485 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBExpired);
486 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBIconType);
487 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBEmpty);
470 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, 488 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
471 CloneFaviconIsRestrictedToSameDomain); 489 CloneFaviconIsRestrictedToSameDomain);
472 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, QueryFilteredURLs); 490 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, QueryFilteredURLs);
473 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, UpdateVisitDuration); 491 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, UpdateVisitDuration);
474 492
475 friend class ::TestingProfile; 493 friend class ::TestingProfile;
476 494
477 // Computes the name of the specified database on disk. 495 // Computes the name of the specified database on disk.
478 FilePath GetThumbnailFileName() const; 496 FilePath GetThumbnailFileName() const;
479 497
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 // Update the segment information. This is called internally when a page is 589 // Update the segment information. This is called internally when a page is
572 // added. Return the segment id of the segment that has been updated. 590 // added. Return the segment id of the segment that has been updated.
573 SegmentID UpdateSegments(const GURL& url, 591 SegmentID UpdateSegments(const GURL& url,
574 VisitID from_visit, 592 VisitID from_visit,
575 VisitID visit_id, 593 VisitID visit_id,
576 content::PageTransition transition_type, 594 content::PageTransition transition_type,
577 const base::Time ts); 595 const base::Time ts);
578 596
579 // Favicons ------------------------------------------------------------------ 597 // Favicons ------------------------------------------------------------------
580 598
581 // Used by both UpdateFaviconMappingAndFetch and GetFavicon. 599 // Used by both UpdateFaviconMappingsAndFetch and GetFavicons.
582 // If page_url is non-null and SetFavicon has previously been invoked for 600 // If |page_url| is non-null, the icon urls for |page_url| (and all
583 // icon_url the favicon url for page_url (and all redirects) is set to 601 // redirects) are set to the subset of |icon_urls| for which icons are
584 // icon_url. 602 // already stored in the database.
585 // Only a single type can be given in icon_type when page_url is specified. 603 // Only a single type can be given in icon_type when page_url is specified.
586 void UpdateFaviconMappingAndFetchImpl( 604 void UpdateFaviconMappingsAndFetchImpl(
587 const GURL* page_url, 605 const GURL* page_url,
588 const GURL& icon_url, 606 const std::vector<GURL>& icon_urls,
589 scoped_refptr<GetFaviconRequest> request, 607 scoped_refptr<GetFaviconRequest> request,
590 int icon_type); 608 int icon_types);
591 609
592 // Sets the favicon url id for page_url to id. This will also broadcast 610 // Set the favicon bitmaps for the favicon at |icon_id|.
593 // notifications as necessary. 611 void SetFaviconBitmaps(FaviconID icon_id,
594 void SetFaviconMapping(const GURL& page_url, 612 const std::vector<FaviconDataElement>& elements);
595 FaviconID id,
596 IconType icon_type);
597 613
598 // Updates the FaviconID associated with the url of a page. If there is an 614 // Returns true if |elements| and |icon_url_sizes| passed to SetFavicons
599 // existing mapping between |page_url| and |id| this does nothing and returns 615 // are valid.
600 // false. If the mapping needs to be added or updated, true is returned. If 616 bool ValidateSetFaviconsParams(
601 // there is an existing mapping but it does not map to |id|, then the |id| of 617 const std::vector<FaviconDataElement>& elements,
602 // the replaced FaviconID is set in |replaced_icon_id|. 618 const IconURLSizesMap& icon_url_sizes) const;
603 bool AddOrUpdateIconMapping(const GURL& page_url, 619
604 FaviconID id, 620 // Sets the sizes that the thumbnail database knows that the favicon at
605 IconType icon_type, 621 // |icon_id| is available at from the web. See history_types for a more
606 FaviconID* replaced_icon_id); 622 // in depth discussion about FaviconSizes.
623 void SetFaviconSizes(FaviconID icon_id,
624 const FaviconSizes& sizes);
625
626 // If there are favicons for |page_url| and one of the types in
627 // |icon_types|, |favicon_data| is set appropriately and true is returned.
628 bool GetFaviconsFromDB(const GURL& page_url,
629 int icon_types,
630 FaviconData* favicon_data);
631
632 // Add data for the favicon at |favicon_id| to |favicon_data|.
633 // As FaviconData only contains FaviconDataElements for a single IconType,
634 // the IconType of the favicon at favicon_id must match that of previous
635 // |FaviconData::elements|.
636 // Returns true on success.
637 bool AddToFaviconData(FaviconID favicon_id,
sky 2012/08/21 20:16:56 Using 'Add' in the name makes it sound as though t
638 FaviconData* favicon_data);
639
640 // Define type used solely in SetFaviconMappingsForPageAndRedirects.
641 typedef std::map<GURL, FaviconID> IconURLFaviconIDMap;
642
643 // Maps the favicon ids in |icon_url_id_map| to |page_url| (and all
644 // redirects) for |icon_type|. This will also broadcast notifications as
645 // necessary.
646 void SetFaviconMappingsForPageAndRedirects(
647 const GURL& page_url,
648 const IconType icon_type,
649 const IconURLFaviconIDMap& icon_url_id_map);
650
651 // Maps the favicon ids in |icon_url_id_map| to |page_url| for |icon_type|.
652 bool SetFaviconMappingsForPage(const GURL& page_url,
653 IconType icon_type,
654 const IconURLFaviconIDMap& icon_url_id_map);
607 655
608 // Generic stuff ------------------------------------------------------------- 656 // Generic stuff -------------------------------------------------------------
609 657
610 // Processes the next scheduled HistoryDBTask, scheduling this method 658 // Processes the next scheduled HistoryDBTask, scheduling this method
611 // to be invoked again if there are more tasks that need to run. 659 // to be invoked again if there are more tasks that need to run.
612 void ProcessDBTaskImpl(); 660 void ProcessDBTaskImpl();
613 661
614 // Release all tasks in history_db_tasks_ and clears it. 662 // Release all tasks in history_db_tasks_ and clears it.
615 void ReleaseDBTasks(); 663 void ReleaseDBTasks();
616 664
(...skipping 23 matching lines...) Expand all
640 // set of URLs in the URL table (these should correspond to the bookmarked 688 // set of URLs in the URL table (these should correspond to the bookmarked
641 // URLs). 689 // URLs).
642 // 690 //
643 // The IDs of the URLs may change. 691 // The IDs of the URLs may change.
644 bool ClearAllMainHistory(const URLRows& kept_urls); 692 bool ClearAllMainHistory(const URLRows& kept_urls);
645 693
646 // Returns the BookmarkService, blocking until it is loaded. This may return 694 // Returns the BookmarkService, blocking until it is loaded. This may return
647 // NULL during testing. 695 // NULL during testing.
648 BookmarkService* GetBookmarkService(); 696 BookmarkService* GetBookmarkService();
649 697
650 // If there is a favicon for |page_url| and one of the types in |icon_types|,
651 // |favicon| is set appropriately and true is returned.
652 bool GetFaviconFromDB(const GURL& page_url,
653 int icon_types,
654 FaviconData* favicon);
655
656 // Get favicon by the given |favicon_id|, the |favicon| is set appropriately
657 // and true if returned on success, otherwise false is returned.
658 bool GetFaviconFromDB(FaviconID favicon_id, FaviconData* favicon);
659
660 // Notify any observers of an addition to the visit database. 698 // Notify any observers of an addition to the visit database.
661 void NotifyVisitObservers(const VisitRow& visit); 699 void NotifyVisitObservers(const VisitRow& visit);
662 700
663 // Data ---------------------------------------------------------------------- 701 // Data ----------------------------------------------------------------------
664 702
665 // Delegate. See the class definition above for more information. This will 703 // Delegate. See the class definition above for more information. This will
666 // be NULL before Init is called and after Cleanup, but is guaranteed 704 // be NULL before Init is called and after Cleanup, but is guaranteed
667 // non-NULL in between. 705 // non-NULL in between.
668 scoped_ptr<Delegate> delegate_; 706 scoped_ptr<Delegate> delegate_;
669 707
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 787
750 // Publishes the history to all indexers which are registered to receive 788 // Publishes the history to all indexers which are registered to receive
751 // history data from us. Can be NULL if there are no listeners. 789 // history data from us. Can be NULL if there are no listeners.
752 scoped_ptr<HistoryPublisher> history_publisher_; 790 scoped_ptr<HistoryPublisher> history_publisher_;
753 791
754 #if defined(OS_ANDROID) 792 #if defined(OS_ANDROID)
755 // Used to provide the Android ContentProvider APIs. 793 // Used to provide the Android ContentProvider APIs.
756 scoped_ptr<AndroidProviderBackend> android_provider_backend_; 794 scoped_ptr<AndroidProviderBackend> android_provider_backend_;
757 #endif 795 #endif
758 796
797 // If true HistoryBackend::SetFavicons is cripled such that it can only be
798 // used to set favicon bitmapas for a single URL and 0 0 bitmap size.
799 bool single_favicon_bitmap_per_icon_type_;
800
759 DISALLOW_COPY_AND_ASSIGN(HistoryBackend); 801 DISALLOW_COPY_AND_ASSIGN(HistoryBackend);
760 }; 802 };
761 803
762 } // namespace history 804 } // namespace history
763 805
764 #endif // CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ 806 #endif // CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698