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

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

Issue 285233012: Abstract history dependencies on bookmarks through HistoryClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests Created 6 years, 7 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
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/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 19 matching lines...) Expand all
30 #include "chrome/browser/history/history_db_task.h" 30 #include "chrome/browser/history/history_db_task.h"
31 #include "chrome/browser/history/history_notifications.h" 31 #include "chrome/browser/history/history_notifications.h"
32 #include "chrome/browser/history/in_memory_history_backend.h" 32 #include "chrome/browser/history/in_memory_history_backend.h"
33 #include "chrome/browser/history/page_usage_data.h" 33 #include "chrome/browser/history/page_usage_data.h"
34 #include "chrome/browser/history/top_sites.h" 34 #include "chrome/browser/history/top_sites.h"
35 #include "chrome/browser/history/typed_url_syncable_service.h" 35 #include "chrome/browser/history/typed_url_syncable_service.h"
36 #include "chrome/browser/history/visit_filter.h" 36 #include "chrome/browser/history/visit_filter.h"
37 #include "chrome/common/chrome_constants.h" 37 #include "chrome/common/chrome_constants.h"
38 #include "chrome/common/importer/imported_favicon_usage.h" 38 #include "chrome/common/importer/imported_favicon_usage.h"
39 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
40 #include "components/bookmarks/browser/bookmark_service.h"
41 #include "components/favicon_base/select_favicon_frames.h" 40 #include "components/favicon_base/select_favicon_frames.h"
41 #include "components/history/core/browser/history_client.h"
42 #include "grit/chromium_strings.h" 42 #include "grit/chromium_strings.h"
43 #include "grit/generated_resources.h" 43 #include "grit/generated_resources.h"
44 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 44 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
45 #include "sql/error_delegate_util.h" 45 #include "sql/error_delegate_util.h"
46 #include "url/gurl.h" 46 #include "url/gurl.h"
47 47
48 #if defined(OS_ANDROID) 48 #if defined(OS_ANDROID)
49 #include "chrome/browser/history/android/android_provider_backend.h" 49 #include "chrome/browser/history/android/android_provider_backend.h"
50 #endif 50 #endif
51 51
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 ~CommitLaterTask() {} 158 ~CommitLaterTask() {}
159 159
160 scoped_refptr<HistoryBackend> history_backend_; 160 scoped_refptr<HistoryBackend> history_backend_;
161 }; 161 };
162 162
163 // HistoryBackend -------------------------------------------------------------- 163 // HistoryBackend --------------------------------------------------------------
164 164
165 HistoryBackend::HistoryBackend(const base::FilePath& history_dir, 165 HistoryBackend::HistoryBackend(const base::FilePath& history_dir,
166 Delegate* delegate, 166 Delegate* delegate,
167 BookmarkService* bookmark_service) 167 HistoryClient* history_client)
168 : delegate_(delegate), 168 : delegate_(delegate),
169 history_dir_(history_dir), 169 history_dir_(history_dir),
170 scheduled_kill_db_(false), 170 scheduled_kill_db_(false),
171 expirer_(this, bookmark_service), 171 expirer_(this, history_client),
172 recent_redirects_(kMaxRedirectCount), 172 recent_redirects_(kMaxRedirectCount),
173 backend_destroy_message_loop_(NULL), 173 backend_destroy_message_loop_(NULL),
174 segment_queried_(false), 174 segment_queried_(false),
175 bookmark_service_(bookmark_service) { 175 history_client_(history_client) {
176 } 176 }
177 177
178 HistoryBackend::~HistoryBackend() { 178 HistoryBackend::~HistoryBackend() {
179 DCHECK(!scheduled_commit_.get()) << "Deleting without cleanup"; 179 DCHECK(!scheduled_commit_.get()) << "Deleting without cleanup";
180 ReleaseDBTasks(); 180 ReleaseDBTasks();
181 181
182 #if defined(OS_ANDROID) 182 #if defined(OS_ANDROID)
183 // Release AndroidProviderBackend before other objects. 183 // Release AndroidProviderBackend before other objects.
184 android_provider_backend_.reset(); 184 android_provider_backend_.reset();
185 #endif 185 #endif
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 // Get the first item in our database. 658 // Get the first item in our database.
659 db_->GetStartDate(&first_recorded_time_); 659 db_->GetStartDate(&first_recorded_time_);
660 660
661 // Start expiring old stuff. 661 // Start expiring old stuff.
662 expirer_.StartArchivingOldStuff(TimeDelta::FromDays(kArchiveDaysThreshold)); 662 expirer_.StartArchivingOldStuff(TimeDelta::FromDays(kArchiveDaysThreshold));
663 663
664 #if defined(OS_ANDROID) 664 #if defined(OS_ANDROID)
665 if (thumbnail_db_) { 665 if (thumbnail_db_) {
666 android_provider_backend_.reset(new AndroidProviderBackend( 666 android_provider_backend_.reset(new AndroidProviderBackend(
667 GetAndroidCacheFileName(), db_.get(), thumbnail_db_.get(), 667 GetAndroidCacheFileName(), db_.get(), thumbnail_db_.get(),
668 bookmark_service_, delegate_.get())); 668 history_client_, delegate_.get()));
669 } 669 }
670 #endif 670 #endif
671 671
672 HISTOGRAM_TIMES("History.InitTime", 672 HISTOGRAM_TIMES("History.InitTime",
673 TimeTicks::Now() - beginning_time); 673 TimeTicks::Now() - beginning_time);
674 } 674 }
675 675
676 void HistoryBackend::OnMemoryPressure( 676 void HistoryBackend::OnMemoryPressure(
677 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 677 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
678 bool trim_aggressively = memory_pressure_level == 678 bool trim_aggressively = memory_pressure_level ==
(...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 // TODO(pkotwicz): Pass in real pixel size. 2034 // TODO(pkotwicz): Pass in real pixel size.
2035 favicon_id = thumbnail_db_->AddFavicon( 2035 favicon_id = thumbnail_db_->AddFavicon(
2036 favicon_usage[i].favicon_url, 2036 favicon_usage[i].favicon_url,
2037 favicon_base::FAVICON, 2037 favicon_base::FAVICON,
2038 new base::RefCountedBytes(favicon_usage[i].png_data), 2038 new base::RefCountedBytes(favicon_usage[i].png_data),
2039 now, 2039 now,
2040 gfx::Size()); 2040 gfx::Size());
2041 } 2041 }
2042 2042
2043 // Save the mapping from all the URLs to the favicon. 2043 // Save the mapping from all the URLs to the favicon.
2044 BookmarkService* bookmark_service = GetBookmarkService(); 2044 HistoryClient* history_client = GetHistoryClient();
2045 for (std::set<GURL>::const_iterator url = favicon_usage[i].urls.begin(); 2045 for (std::set<GURL>::const_iterator url = favicon_usage[i].urls.begin();
2046 url != favicon_usage[i].urls.end(); ++url) { 2046 url != favicon_usage[i].urls.end(); ++url) {
2047 URLRow url_row; 2047 URLRow url_row;
2048 if (!db_->GetRowForURL(*url, &url_row)) { 2048 if (!db_->GetRowForURL(*url, &url_row)) {
2049 // If the URL is present as a bookmark, add the url in history to 2049 // If the URL is present as a bookmark, add the url in history to
2050 // save the favicon mapping. This will match with what history db does 2050 // save the favicon mapping. This will match with what history db does
2051 // for regular bookmarked URLs with favicons - when history db is 2051 // for regular bookmarked URLs with favicons - when history db is
2052 // cleaned, we keep an entry in the db with 0 visits as long as that 2052 // cleaned, we keep an entry in the db with 0 visits as long as that
2053 // url is bookmarked. 2053 // url is bookmarked.
2054 if (bookmark_service && bookmark_service_->IsBookmarked(*url)) { 2054 if (history_client && history_client->IsBookmarked(*url)) {
2055 URLRow url_info(*url); 2055 URLRow url_info(*url);
2056 url_info.set_visit_count(0); 2056 url_info.set_visit_count(0);
2057 url_info.set_typed_count(0); 2057 url_info.set_typed_count(0);
2058 url_info.set_last_visit(base::Time()); 2058 url_info.set_last_visit(base::Time());
2059 url_info.set_hidden(false); 2059 url_info.set_hidden(false);
2060 db_->AddURL(url_info); 2060 db_->AddURL(url_info);
2061 thumbnail_db_->AddIconMapping(*url, favicon_id); 2061 thumbnail_db_->AddIconMapping(*url, favicon_id);
2062 favicons_changed.insert(*url); 2062 favicons_changed.insert(*url);
2063 } 2063 }
2064 } else { 2064 } else {
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 // 2. Delete the original tables. Since tables can not share pages, we know 2767 // 2. Delete the original tables. Since tables can not share pages, we know
2768 // that any data we don't want to keep is now in an unused page. 2768 // that any data we don't want to keep is now in an unused page.
2769 // 3. Renaming the temporary tables to match the original. 2769 // 3. Renaming the temporary tables to match the original.
2770 // 4. Vacuuming the database to delete the unused pages. 2770 // 4. Vacuuming the database to delete the unused pages.
2771 // 2771 //
2772 // Since we are likely to have very few bookmarks and their dependencies 2772 // Since we are likely to have very few bookmarks and their dependencies
2773 // compared to all history, this is also much faster than just deleting from 2773 // compared to all history, this is also much faster than just deleting from
2774 // the original tables directly. 2774 // the original tables directly.
2775 2775
2776 // Get the bookmarked URLs. 2776 // Get the bookmarked URLs.
2777 std::vector<BookmarkService::URLAndTitle> starred_urls; 2777 std::vector<URLAndTitle> starred_urls;
2778 BookmarkService* bookmark_service = GetBookmarkService(); 2778 HistoryClient* history_client = GetHistoryClient();
2779 if (bookmark_service) 2779 if (history_client)
2780 bookmark_service_->GetBookmarks(&starred_urls); 2780 history_client->GetBookmarks(&starred_urls);
2781 2781
2782 URLRows kept_urls; 2782 URLRows kept_urls;
2783 for (size_t i = 0; i < starred_urls.size(); i++) { 2783 for (size_t i = 0; i < starred_urls.size(); i++) {
2784 URLRow row; 2784 URLRow row;
2785 if (!db_->GetRowForURL(starred_urls[i].url, &row)) 2785 if (!db_->GetRowForURL(starred_urls[i].url, &row))
2786 continue; 2786 continue;
2787 2787
2788 // Clear the last visit time so when we write these rows they are "clean." 2788 // Clear the last visit time so when we write these rows they are "clean."
2789 row.set_last_visit(Time()); 2789 row.set_last_visit(Time());
2790 row.set_visit_count(0); 2790 row.set_visit_count(0);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2906 // when there is no transaction open, and we assume that our long-running 2906 // when there is no transaction open, and we assume that our long-running
2907 // transaction is currently open. 2907 // transaction is currently open.
2908 db_->CommitTransaction(); 2908 db_->CommitTransaction();
2909 db_->Vacuum(); 2909 db_->Vacuum();
2910 db_->BeginTransaction(); 2910 db_->BeginTransaction();
2911 db_->GetStartDate(&first_recorded_time_); 2911 db_->GetStartDate(&first_recorded_time_);
2912 2912
2913 return true; 2913 return true;
2914 } 2914 }
2915 2915
2916 BookmarkService* HistoryBackend::GetBookmarkService() { 2916 HistoryClient* HistoryBackend::GetHistoryClient() {
2917 if (bookmark_service_) 2917 if (history_client_)
2918 bookmark_service_->BlockTillLoaded(); 2918 history_client_->BlockTillBookmarksLoaded();
2919 return bookmark_service_; 2919 return history_client_;
2920 } 2920 }
2921 2921
2922 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) { 2922 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) {
2923 BriefVisitInfo info; 2923 BriefVisitInfo info;
2924 info.url_id = visit.url_id; 2924 info.url_id = visit.url_id;
2925 info.time = visit.visit_time; 2925 info.time = visit.visit_time;
2926 info.transition = visit.transition; 2926 info.transition = visit.transition;
2927 // If we don't have a delegate yet during setup or shutdown, we will drop 2927 // If we don't have a delegate yet during setup or shutdown, we will drop
2928 // these notifications. 2928 // these notifications.
2929 if (delegate_) 2929 if (delegate_)
(...skipping 18 matching lines...) Expand all
2948 int rank = kPageVisitStatsMaxTopSites; 2948 int rank = kPageVisitStatsMaxTopSites;
2949 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); 2949 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url);
2950 if (it != most_visited_urls_map_.end()) 2950 if (it != most_visited_urls_map_.end())
2951 rank = (*it).second; 2951 rank = (*it).second;
2952 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", 2952 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank",
2953 rank, kPageVisitStatsMaxTopSites + 1); 2953 rank, kPageVisitStatsMaxTopSites + 1);
2954 } 2954 }
2955 #endif 2955 #endif
2956 2956
2957 } // namespace history 2957 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698