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

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

Issue 267019: Add the ability to unload the HistoryBackend.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « chrome/browser/cocoa/history_menu_bridge.mm ('k') | chrome/browser/history/history.cc » ('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) 2006-2008 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 #ifndef CHROME_BROWSER_HISTORY_HISTORY_H__ 5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_H__
6 #define CHROME_BROWSER_HISTORY_HISTORY_H__ 6 #define CHROME_BROWSER_HISTORY_HISTORY_H__
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/file_path.h"
12 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
13 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
14 #include "base/task.h" 15 #include "base/task.h"
15 #include "chrome/browser/cancelable_request.h" 16 #include "chrome/browser/cancelable_request.h"
16 #include "chrome/browser/favicon_service.h" 17 #include "chrome/browser/favicon_service.h"
17 #include "chrome/browser/history/history_notifications.h" 18 #include "chrome/browser/history/history_notifications.h"
18 #include "chrome/browser/history/history_types.h" 19 #include "chrome/browser/history/history_types.h"
19 #include "chrome/browser/search_engines/template_url.h" 20 #include "chrome/browser/search_engines/template_url.h"
20 #include "chrome/common/notification_registrar.h" 21 #include "chrome/common/notification_registrar.h"
21 #include "chrome/common/page_transition_types.h" 22 #include "chrome/common/page_transition_types.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // The empty constructor is provided only for testing. 96 // The empty constructor is provided only for testing.
96 HistoryService(); 97 HistoryService();
97 ~HistoryService(); 98 ~HistoryService();
98 99
99 // Initializes the history service, returning true on success. On false, do 100 // Initializes the history service, returning true on success. On false, do
100 // not call any other functions. The given directory will be used for storing 101 // not call any other functions. The given directory will be used for storing
101 // the history files. The BookmarkService is used when deleting URLs to 102 // the history files. The BookmarkService is used when deleting URLs to
102 // test if a URL is bookmarked; it may be NULL during testing. 103 // test if a URL is bookmarked; it may be NULL during testing.
103 bool Init(const FilePath& history_dir, BookmarkService* bookmark_service); 104 bool Init(const FilePath& history_dir, BookmarkService* bookmark_service);
104 105
105 // Did the backend finish loading the databases? 106 // Triggers the backend to load if it hasn't already, and then returns whether
106 bool backend_loaded() const { return backend_loaded_; } 107 // it's finished loading.
108 bool BackendLoaded();
109
110 // Unloads the backend without actually shutting down the history service.
111 // This can be used to temporarily reduce the browser process' memory
112 // footprint.
113 void UnloadBackend();
107 114
108 // Called on shutdown, this will tell the history backend to complete and 115 // Called on shutdown, this will tell the history backend to complete and
109 // will release pointers to it. No other functions should be called once 116 // will release pointers to it. No other functions should be called once
110 // cleanup has happened that may dispatch to the history thread (because it 117 // cleanup has happened that may dispatch to the history thread (because it
111 // will be NULL). 118 // will be NULL).
112 // 119 //
113 // In practice, this will be called by the service manager (BrowserProcess) 120 // In practice, this will be called by the service manager (BrowserProcess)
114 // when it is being destroyed. Because that reference is being destroyed, it 121 // when it is being destroyed. Because that reference is being destroyed, it
115 // should be impossible for anybody else to call the service, even if it is 122 // should be impossible for anybody else to call the service, even if it is
116 // still in memory (pending requests may be holding a reference to us). 123 // still in memory (pending requests may be holding a reference to us).
117 void Cleanup(); 124 void Cleanup();
118 125
119 // RenderProcessHost pointers are used to scope page IDs (see AddPage). These 126 // RenderProcessHost pointers are used to scope page IDs (see AddPage). These
120 // objects must tell us when they are being destroyed so that we can clear 127 // objects must tell us when they are being destroyed so that we can clear
121 // out any cached data associated with that scope. 128 // out any cached data associated with that scope.
122 // 129 //
123 // The given pointer will not be dereferenced, it is only used for 130 // The given pointer will not be dereferenced, it is only used for
124 // identification purposes, hence it is a void*. 131 // identification purposes, hence it is a void*.
125 void NotifyRenderProcessHostDestruction(const void* host); 132 void NotifyRenderProcessHostDestruction(const void* host);
126 133
127 // Returns the in-memory URL database. The returned pointer MAY BE NULL if 134 // Triggers the backend to load if it hasn't already, and then returns the
128 // the in-memory database has not been loaded yet. This pointer is owned 135 // in-memory URL database. The returned pointer MAY BE NULL if the in-memory
129 // by the history system. Callers should not store or cache this value. 136 // database has not been loaded yet. This pointer is owned by the history
137 // system. Callers should not store or cache this value.
130 // 138 //
131 // TODO(brettw) this should return the InMemoryHistoryBackend. 139 // TODO(brettw) this should return the InMemoryHistoryBackend.
132 history::URLDatabase* in_memory_database() const; 140 history::URLDatabase* InMemoryDatabase();
133 141
134 // Navigation ---------------------------------------------------------------- 142 // Navigation ----------------------------------------------------------------
135 143
136 // Adds the given canonical URL to history with the current time as the visit 144 // Adds the given canonical URL to history with the current time as the visit
137 // time. Referrer may be the empty string. 145 // time. Referrer may be the empty string.
138 // 146 //
139 // The supplied render process host is used to scope the given page ID. Page 147 // The supplied render process host is used to scope the given page ID. Page
140 // IDs are only unique inside a given render process, so we need that to 148 // IDs are only unique inside a given render process, so we need that to
141 // differentiate them. This pointer should not be dereferenced by the history 149 // differentiate them. This pointer should not be dereferenced by the history
142 // system. Since render view host pointers may be reused (if one gets deleted 150 // system. Since render view host pointers may be reused (if one gets deleted
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 // Broadcasts the given notification. This is called by the backend so that 554 // Broadcasts the given notification. This is called by the backend so that
547 // the notification will be broadcast on the main thread. 555 // the notification will be broadcast on the main thread.
548 // 556 //
549 // The |details_deleted| pointer will be sent as the "details" for the 557 // The |details_deleted| pointer will be sent as the "details" for the
550 // notification. The function takes ownership of the pointer and deletes it 558 // notification. The function takes ownership of the pointer and deletes it
551 // when the notification is sent (it is coming from another thread, so must 559 // when the notification is sent (it is coming from another thread, so must
552 // be allocated on the heap). 560 // be allocated on the heap).
553 void BroadcastNotifications(NotificationType type, 561 void BroadcastNotifications(NotificationType type,
554 history::HistoryDetails* details_deleted); 562 history::HistoryDetails* details_deleted);
555 563
564 // Initializes the backend.
565 void LoadBackendIfNecessary();
566
556 // Notification from the backend that it has finished loading. Sends 567 // Notification from the backend that it has finished loading. Sends
557 // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true. 568 // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true.
558 void OnDBLoaded(); 569 void OnDBLoaded();
559 570
560 // Returns true if this looks like the type of URL we want to add to the 571 // Returns true if this looks like the type of URL we want to add to the
561 // history. We filter out some URLs such as JavaScript. 572 // history. We filter out some URLs such as JavaScript.
562 bool CanAddURL(const GURL& url) const; 573 bool CanAddURL(const GURL& url) const;
563 574
564 // FavIcon ------------------------------------------------------------------- 575 // FavIcon -------------------------------------------------------------------
565 576
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // read properly. 617 // read properly.
607 void NotifyTooNew(); 618 void NotifyTooNew();
608 619
609 // Call to schedule a given task for running on the history thread with the 620 // Call to schedule a given task for running on the history thread with the
610 // specified priority. The task will have ownership taken. 621 // specified priority. The task will have ownership taken.
611 void ScheduleTask(SchedulePriority priority, Task* task); 622 void ScheduleTask(SchedulePriority priority, Task* task);
612 623
613 // Schedule ------------------------------------------------------------------ 624 // Schedule ------------------------------------------------------------------
614 // 625 //
615 // Functions for scheduling operations on the history thread that have a 626 // Functions for scheduling operations on the history thread that have a
616 // handle and are cancelable. For fire-and-forget operations, see 627 // handle and may be cancelable. For fire-and-forget operations, see
617 // ScheduleAndForget below. 628 // ScheduleAndForget below.
618 629
619 template<typename BackendFunc, class RequestType> 630 template<typename BackendFunc, class RequestType>
620 Handle Schedule(SchedulePriority priority, 631 Handle Schedule(SchedulePriority priority,
621 BackendFunc func, // Function to call on the HistoryBackend. 632 BackendFunc func, // Function to call on the HistoryBackend.
622 CancelableRequestConsumerBase* consumer, 633 CancelableRequestConsumerBase* consumer,
623 RequestType* request) { 634 RequestType* request) {
624 DCHECK(history_backend_) << "History service being called after cleanup"; 635 DCHECK(thread_) << "History service being called after cleanup";
625 AddRequest(request, consumer); 636 LoadBackendIfNecessary();
637 if (consumer)
638 AddRequest(request, consumer);
626 ScheduleTask(priority, 639 ScheduleTask(priority,
627 NewRunnableMethod(history_backend_.get(), func, 640 NewRunnableMethod(history_backend_.get(), func,
628 scoped_refptr<RequestType>(request))); 641 scoped_refptr<RequestType>(request)));
629 return request->handle(); 642 return request->handle();
630 } 643 }
631 644
632 template<typename BackendFunc, class RequestType, typename ArgA> 645 template<typename BackendFunc, class RequestType, typename ArgA>
633 Handle Schedule(SchedulePriority priority, 646 Handle Schedule(SchedulePriority priority,
634 BackendFunc func, // Function to call on the HistoryBackend. 647 BackendFunc func, // Function to call on the HistoryBackend.
635 CancelableRequestConsumerBase* consumer, 648 CancelableRequestConsumerBase* consumer,
636 RequestType* request, 649 RequestType* request,
637 const ArgA& a) { 650 const ArgA& a) {
638 DCHECK(history_backend_) << "History service being called after cleanup"; 651 DCHECK(thread_) << "History service being called after cleanup";
639 AddRequest(request, consumer); 652 LoadBackendIfNecessary();
653 if (consumer)
654 AddRequest(request, consumer);
640 ScheduleTask(priority, 655 ScheduleTask(priority,
641 NewRunnableMethod(history_backend_.get(), func, 656 NewRunnableMethod(history_backend_.get(), func,
642 scoped_refptr<RequestType>(request), 657 scoped_refptr<RequestType>(request),
643 a)); 658 a));
644 return request->handle(); 659 return request->handle();
645 } 660 }
646 661
647 template<typename BackendFunc, 662 template<typename BackendFunc,
648 class RequestType, // Descendant of CancelableRequstBase. 663 class RequestType, // Descendant of CancelableRequstBase.
649 typename ArgA, 664 typename ArgA,
650 typename ArgB> 665 typename ArgB>
651 Handle Schedule(SchedulePriority priority, 666 Handle Schedule(SchedulePriority priority,
652 BackendFunc func, // Function to call on the HistoryBackend. 667 BackendFunc func, // Function to call on the HistoryBackend.
653 CancelableRequestConsumerBase* consumer, 668 CancelableRequestConsumerBase* consumer,
654 RequestType* request, 669 RequestType* request,
655 const ArgA& a, 670 const ArgA& a,
656 const ArgB& b) { 671 const ArgB& b) {
657 DCHECK(history_backend_) << "History service being called after cleanup"; 672 DCHECK(thread_) << "History service being called after cleanup";
658 AddRequest(request, consumer); 673 LoadBackendIfNecessary();
674 if (consumer)
675 AddRequest(request, consumer);
659 ScheduleTask(priority, 676 ScheduleTask(priority,
660 NewRunnableMethod(history_backend_.get(), func, 677 NewRunnableMethod(history_backend_.get(), func,
661 scoped_refptr<RequestType>(request), 678 scoped_refptr<RequestType>(request),
662 a, b)); 679 a, b));
663 return request->handle(); 680 return request->handle();
664 } 681 }
665 682
666 template<typename BackendFunc, 683 template<typename BackendFunc,
667 class RequestType, // Descendant of CancelableRequstBase. 684 class RequestType, // Descendant of CancelableRequstBase.
668 typename ArgA, 685 typename ArgA,
669 typename ArgB, 686 typename ArgB,
670 typename ArgC> 687 typename ArgC>
671 Handle Schedule(SchedulePriority priority, 688 Handle Schedule(SchedulePriority priority,
672 BackendFunc func, // Function to call on the HistoryBackend. 689 BackendFunc func, // Function to call on the HistoryBackend.
673 CancelableRequestConsumerBase* consumer, 690 CancelableRequestConsumerBase* consumer,
674 RequestType* request, 691 RequestType* request,
675 const ArgA& a, 692 const ArgA& a,
676 const ArgB& b, 693 const ArgB& b,
677 const ArgC& c) { 694 const ArgC& c) {
678 DCHECK(history_backend_) << "History service being called after cleanup"; 695 DCHECK(thread_) << "History service being called after cleanup";
679 AddRequest(request, consumer); 696 LoadBackendIfNecessary();
697 if (consumer)
698 AddRequest(request, consumer);
680 ScheduleTask(priority, 699 ScheduleTask(priority,
681 NewRunnableMethod(history_backend_.get(), func, 700 NewRunnableMethod(history_backend_.get(), func,
682 scoped_refptr<RequestType>(request), 701 scoped_refptr<RequestType>(request),
683 a, b, c)); 702 a, b, c));
684 return request->handle(); 703 return request->handle();
685 } 704 }
686 705
687 // ScheduleAndForget --------------------------------------------------------- 706 // ScheduleAndForget ---------------------------------------------------------
688 // 707 //
689 // Functions for scheduling operations on the history thread that do not need 708 // Functions for scheduling operations on the history thread that do not need
690 // any callbacks and are not cancelable. 709 // any callbacks and are not cancelable.
691 710
692 template<typename BackendFunc> 711 template<typename BackendFunc>
693 void ScheduleAndForget(SchedulePriority priority, 712 void ScheduleAndForget(SchedulePriority priority,
694 BackendFunc func) { // Function to call on backend. 713 BackendFunc func) { // Function to call on backend.
695 DCHECK(history_backend_) << "History service being called after cleanup"; 714 DCHECK(thread_) << "History service being called after cleanup";
715 LoadBackendIfNecessary();
696 ScheduleTask(priority, NewRunnableMethod(history_backend_.get(), func)); 716 ScheduleTask(priority, NewRunnableMethod(history_backend_.get(), func));
697 } 717 }
698 718
699 template<typename BackendFunc, typename ArgA> 719 template<typename BackendFunc, typename ArgA>
700 void ScheduleAndForget(SchedulePriority priority, 720 void ScheduleAndForget(SchedulePriority priority,
701 BackendFunc func, // Function to call on backend. 721 BackendFunc func, // Function to call on backend.
702 const ArgA& a) { 722 const ArgA& a) {
703 DCHECK(history_backend_) << "History service being called after cleanup"; 723 DCHECK(thread_) << "History service being called after cleanup";
724 LoadBackendIfNecessary();
704 ScheduleTask(priority, NewRunnableMethod(history_backend_.get(), func, a)); 725 ScheduleTask(priority, NewRunnableMethod(history_backend_.get(), func, a));
705 } 726 }
706 727
707 template<typename BackendFunc, typename ArgA, typename ArgB> 728 template<typename BackendFunc, typename ArgA, typename ArgB>
708 void ScheduleAndForget(SchedulePriority priority, 729 void ScheduleAndForget(SchedulePriority priority,
709 BackendFunc func, // Function to call on backend. 730 BackendFunc func, // Function to call on backend.
710 const ArgA& a, 731 const ArgA& a,
711 const ArgB& b) { 732 const ArgB& b) {
712 DCHECK(history_backend_) << "History service being called after cleanup"; 733 DCHECK(thread_) << "History service being called after cleanup";
734 LoadBackendIfNecessary();
713 ScheduleTask(priority, NewRunnableMethod(history_backend_.get(), func, 735 ScheduleTask(priority, NewRunnableMethod(history_backend_.get(), func,
714 a, b)); 736 a, b));
715 } 737 }
716 738
717 template<typename BackendFunc, typename ArgA, typename ArgB, typename ArgC> 739 template<typename BackendFunc, typename ArgA, typename ArgB, typename ArgC>
718 void ScheduleAndForget(SchedulePriority priority, 740 void ScheduleAndForget(SchedulePriority priority,
719 BackendFunc func, // Function to call on backend. 741 BackendFunc func, // Function to call on backend.
720 const ArgA& a, 742 const ArgA& a,
721 const ArgB& b, 743 const ArgB& b,
722 const ArgC& c) { 744 const ArgC& c) {
723 DCHECK(history_backend_) << "History service being called after cleanup"; 745 DCHECK(thread_) << "History service being called after cleanup";
746 LoadBackendIfNecessary();
724 ScheduleTask(priority, NewRunnableMethod(history_backend_.get(), func, 747 ScheduleTask(priority, NewRunnableMethod(history_backend_.get(), func,
725 a, b, c)); 748 a, b, c));
726 } 749 }
727 750
728 template<typename BackendFunc, 751 template<typename BackendFunc,
729 typename ArgA, 752 typename ArgA,
730 typename ArgB, 753 typename ArgB,
731 typename ArgC, 754 typename ArgC,
732 typename ArgD> 755 typename ArgD>
733 void ScheduleAndForget(SchedulePriority priority, 756 void ScheduleAndForget(SchedulePriority priority,
734 BackendFunc func, // Function to call on backend. 757 BackendFunc func, // Function to call on backend.
735 const ArgA& a, 758 const ArgA& a,
736 const ArgB& b, 759 const ArgB& b,
737 const ArgC& c, 760 const ArgC& c,
738 const ArgD& d) { 761 const ArgD& d) {
739 DCHECK(history_backend_) << "History service being called after cleanup"; 762 DCHECK(thread_) << "History service being called after cleanup";
763 LoadBackendIfNecessary();
740 ScheduleTask(priority, NewRunnableMethod(history_backend_.get(), func, 764 ScheduleTask(priority, NewRunnableMethod(history_backend_.get(), func,
741 a, b, c, d)); 765 a, b, c, d));
742 } 766 }
743 767
744 NotificationRegistrar registrar_; 768 NotificationRegistrar registrar_;
745 769
746 // Some void primitives require some internal processing in the main thread 770 // Some void primitives require some internal processing in the main thread
747 // when done. We use this internal consumer for this purpose. 771 // when done. We use this internal consumer for this purpose.
748 CancelableRequestConsumer internal_consumer_; 772 CancelableRequestConsumer internal_consumer_;
749 773
(...skipping 13 matching lines...) Expand all
763 // on the background thread. 787 // on the background thread.
764 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; 788 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_;
765 789
766 // The profile, may be null when testing. 790 // The profile, may be null when testing.
767 Profile* profile_; 791 Profile* profile_;
768 792
769 // Has the backend finished loading? The backend is loaded once Init has 793 // Has the backend finished loading? The backend is loaded once Init has
770 // completed. 794 // completed.
771 bool backend_loaded_; 795 bool backend_loaded_;
772 796
773 DISALLOW_EVIL_CONSTRUCTORS(HistoryService); 797 // Cached values from Init(), used whenever we need to reload the backend.
798 FilePath history_dir_;
799 BookmarkService* bookmark_service_;
800
801 DISALLOW_COPY_AND_ASSIGN(HistoryService);
774 }; 802 };
775 803
776 #endif // CHROME_BROWSER_HISTORY_HISTORY_H__ 804 #endif // CHROME_BROWSER_HISTORY_HISTORY_H__
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/history_menu_bridge.mm ('k') | chrome/browser/history/history.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698