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

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

Issue 343067: Unittest for fix to allow navigation when there is no history DB.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/history/history.h ('k') | chrome/browser/history/history_backend.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // The history system runs on a background thread so that potentially slow 5 // The history system runs on a background thread so that potentially slow
6 // database operations don't delay the browser. This backend processing is 6 // database operations don't delay the browser. This backend processing is
7 // represented by HistoryBackend. The HistoryService's job is to dispatch to 7 // represented by HistoryBackend. The HistoryService's job is to dispatch to
8 // that thread. 8 // that thread.
9 // 9 //
10 // Main thread History thread 10 // Main thread History thread
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 scoped_refptr<HistoryService> history_service_; 123 scoped_refptr<HistoryService> history_service_;
124 MessageLoop* message_loop_; 124 MessageLoop* message_loop_;
125 }; 125 };
126 126
127 // static 127 // static
128 const history::StarID HistoryService::kBookmarkBarID = 1; 128 const history::StarID HistoryService::kBookmarkBarID = 1;
129 129
130 HistoryService::HistoryService() 130 HistoryService::HistoryService()
131 : thread_(new ChromeHistoryThread()), 131 : thread_(new ChromeHistoryThread()),
132 profile_(NULL), 132 profile_(NULL),
133 backend_loaded_(false) { 133 backend_loaded_(false),
134 bookmark_service_(NULL),
135 no_db_(false) {
134 // Is NULL when running generate_profile. 136 // Is NULL when running generate_profile.
135 if (NotificationService::current()) { 137 if (NotificationService::current()) {
136 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, 138 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED,
137 Source<Profile>(profile_)); 139 Source<Profile>(profile_));
138 } 140 }
139 } 141 }
140 142
141 HistoryService::HistoryService(Profile* profile) 143 HistoryService::HistoryService(Profile* profile)
142 : thread_(new ChromeHistoryThread()), 144 : thread_(new ChromeHistoryThread()),
143 profile_(profile), 145 profile_(profile),
144 backend_loaded_(false) { 146 backend_loaded_(false),
147 bookmark_service_(NULL),
148 no_db_(false) {
145 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, 149 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED,
146 Source<Profile>(profile_)); 150 Source<Profile>(profile_));
147 } 151 }
148 152
149 HistoryService::~HistoryService() { 153 HistoryService::~HistoryService() {
150 // Shutdown the backend. This does nothing if Cleanup was already invoked. 154 // Shutdown the backend. This does nothing if Cleanup was already invoked.
151 Cleanup(); 155 Cleanup();
152 } 156 }
153 157
154 bool HistoryService::Init(const FilePath& history_dir,
155 BookmarkService* bookmark_service) {
156 if (!thread_->Start()) {
157 Cleanup();
158 return false;
159 }
160
161 history_dir_ = history_dir;
162 bookmark_service_ = bookmark_service;
163
164 // Create the history backend.
165 LoadBackendIfNecessary();
166 return true;
167 }
168
169 bool HistoryService::BackendLoaded() { 158 bool HistoryService::BackendLoaded() {
170 // NOTE: We start the backend loading even though it completes asynchronously 159 // NOTE: We start the backend loading even though it completes asynchronously
171 // and thus won't affect the return value of this function. This is because 160 // and thus won't affect the return value of this function. This is because
172 // callers of this assume that if the backend isn't yet loaded it will be 161 // callers of this assume that if the backend isn't yet loaded it will be
173 // soon, so they will either listen for notifications or just retry this call 162 // soon, so they will either listen for notifications or just retry this call
174 // later. If we've purged the backend, we haven't necessarily restarted it 163 // later. If we've purged the backend, we haven't necessarily restarted it
175 // loading by now, so we need to trigger the load in order to maintain that 164 // loading by now, so we need to trigger the load in order to maintain that
176 // expectation. 165 // expectation.
177 LoadBackendIfNecessary(); 166 LoadBackendIfNecessary();
178 return backend_loaded_; 167 return backend_loaded_;
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 Details<history::URLsDeletedDetails> deleted_details(details); 602 Details<history::URLsDeletedDetails> deleted_details(details);
614 VisitedLinkMaster* visited_links = profile_->GetVisitedLinkMaster(); 603 VisitedLinkMaster* visited_links = profile_->GetVisitedLinkMaster();
615 if (!visited_links) 604 if (!visited_links)
616 return; // Nobody to update. 605 return; // Nobody to update.
617 if (deleted_details->all_history) 606 if (deleted_details->all_history)
618 visited_links->DeleteAllURLs(); 607 visited_links->DeleteAllURLs();
619 else // Delete individual ones. 608 else // Delete individual ones.
620 visited_links->DeleteURLs(deleted_details->urls); 609 visited_links->DeleteURLs(deleted_details->urls);
621 } 610 }
622 611
612 bool HistoryService::Init(const FilePath& history_dir,
613 BookmarkService* bookmark_service,
614 bool no_db) {
615 if (!thread_->Start()) {
616 Cleanup();
617 return false;
618 }
619
620 history_dir_ = history_dir;
621 bookmark_service_ = bookmark_service;
622 no_db_ = no_db;
623
624 // Create the history backend.
625 LoadBackendIfNecessary();
626 return true;
627 }
628
623 void HistoryService::ScheduleAutocomplete(HistoryURLProvider* provider, 629 void HistoryService::ScheduleAutocomplete(HistoryURLProvider* provider,
624 HistoryURLProviderParams* params) { 630 HistoryURLProviderParams* params) {
625 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::ScheduleAutocomplete, 631 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::ScheduleAutocomplete,
626 scoped_refptr<HistoryURLProvider>(provider), params); 632 scoped_refptr<HistoryURLProvider>(provider), params);
627 } 633 }
628 634
629 void HistoryService::ScheduleTask(SchedulePriority priority, 635 void HistoryService::ScheduleTask(SchedulePriority priority,
630 Task* task) { 636 Task* task) {
631 // FIXME(brettw) do prioritization. 637 // FIXME(brettw) do prioritization.
632 thread_->message_loop()->PostTask(FROM_HERE, task); 638 thread_->message_loop()->PostTask(FROM_HERE, task);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 void HistoryService::LoadBackendIfNecessary() { 721 void HistoryService::LoadBackendIfNecessary() {
716 if (!thread_ || history_backend_) 722 if (!thread_ || history_backend_)
717 return; // Failed to init, or already started loading. 723 return; // Failed to init, or already started loading.
718 724
719 scoped_refptr<HistoryBackend> backend( 725 scoped_refptr<HistoryBackend> backend(
720 new HistoryBackend(history_dir_, 726 new HistoryBackend(history_dir_,
721 new BackendDelegate(this), 727 new BackendDelegate(this),
722 bookmark_service_)); 728 bookmark_service_));
723 history_backend_.swap(backend); 729 history_backend_.swap(backend);
724 730
725 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init); 731 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init, no_db_);
726 } 732 }
727 733
728 void HistoryService::OnDBLoaded() { 734 void HistoryService::OnDBLoaded() {
729 LOG(INFO) << "History backend finished loading"; 735 LOG(INFO) << "History backend finished loading";
730 backend_loaded_ = true; 736 backend_loaded_ = true;
731 NotificationService::current()->Notify(NotificationType::HISTORY_LOADED, 737 NotificationService::current()->Notify(NotificationType::HISTORY_LOADED,
732 Source<Profile>(profile_), 738 Source<Profile>(profile_),
733 Details<HistoryService>(this)); 739 Details<HistoryService>(this));
734 } 740 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history.h ('k') | chrome/browser/history/history_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698