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

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 android unit tests 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 archived_db_->BeginTransaction(); 656 archived_db_->BeginTransaction();
657 657
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(
667 GetAndroidCacheFileName(), db_.get(), thumbnail_db_.get(), 667 new AndroidProviderBackend(GetAndroidCacheFileName(),
668 bookmark_service_, delegate_.get())); 668 db_.get(),
669 thumbnail_db_.get(),
670 history_client_,
671 delegate_.get()));
669 } 672 }
670 #endif 673 #endif
671 674
672 HISTOGRAM_TIMES("History.InitTime", 675 HISTOGRAM_TIMES("History.InitTime",
673 TimeTicks::Now() - beginning_time); 676 TimeTicks::Now() - beginning_time);
674 } 677 }
675 678
676 void HistoryBackend::OnMemoryPressure( 679 void HistoryBackend::OnMemoryPressure(
677 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 680 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
678 bool trim_aggressively = memory_pressure_level == 681 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. 2038 // TODO(pkotwicz): Pass in real pixel size.
2036 favicon_id = thumbnail_db_->AddFavicon( 2039 favicon_id = thumbnail_db_->AddFavicon(
2037 favicon_usage[i].favicon_url, 2040 favicon_usage[i].favicon_url,
2038 favicon_base::FAVICON, 2041 favicon_base::FAVICON,
2039 new base::RefCountedBytes(favicon_usage[i].png_data), 2042 new base::RefCountedBytes(favicon_usage[i].png_data),
2040 now, 2043 now,
2041 gfx::Size()); 2044 gfx::Size());
2042 } 2045 }
2043 2046
2044 // Save the mapping from all the URLs to the favicon. 2047 // Save the mapping from all the URLs to the favicon.
2045 BookmarkService* bookmark_service = GetBookmarkService(); 2048 HistoryClient* history_client = GetHistoryClient();
2046 for (std::set<GURL>::const_iterator url = favicon_usage[i].urls.begin(); 2049 for (std::set<GURL>::const_iterator url = favicon_usage[i].urls.begin();
2047 url != favicon_usage[i].urls.end(); ++url) { 2050 url != favicon_usage[i].urls.end(); ++url) {
2048 URLRow url_row; 2051 URLRow url_row;
2049 if (!db_->GetRowForURL(*url, &url_row)) { 2052 if (!db_->GetRowForURL(*url, &url_row)) {
2050 // If the URL is present as a bookmark, add the url in history to 2053 // 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 2054 // save the favicon mapping. This will match with what history db does
2052 // for regular bookmarked URLs with favicons - when history db is 2055 // 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 2056 // cleaned, we keep an entry in the db with 0 visits as long as that
2054 // url is bookmarked. 2057 // url is bookmarked.
2055 if (bookmark_service && bookmark_service_->IsBookmarked(*url)) { 2058 if (history_client && history_client->IsBookmarked(*url)) {
2056 URLRow url_info(*url); 2059 URLRow url_info(*url);
2057 url_info.set_visit_count(0); 2060 url_info.set_visit_count(0);
2058 url_info.set_typed_count(0); 2061 url_info.set_typed_count(0);
2059 url_info.set_last_visit(base::Time()); 2062 url_info.set_last_visit(base::Time());
2060 url_info.set_hidden(false); 2063 url_info.set_hidden(false);
2061 db_->AddURL(url_info); 2064 db_->AddURL(url_info);
2062 thumbnail_db_->AddIconMapping(*url, favicon_id); 2065 thumbnail_db_->AddIconMapping(*url, favicon_id);
2063 favicons_changed.insert(*url); 2066 favicons_changed.insert(*url);
2064 } 2067 }
2065 } else { 2068 } 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 2771 // 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. 2772 // 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. 2773 // 3. Renaming the temporary tables to match the original.
2771 // 4. Vacuuming the database to delete the unused pages. 2774 // 4. Vacuuming the database to delete the unused pages.
2772 // 2775 //
2773 // Since we are likely to have very few bookmarks and their dependencies 2776 // 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 2777 // compared to all history, this is also much faster than just deleting from
2775 // the original tables directly. 2778 // the original tables directly.
2776 2779
2777 // Get the bookmarked URLs. 2780 // Get the bookmarked URLs.
2778 std::vector<BookmarkService::URLAndTitle> starred_urls; 2781 std::vector<URLAndTitle> starred_urls;
2779 BookmarkService* bookmark_service = GetBookmarkService(); 2782 HistoryClient* history_client = GetHistoryClient();
2780 if (bookmark_service) 2783 if (history_client)
2781 bookmark_service_->GetBookmarks(&starred_urls); 2784 history_client->GetBookmarks(&starred_urls);
2782 2785
2783 URLRows kept_urls; 2786 URLRows kept_urls;
2784 for (size_t i = 0; i < starred_urls.size(); i++) { 2787 for (size_t i = 0; i < starred_urls.size(); i++) {
2785 URLRow row; 2788 URLRow row;
2786 if (!db_->GetRowForURL(starred_urls[i].url, &row)) 2789 if (!db_->GetRowForURL(starred_urls[i].url, &row))
2787 continue; 2790 continue;
2788 2791
2789 // Clear the last visit time so when we write these rows they are "clean." 2792 // Clear the last visit time so when we write these rows they are "clean."
2790 row.set_last_visit(Time()); 2793 row.set_last_visit(Time());
2791 row.set_visit_count(0); 2794 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 2910 // when there is no transaction open, and we assume that our long-running
2908 // transaction is currently open. 2911 // transaction is currently open.
2909 db_->CommitTransaction(); 2912 db_->CommitTransaction();
2910 db_->Vacuum(); 2913 db_->Vacuum();
2911 db_->BeginTransaction(); 2914 db_->BeginTransaction();
2912 db_->GetStartDate(&first_recorded_time_); 2915 db_->GetStartDate(&first_recorded_time_);
2913 2916
2914 return true; 2917 return true;
2915 } 2918 }
2916 2919
2917 BookmarkService* HistoryBackend::GetBookmarkService() { 2920 HistoryClient* HistoryBackend::GetHistoryClient() {
2918 if (bookmark_service_) 2921 if (history_client_)
2919 bookmark_service_->BlockTillLoaded(); 2922 history_client_->BlockUntilBookmarksLoaded();
2920 return bookmark_service_; 2923 return history_client_;
2921 } 2924 }
2922 2925
2923 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) { 2926 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) {
2924 BriefVisitInfo info; 2927 BriefVisitInfo info;
2925 info.url_id = visit.url_id; 2928 info.url_id = visit.url_id;
2926 info.time = visit.visit_time; 2929 info.time = visit.visit_time;
2927 info.transition = visit.transition; 2930 info.transition = visit.transition;
2928 // If we don't have a delegate yet during setup or shutdown, we will drop 2931 // If we don't have a delegate yet during setup or shutdown, we will drop
2929 // these notifications. 2932 // these notifications.
2930 if (delegate_) 2933 if (delegate_)
(...skipping 18 matching lines...) Expand all
2949 int rank = kPageVisitStatsMaxTopSites; 2952 int rank = kPageVisitStatsMaxTopSites;
2950 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); 2953 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url);
2951 if (it != most_visited_urls_map_.end()) 2954 if (it != most_visited_urls_map_.end())
2952 rank = (*it).second; 2955 rank = (*it).second;
2953 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", 2956 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank",
2954 rank, kPageVisitStatsMaxTopSites + 1); 2957 rank, kPageVisitStatsMaxTopSites + 1);
2955 } 2958 }
2956 #endif 2959 #endif
2957 2960
2958 } // namespace history 2961 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.h ('k') | chrome/browser/history/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698