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

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: Rebase Created 6 years, 6 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 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 // TODO(pkotwicz): Pass in real pixel size. 2035 // TODO(pkotwicz): Pass in real pixel size.
2036 favicon_id = thumbnail_db_->AddFavicon( 2036 favicon_id = thumbnail_db_->AddFavicon(
2037 favicon_usage[i].favicon_url, 2037 favicon_usage[i].favicon_url,
2038 favicon_base::FAVICON, 2038 favicon_base::FAVICON,
2039 new base::RefCountedBytes(favicon_usage[i].png_data), 2039 new base::RefCountedBytes(favicon_usage[i].png_data),
2040 now, 2040 now,
2041 gfx::Size()); 2041 gfx::Size());
2042 } 2042 }
2043 2043
2044 // Save the mapping from all the URLs to the favicon. 2044 // Save the mapping from all the URLs to the favicon.
2045 BookmarkService* bookmark_service = GetBookmarkService(); 2045 HistoryClient* history_client = GetHistoryClient();
2046 for (std::set<GURL>::const_iterator url = favicon_usage[i].urls.begin(); 2046 for (std::set<GURL>::const_iterator url = favicon_usage[i].urls.begin();
2047 url != favicon_usage[i].urls.end(); ++url) { 2047 url != favicon_usage[i].urls.end(); ++url) {
2048 URLRow url_row; 2048 URLRow url_row;
2049 if (!db_->GetRowForURL(*url, &url_row)) { 2049 if (!db_->GetRowForURL(*url, &url_row)) {
2050 // If the URL is present as a bookmark, add the url in history to 2050 // If the URL is present as a bookmark, add the url in history to
2051 // save the favicon mapping. This will match with what history db does 2051 // save the favicon mapping. This will match with what history db does
2052 // for regular bookmarked URLs with favicons - when history db is 2052 // for regular bookmarked URLs with favicons - when history db is
2053 // cleaned, we keep an entry in the db with 0 visits as long as that 2053 // cleaned, we keep an entry in the db with 0 visits as long as that
2054 // url is bookmarked. 2054 // url is bookmarked.
2055 if (bookmark_service && bookmark_service_->IsBookmarked(*url)) { 2055 if (history_client && history_client->IsBookmarked(*url)) {
2056 URLRow url_info(*url); 2056 URLRow url_info(*url);
2057 url_info.set_visit_count(0); 2057 url_info.set_visit_count(0);
2058 url_info.set_typed_count(0); 2058 url_info.set_typed_count(0);
2059 url_info.set_last_visit(base::Time()); 2059 url_info.set_last_visit(base::Time());
2060 url_info.set_hidden(false); 2060 url_info.set_hidden(false);
2061 db_->AddURL(url_info); 2061 db_->AddURL(url_info);
2062 thumbnail_db_->AddIconMapping(*url, favicon_id); 2062 thumbnail_db_->AddIconMapping(*url, favicon_id);
2063 favicons_changed.insert(*url); 2063 favicons_changed.insert(*url);
2064 } 2064 }
2065 } else { 2065 } else {
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
2768 // 2. Delete the original tables. Since tables can not share pages, we know 2768 // 2. Delete the original tables. Since tables can not share pages, we know
2769 // that any data we don't want to keep is now in an unused page. 2769 // that any data we don't want to keep is now in an unused page.
2770 // 3. Renaming the temporary tables to match the original. 2770 // 3. Renaming the temporary tables to match the original.
2771 // 4. Vacuuming the database to delete the unused pages. 2771 // 4. Vacuuming the database to delete the unused pages.
2772 // 2772 //
2773 // Since we are likely to have very few bookmarks and their dependencies 2773 // Since we are likely to have very few bookmarks and their dependencies
2774 // compared to all history, this is also much faster than just deleting from 2774 // compared to all history, this is also much faster than just deleting from
2775 // the original tables directly. 2775 // the original tables directly.
2776 2776
2777 // Get the bookmarked URLs. 2777 // Get the bookmarked URLs.
2778 std::vector<BookmarkService::URLAndTitle> starred_urls; 2778 std::vector<URLAndTitle> starred_urls;
2779 BookmarkService* bookmark_service = GetBookmarkService(); 2779 HistoryClient* history_client = GetHistoryClient();
2780 if (bookmark_service) 2780 if (history_client)
2781 bookmark_service_->GetBookmarks(&starred_urls); 2781 history_client->GetBookmarks(&starred_urls);
2782 2782
2783 URLRows kept_urls; 2783 URLRows kept_urls;
2784 for (size_t i = 0; i < starred_urls.size(); i++) { 2784 for (size_t i = 0; i < starred_urls.size(); i++) {
2785 URLRow row; 2785 URLRow row;
2786 if (!db_->GetRowForURL(starred_urls[i].url, &row)) 2786 if (!db_->GetRowForURL(starred_urls[i].url, &row))
2787 continue; 2787 continue;
2788 2788
2789 // Clear the last visit time so when we write these rows they are "clean." 2789 // Clear the last visit time so when we write these rows they are "clean."
2790 row.set_last_visit(Time()); 2790 row.set_last_visit(Time());
2791 row.set_visit_count(0); 2791 row.set_visit_count(0);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2907 // when there is no transaction open, and we assume that our long-running 2907 // when there is no transaction open, and we assume that our long-running
2908 // transaction is currently open. 2908 // transaction is currently open.
2909 db_->CommitTransaction(); 2909 db_->CommitTransaction();
2910 db_->Vacuum(); 2910 db_->Vacuum();
2911 db_->BeginTransaction(); 2911 db_->BeginTransaction();
2912 db_->GetStartDate(&first_recorded_time_); 2912 db_->GetStartDate(&first_recorded_time_);
2913 2913
2914 return true; 2914 return true;
2915 } 2915 }
2916 2916
2917 BookmarkService* HistoryBackend::GetBookmarkService() { 2917 HistoryClient* HistoryBackend::GetHistoryClient() {
2918 if (bookmark_service_) 2918 if (history_client_)
2919 bookmark_service_->BlockTillLoaded(); 2919 history_client_->BlockUntilBookmarksLoaded();
2920 return bookmark_service_; 2920 return history_client_;
2921 } 2921 }
2922 2922
2923 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) { 2923 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) {
2924 BriefVisitInfo info; 2924 BriefVisitInfo info;
2925 info.url_id = visit.url_id; 2925 info.url_id = visit.url_id;
2926 info.time = visit.visit_time; 2926 info.time = visit.visit_time;
2927 info.transition = visit.transition; 2927 info.transition = visit.transition;
2928 // If we don't have a delegate yet during setup or shutdown, we will drop 2928 // If we don't have a delegate yet during setup or shutdown, we will drop
2929 // these notifications. 2929 // these notifications.
2930 if (delegate_) 2930 if (delegate_)
(...skipping 18 matching lines...) Expand all
2949 int rank = kPageVisitStatsMaxTopSites; 2949 int rank = kPageVisitStatsMaxTopSites;
2950 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); 2950 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url);
2951 if (it != most_visited_urls_map_.end()) 2951 if (it != most_visited_urls_map_.end())
2952 rank = (*it).second; 2952 rank = (*it).second;
2953 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", 2953 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank",
2954 rank, kPageVisitStatsMaxTopSites + 1); 2954 rank, kPageVisitStatsMaxTopSites + 1);
2955 } 2955 }
2956 #endif 2956 #endif
2957 2957
2958 } // namespace history 2958 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698