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

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
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/mru_cache.h" 13 #include "base/memory/mru_cache.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/cancelable_request.h" 15 #include "chrome/browser/cancelable_request.h"
16 #include "chrome/browser/history/archived_database.h" 16 #include "chrome/browser/history/archived_database.h"
17 #include "chrome/browser/history/expire_history_backend.h" 17 #include "chrome/browser/history/expire_history_backend.h"
18 #include "chrome/browser/history/history_database.h" 18 #include "chrome/browser/history/history_database.h"
19 #include "chrome/browser/history/history_marshaling.h" 19 #include "chrome/browser/history/history_marshaling.h"
20 #include "chrome/browser/history/history_types.h" 20 #include "chrome/browser/history/history_types.h"
21 #include "chrome/browser/history/text_database_manager.h" 21 #include "chrome/browser/history/text_database_manager.h"
22 #include "chrome/browser/history/thumbnail_database.h" 22 #include "chrome/browser/history/thumbnail_database.h"
23 #include "chrome/browser/history/visit_tracker.h" 23 #include "chrome/browser/history/visit_tracker.h"
24 #include "chrome/browser/search_engines/template_url_id.h" 24 #include "chrome/browser/search_engines/template_url_id.h"
25 #include "sql/init_status.h" 25 #include "sql/init_status.h"
26 #include "ui/base/layout.h"
26 27
27 class BookmarkService; 28 class BookmarkService;
28 class TestingProfile; 29 class TestingProfile;
29 struct ThumbnailScore; 30 struct ThumbnailScore;
30 31
31 namespace content { 32 namespace content {
32 struct DownloadPersistentStoreInfo; 33 struct DownloadPersistentStoreInfo;
33 } 34 }
34 35
35 namespace history { 36 namespace history {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // Exposed for testing reasons. 243 // Exposed for testing reasons.
243 void GetPageThumbnailDirectly( 244 void GetPageThumbnailDirectly(
244 const GURL& page_url, 245 const GURL& page_url,
245 scoped_refptr<base::RefCountedBytes>* data); 246 scoped_refptr<base::RefCountedBytes>* data);
246 247
247 void MigrateThumbnailsDatabase(); 248 void MigrateThumbnailsDatabase();
248 249
249 // Favicon ------------------------------------------------------------------- 250 // Favicon -------------------------------------------------------------------
250 251
251 void GetFavicon(scoped_refptr<GetFaviconRequest> request, 252 void GetFavicon(scoped_refptr<GetFaviconRequest> request,
252 const GURL& icon_url, 253 const std::vector<GURL>& icon_urls,
253 int icon_types); 254 int icon_types,
255 const gfx::Size& desired_dip_size,
256 const std::vector<ui::ScaleFactor>& desired_scale_factors);
254 257
255 void GetFaviconForURL(scoped_refptr<GetFaviconRequest> request, 258 void GetFaviconForURL(
256 const GURL& page_url, 259 scoped_refptr<GetFaviconRequest> request,
257 int icon_types); 260 const GURL& page_url,
261 int icon_types,
262 const gfx::Size& desired_dip_size,
263 const std::vector<ui::ScaleFactor>& desired_scale_factors);
258 264
259 void GetFaviconForID(scoped_refptr<GetFaviconRequest> request, FaviconID id); 265 void UpdateFaviconMappingsAndFetch(
266 scoped_refptr<GetFaviconRequest> request,
267 const GURL& page_url,
268 const std::vector<GURL>& icon_urls,
269 IconType icon_type,
270 const gfx::Size& desired_dip_size,
271 const std::vector<ui::ScaleFactor>& desired_scale_factors);
260 272
261 void SetFavicon(const GURL& page_url, 273 void AddFavicons(const GURL& page_url,
262 const GURL& icon_url, 274 const GURL& icon_url,
263 scoped_refptr<base::RefCountedMemory> data, 275 IconType icon_type,
264 IconType icon_type); 276 const std::vector<FaviconBitmapData>& favicon_bitmaps);
265 277
266 void UpdateFaviconMappingAndFetch(scoped_refptr<GetFaviconRequest> request, 278 void SetFavicons(const GURL& page_url,
267 const GURL& page_url, 279 const GURL& icon_url,
268 const GURL& icon_url, 280 IconType icon_type,
269 IconType icon_type); 281 const std::vector<FaviconBitmapData>& favicon_bitmaps,
282 const IconURLSizesMap& icon_url_sizes);
270 283
271 void SetFaviconOutOfDateForPage(const GURL& page_url); 284 void SetFaviconsOutOfDateForPage(const GURL& page_url);
272 285
273 void CloneFavicon(const GURL& old_page_url, const GURL& new_page_url); 286 void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url);
274 287
275 void SetImportedFavicons( 288 void SetImportedFavicons(
276 const std::vector<ImportedFaviconUsage>& favicon_usage); 289 const std::vector<ImportedFaviconUsage>& favicon_usage);
277 290
278 // Downloads ----------------------------------------------------------------- 291 // Downloads -----------------------------------------------------------------
279 292
280 void GetNextDownloadId(scoped_refptr<DownloadNextIdRequest> request); 293 void GetNextDownloadId(scoped_refptr<DownloadNextIdRequest> request);
281 void QueryDownloads(scoped_refptr<DownloadQueryRequest> request); 294 void QueryDownloads(scoped_refptr<DownloadQueryRequest> request);
282 void CleanUpInProgressEntries(); 295 void CleanUpInProgressEntries();
283 void UpdateDownload(const content::DownloadPersistentStoreInfo& data); 296 void UpdateDownload(const content::DownloadPersistentStoreInfo& data);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 #if defined(UNIT_TEST) 448 #if defined(UNIT_TEST)
436 HistoryDatabase* db() const { return db_.get(); } 449 HistoryDatabase* db() const { return db_.get(); }
437 450
438 ExpireHistoryBackend* expire_backend() { return &expirer_; } 451 ExpireHistoryBackend* expire_backend() { return &expirer_; }
439 #endif 452 #endif
440 453
441 // Returns true if the passed visit time is already expired (used by the sync 454 // 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). 455 // code to avoid syncing visits that would immediately be expired).
443 virtual bool IsExpiredVisitTime(const base::Time& time); 456 virtual bool IsExpiredVisitTime(const base::Time& time);
444 457
458 // Set whether HistoryBackend::SetFavicon is cripled such that it can only be
459 // used to set favicon bitmaps of size 0 0 for a single URL.
460 // TODO(pkotwicz): Remove this restriction.
461 void set_single_favicon_bitmap_per_icon_type(
462 bool single_favicon_bitmap_per_icon_type) {
463 single_favicon_bitmap_per_icon_type_ = single_favicon_bitmap_per_icon_type;
464 }
465
445 protected: 466 protected:
446 virtual ~HistoryBackend(); 467 virtual ~HistoryBackend();
447 468
448 private: 469 private:
449 friend class base::RefCountedThreadSafe<HistoryBackend>; 470 friend class base::RefCountedThreadSafe<HistoryBackend>;
450 friend class CommitLaterTask; // The commit task needs to call Commit(). 471 friend class CommitLaterTask; // The commit task needs to call Commit().
451 friend class HistoryBackendTest; 472 friend class HistoryBackendTest;
452 friend class HistoryTest; // So the unit tests can poke our innards. 473 friend class HistoryTest; // So the unit tests can poke our innards.
453 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll); 474 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll);
454 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAllThenAddData); 475 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAllThenAddData);
455 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, ImportedFaviconsTest); 476 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, ImportedFaviconsTest);
456 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, URLsNoLongerBookmarked); 477 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, URLsNoLongerBookmarked);
457 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, StripUsernamePasswordTest); 478 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, StripUsernamePasswordTest);
458 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteThumbnailsDatabaseTest); 479 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteThumbnailsDatabaseTest);
459 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddPageVisitSource); 480 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddPageVisitSource);
460 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddPageArgsSource); 481 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddPageArgsSource);
461 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddVisitsSource); 482 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddVisitsSource);
462 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsSource); 483 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsSource);
463 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsTransitions); 484 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsTransitions);
464 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationVisitSource); 485 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationVisitSource);
465 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); 486 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping);
466 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconMapping); 487 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
467 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddOrUpdateIconMapping); 488 SetFaviconMappingsForPageAndRedirects);
489 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
490 SetFaviconMappingsForPageDuplicates);
491 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFavicons);
492 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsDeleteBitmaps);
493 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsReplaceBitmapData);
468 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetMostRecentVisits); 494 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetMostRecentVisits);
469 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconForURL); 495 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDB);
496 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBExpired);
497 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBIconType);
498 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBEmpty);
470 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, 499 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
471 CloneFaviconIsRestrictedToSameDomain); 500 CloneFaviconIsRestrictedToSameDomain);
472 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, QueryFilteredURLs); 501 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, QueryFilteredURLs);
473 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, UpdateVisitDuration); 502 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, UpdateVisitDuration);
474 503
475 friend class ::TestingProfile; 504 friend class ::TestingProfile;
476 505
477 // Computes the name of the specified database on disk. 506 // Computes the name of the specified database on disk.
478 FilePath GetThumbnailFileName() const; 507 FilePath GetThumbnailFileName() const;
479 508
(...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 600 // 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. 601 // added. Return the segment id of the segment that has been updated.
573 SegmentID UpdateSegments(const GURL& url, 602 SegmentID UpdateSegments(const GURL& url,
574 VisitID from_visit, 603 VisitID from_visit,
575 VisitID visit_id, 604 VisitID visit_id,
576 content::PageTransition transition_type, 605 content::PageTransition transition_type,
577 const base::Time ts); 606 const base::Time ts);
578 607
579 // Favicons ------------------------------------------------------------------ 608 // Favicons ------------------------------------------------------------------
580 609
581 // Used by both UpdateFaviconMappingAndFetch and GetFavicon. 610 // Used by both UpdateFaviconMappingsAndFetch and GetFavicons.
582 // If page_url is non-null and SetFavicon has previously been invoked for 611 // 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 612 // redirects) are set to the subset of |icon_urls| for which icons are
584 // icon_url. 613 // already stored in the database.
585 // Only a single type can be given in icon_type when page_url is specified. 614 // Only a single type can be given in icon_type when page_url is specified.
586 void UpdateFaviconMappingAndFetchImpl( 615 void UpdateFaviconMappingsAndFetchImpl(
587 const GURL* page_url, 616 const GURL* page_url,
588 const GURL& icon_url, 617 const std::vector<GURL>& icon_urls,
589 scoped_refptr<GetFaviconRequest> request, 618 scoped_refptr<GetFaviconRequest> request,
590 int icon_type); 619 int icon_types,
620 const gfx::Size& desired_dip_size,
621 const std::vector<ui::ScaleFactor> desired_scale_factors);
591 622
592 // Sets the favicon url id for page_url to id. This will also broadcast 623 // Set the favicon bitmaps for the favicon at |icon_id|.
593 // notifications as necessary. 624 void SetFaviconBitmaps(
594 void SetFaviconMapping(const GURL& page_url, 625 FaviconID icon_id,
595 FaviconID id, 626 const std::vector<FaviconBitmapData>& favicon_bitmaps);
596 IconType icon_type);
597 627
598 // Updates the FaviconID associated with the url of a page. If there is an 628 // Returns true if |elements| and |icon_url_sizes| passed to SetFavicons
599 // existing mapping between |page_url| and |id| this does nothing and returns 629 // are valid.
600 // false. If the mapping needs to be added or updated, true is returned. If 630 bool ValidateSetFaviconsParams(
601 // there is an existing mapping but it does not map to |id|, then the |id| of 631 const std::vector<FaviconBitmapData>& favicon_bitmaps,
602 // the replaced FaviconID is set in |replaced_icon_id|. 632 const IconURLSizesMap& icon_url_sizes) const;
603 bool AddOrUpdateIconMapping(const GURL& page_url, 633
604 FaviconID id, 634 // Sets the sizes that the thumbnail database knows that the favicon at
605 IconType icon_type, 635 // |icon_id| is available at from the web. See history_types for a more
606 FaviconID* replaced_icon_id); 636 // in depth discussion about FaviconSizes.
637 void SetFaviconSizes(FaviconID icon_id,
638 const std::vector<gfx::Size>& sizes);
639
640 // Returns true if there are favicons for |page_url| and one of the types in
641 // |icon_types|.
642 // |favicon_data| is set to the favicon bitmaps which most closely match
643 // |desired_dip_size| and |desired_scale_factors|. See the comment for
644 // GetFaviconDataForBestMatch() for more details on how FaviconData is
645 // constructed.
646 // |mapped_icon_urls| is set to all of the icon URLs which are mapped to
647 // |page_url| with one of the types in |icon_types|. If |icon_types| contains
648 // multiple icon types and there are several matched icon types in the
649 // database, icon URLs of a only single type will be in |mapped_icon_urls|
650 // in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and FAVICON.
651 bool GetFaviconFromDB(
652 const GURL& page_url,
653 int icon_types,
654 const gfx::Size& desired_dip_size,
655 const std::vector<ui::ScaleFactor>& desired_scale_factors,
656 FaviconData* favicon_data,
657 std::vector<GURL>* mapped_icon_urls);
658
659 // Construct a FaviconData object from the favicon bitmaps which most closely
660 // match |desired_dip_size| and |desired_scale_factors|.
661 // Goodness is computed on a per favicon id basis, thus all of
662 // FaviconData::bitmaps are guaranteed to be for the same FaviconID.
663 // FaviconData::bitmaps may not contain all the favicon bitmaps for FaviconID
664 // which are in the database. Returns true on success.
665 bool GetFaviconDataForBestMatch(
666 const std::vector<FaviconID>& candidate_favicon_ids,
667 const gfx::Size& desired_dip_size,
668 const std::vector<ui::ScaleFactor>& desired_scale_factors,
669 FaviconData* favicon_data);
670
671 // Define type used solely in SetFaviconMappingsForPageAndRedirects.
672 typedef std::map<GURL, FaviconID> IconURLFaviconIDMap;
673
674 // Maps the favicon ids in |icon_url_id_map| to |page_url| (and all
675 // redirects) for |icon_type|. This will also broadcast notifications as
676 // necessary.
677 void SetFaviconMappingsForPageAndRedirects(
678 const GURL& page_url,
679 const IconType icon_type,
680 const IconURLFaviconIDMap& icon_url_id_map);
681
682 // Maps the favicon ids in |icon_url_id_map| to |page_url| for |icon_type|.
683 bool SetFaviconMappingsForPage(const GURL& page_url,
684 IconType icon_type,
685 const IconURLFaviconIDMap& icon_url_id_map);
607 686
608 // Generic stuff ------------------------------------------------------------- 687 // Generic stuff -------------------------------------------------------------
609 688
610 // Processes the next scheduled HistoryDBTask, scheduling this method 689 // Processes the next scheduled HistoryDBTask, scheduling this method
611 // to be invoked again if there are more tasks that need to run. 690 // to be invoked again if there are more tasks that need to run.
612 void ProcessDBTaskImpl(); 691 void ProcessDBTaskImpl();
613 692
614 // Release all tasks in history_db_tasks_ and clears it. 693 // Release all tasks in history_db_tasks_ and clears it.
615 void ReleaseDBTasks(); 694 void ReleaseDBTasks();
616 695
(...skipping 23 matching lines...) Expand all
640 // set of URLs in the URL table (these should correspond to the bookmarked 719 // set of URLs in the URL table (these should correspond to the bookmarked
641 // URLs). 720 // URLs).
642 // 721 //
643 // The IDs of the URLs may change. 722 // The IDs of the URLs may change.
644 bool ClearAllMainHistory(const URLRows& kept_urls); 723 bool ClearAllMainHistory(const URLRows& kept_urls);
645 724
646 // Returns the BookmarkService, blocking until it is loaded. This may return 725 // Returns the BookmarkService, blocking until it is loaded. This may return
647 // NULL during testing. 726 // NULL during testing.
648 BookmarkService* GetBookmarkService(); 727 BookmarkService* GetBookmarkService();
649 728
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_data);
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_data);
659
660 // Notify any observers of an addition to the visit database. 729 // Notify any observers of an addition to the visit database.
661 void NotifyVisitObservers(const VisitRow& visit); 730 void NotifyVisitObservers(const VisitRow& visit);
662 731
663 // Data ---------------------------------------------------------------------- 732 // Data ----------------------------------------------------------------------
664 733
665 // Delegate. See the class definition above for more information. This will 734 // Delegate. See the class definition above for more information. This will
666 // be NULL before Init is called and after Cleanup, but is guaranteed 735 // be NULL before Init is called and after Cleanup, but is guaranteed
667 // non-NULL in between. 736 // non-NULL in between.
668 scoped_ptr<Delegate> delegate_; 737 scoped_ptr<Delegate> delegate_;
669 738
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 818
750 // Publishes the history to all indexers which are registered to receive 819 // Publishes the history to all indexers which are registered to receive
751 // history data from us. Can be NULL if there are no listeners. 820 // history data from us. Can be NULL if there are no listeners.
752 scoped_ptr<HistoryPublisher> history_publisher_; 821 scoped_ptr<HistoryPublisher> history_publisher_;
753 822
754 #if defined(OS_ANDROID) 823 #if defined(OS_ANDROID)
755 // Used to provide the Android ContentProvider APIs. 824 // Used to provide the Android ContentProvider APIs.
756 scoped_ptr<AndroidProviderBackend> android_provider_backend_; 825 scoped_ptr<AndroidProviderBackend> android_provider_backend_;
757 #endif 826 #endif
758 827
828 // If true HistoryBackend::SetFavicons is cripled such that it can only be
829 // used to set favicon bitmapas for a single URL and 0 0 bitmap size.
830 bool single_favicon_bitmap_per_icon_type_;
831
759 DISALLOW_COPY_AND_ASSIGN(HistoryBackend); 832 DISALLOW_COPY_AND_ASSIGN(HistoryBackend);
760 }; 833 };
761 834
762 } // namespace history 835 } // namespace history
763 836
764 #endif // CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ 837 #endif // CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698