Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / history_service.h
index 40e1df5..aaedce4 100644 (file)
@@ -18,6 +18,7 @@
 #include "base/memory/weak_ptr.h"
 #include "base/observer_list.h"
 #include "base/strings/string16.h"
+#include "base/task/cancelable_task_tracker.h"
 #include "base/threading/thread_checker.h"
 #include "base/time/time.h"
 #include "chrome/browser/common/cancelable_request.h"
@@ -26,9 +27,8 @@
 #include "chrome/browser/history/history_types.h"
 #include "chrome/browser/history/typed_url_syncable_service.h"
 #include "chrome/browser/search_engines/template_url_id.h"
-#include "chrome/common/cancelable_task_tracker.h"
 #include "chrome/common/ref_counted_util.h"
-#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
+#include "components/keyed_service/core/keyed_service.h"
 #include "components/visitedlink/browser/visitedlink_delegate.h"
 #include "content/public/browser/download_manager_delegate.h"
 #include "content/public/browser/notification_observer.h"
@@ -85,7 +85,7 @@ struct HistoryDetails;
 class HistoryService : public CancelableRequestProvider,
                        public content::NotificationObserver,
                        public syncer::SyncableService,
-                       public BrowserContextKeyedService,
+                       public KeyedService,
                        public visitedlink::VisitedLinkDelegate {
  public:
   // Miscellaneous commonly-used types.
@@ -114,11 +114,6 @@ class HistoryService : public CancelableRequestProvider,
   // Returns true if the backend has finished loading.
   bool backend_loaded() const { return backend_loaded_; }
 
-  // Unloads the backend without actually shutting down the history service.
-  // This can be used to temporarily reduce the browser process' memory
-  // footprint.
-  void UnloadBackend();
-
   // Called on shutdown, this will tell the history backend to complete and
   // will release pointers to it. No other functions should be called once
   // cleanup has happened that may dispatch to the history thread (because it
@@ -169,7 +164,7 @@ class HistoryService : public CancelableRequestProvider,
     return in_memory_url_index_.get();
   }
 
-  // BrowserContextKeyedService:
+  // KeyedService:
   virtual void Shutdown() OVERRIDE;
 
   // Navigation ----------------------------------------------------------------
@@ -274,15 +269,18 @@ class HistoryService : public CancelableRequestProvider,
 
   // Called when the results of QueryRedirectsFrom are available.
   // The given vector will contain a list of all redirects, not counting
-  // the original page. If A redirects to B, the vector will contain only B,
-  // and A will be in 'source_url'.
+  // the original page. If A redirects to B which redirects to C, the vector
+  // will contain [B, C], and A will be in 'from_url'.
+  //
+  // For QueryRedirectsTo, the order is reversed. For A->B->C, the vector will
+  // contain [B, A] and C will be in 'to_url'.
   //
   // If there is no such URL in the database or the most recent visit has no
   // redirect, the vector will be empty. If the history system failed for
   // some reason, success will additionally be false. If the given page
   // has redirected to multiple destinations, this will pick a random one.
   typedef base::Callback<void(Handle,
-                              GURL,  // from_url
+                              GURL,  // from_url / to_url
                               bool,  // success
                               history::RedirectList*)> QueryRedirectsCallback;
 
@@ -382,7 +380,7 @@ class HistoryService : public CancelableRequestProvider,
                             base::Time begin_time,
                             base::Time end_time,
                             const base::Closure& callback,
-                            CancelableTaskTracker* tracker);
+                            base::CancelableTaskTracker* tracker);
 
   // Removes all visits to specified URLs in specific time ranges.
   // This is the equivalent ExpireHistoryBetween() once for each element in the
@@ -390,17 +388,16 @@ class HistoryService : public CancelableRequestProvider,
   // of ExpireHistoryBetween().
   void ExpireHistory(const std::vector<history::ExpireHistoryArgs>& expire_list,
                      const base::Closure& callback,
-                     CancelableTaskTracker* tracker);
+                     base::CancelableTaskTracker* tracker);
 
   // Removes all visits to the given URLs in the specified time range. Calls
   // ExpireHistoryBetween() to delete local visits, and handles deletion of
   // synced visits if appropriate.
-  void ExpireLocalAndRemoteHistoryBetween(
-      const std::set<GURL>& restrict_urls,
-      base::Time begin_time,
-      base::Time end_time,
-      const base::Closure& callback,
-      CancelableTaskTracker* tracker);
+  void ExpireLocalAndRemoteHistoryBetween(const std::set<GURL>& restrict_urls,
+                                          base::Time begin_time,
+                                          base::Time end_time,
+                                          const base::Closure& callback,
+                                          base::CancelableTaskTracker* tracker);
 
   // Processes the given |delete_directive| and sends it to the
   // SyncChangeProcessor (if it exists).  Returns any error resulting
@@ -632,18 +629,13 @@ class HistoryService : public CancelableRequestProvider,
 
   // Broadcasts the given notification. This is called by the backend so that
   // the notification will be broadcast on the main thread.
-  //
-  // Compared to BroadcastNotifications(), this function does not take
-  // ownership of |details|.
-  void BroadcastNotificationsHelper(int type,
-                                    history::HistoryDetails* details);
-
-  // Initializes the backend.
-  void LoadBackendIfNecessary();
+  void BroadcastNotificationsHelper(
+      int type,
+      scoped_ptr<history::HistoryDetails> details);
 
   // Notification from the backend that it has finished loading. Sends
   // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true.
-  void OnDBLoaded(int backend_id);
+  void OnDBLoaded();
 
   // Helper function for getting URL information.
   // Reads a URLRow from in-memory database. Returns false if database is not
@@ -666,13 +658,13 @@ class HistoryService : public CancelableRequestProvider,
   // If |icon_types| has several types, results for only a single type will be
   // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and
   // FAVICON.
-  CancelableTaskTracker::TaskId GetFavicons(
+  base::CancelableTaskTracker::TaskId GetFavicons(
       const std::vector<GURL>& icon_urls,
       int icon_types,
       int desired_size_in_dip,
       const std::vector<ui::ScaleFactor>& desired_scale_factors,
       const FaviconService::FaviconResultsCallback& callback,
-      CancelableTaskTracker* tracker);
+      base::CancelableTaskTracker* tracker);
 
   // Used by the FaviconService to get favicons mapped to |page_url| for
   // |icon_types| which most closely match |desired_size_in_dip| and
@@ -683,13 +675,13 @@ class HistoryService : public CancelableRequestProvider,
   // there will be less results. If |icon_types| has several types, results for
   // only a single type will be returned in the priority of
   // TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and FAVICON.
-  CancelableTaskTracker::TaskId GetFaviconsForURL(
+  base::CancelableTaskTracker::TaskId GetFaviconsForURL(
       const GURL& page_url,
       int icon_types,
       int desired_size_in_dip,
       const std::vector<ui::ScaleFactor>& desired_scale_factors,
       const FaviconService::FaviconResultsCallback& callback,
-      CancelableTaskTracker* tracker);
+      base::CancelableTaskTracker* tracker);
 
   // Used by FaviconService to find the first favicon bitmap whose width and
   // height are greater than that of |minimum_size_in_pixels|. This searches
@@ -702,23 +694,23 @@ class HistoryService : public CancelableRequestProvider,
   // icon types in |icon_types| is returned.
   // This feature is especially useful when some types of icon is perfered as
   // long as its size is larger than a specific value.
-  CancelableTaskTracker::TaskId GetLargestFaviconForURL(
+  base::CancelableTaskTracker::TaskId GetLargestFaviconForURL(
       const GURL& page_url,
       const std::vector<int>& icon_types,
       int minimum_size_in_pixels,
       const FaviconService::FaviconRawCallback& callback,
-      CancelableTaskTracker* tracker);
+      base::CancelableTaskTracker* tracker);
 
   // Used by the FaviconService to get the favicon bitmap which most closely
   // matches |desired_size_in_dip| and |desired_scale_factor| from the favicon
   // with |favicon_id| from the history backend. If |desired_size_in_dip| is 0,
   // the largest favicon bitmap for |favicon_id| is returned.
-  CancelableTaskTracker::TaskId GetFaviconForID(
-      chrome::FaviconID favicon_id,
+  base::CancelableTaskTracker::TaskId GetFaviconForID(
+      favicon_base::FaviconID favicon_id,
       int desired_size_in_dip,
       ui::ScaleFactor desired_scale_factor,
       const FaviconService::FaviconResultsCallback& callback,
-      CancelableTaskTracker* tracker);
+      base::CancelableTaskTracker* tracker);
 
   // Used by the FaviconService to replace the favicon mappings to |page_url|
   // for |icon_types| on the history backend.
@@ -739,14 +731,14 @@ class HistoryService : public CancelableRequestProvider,
   // and |desired_scale_factors| from the favicons which were just mapped
   // to |page_url| are returned. If |desired_size_in_dip| is 0, the
   // largest favicon bitmap is returned.
-  CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch(
+  base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch(
       const GURL& page_url,
       const std::vector<GURL>& icon_urls,
       int icon_types,
       int desired_size_in_dip,
       const std::vector<ui::ScaleFactor>& desired_scale_factors,
       const FaviconService::FaviconResultsCallback& callback,
-      CancelableTaskTracker* tracker);
+      base::CancelableTaskTracker* tracker);
 
   // Used by FaviconService to set a favicon for |page_url| and |icon_url| with
   // |pixel_size|.
@@ -770,7 +762,7 @@ class HistoryService : public CancelableRequestProvider,
   // TODO(pkotwicz): Remove once no longer required by sync.
   void MergeFavicon(const GURL& page_url,
                     const GURL& icon_url,
-                    chrome::IconType icon_type,
+                    favicon_base::IconType icon_type,
                     scoped_refptr<base::RefCountedMemory> bitmap_data,
                     const gfx::Size& pixel_size);
 
@@ -787,8 +779,8 @@ class HistoryService : public CancelableRequestProvider,
   // criteria for |favicon_bitmap_data| to be valid.
   void SetFavicons(
       const GURL& page_url,
-      chrome::IconType icon_type,
-      const std::vector<chrome::FaviconBitmapData>& favicon_bitmap_data);
+      favicon_base::IconType icon_type,
+      const std::vector<favicon_base::FaviconBitmapData>& favicon_bitmap_data);
 
   // Used by the FaviconService to mark the favicon for the page as being out
   // of date.
@@ -807,11 +799,10 @@ class HistoryService : public CancelableRequestProvider,
   // Sets the in-memory URL database. This is called by the backend once the
   // database is loaded to make it available.
   void SetInMemoryBackend(
-      int backend_id,
       scoped_ptr<history::InMemoryHistoryBackend> mem_backend);
 
   // Called by our BackendDelegate when there is a problem reading the database.
-  void NotifyProfileError(int backend_id, sql::InitStatus init_status);
+  void NotifyProfileError(sql::InitStatus init_status);
 
   // Call to schedule a given task for running on the history thread with the
   // specified priority. The task will have ownership taken.
@@ -830,7 +821,6 @@ class HistoryService : public CancelableRequestProvider,
                   RequestType* request) {
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     if (consumer)
       AddRequest(request, consumer);
     ScheduleTask(priority,
@@ -847,7 +837,6 @@ class HistoryService : public CancelableRequestProvider,
                   const ArgA& a) {
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     if (consumer)
       AddRequest(request, consumer);
     ScheduleTask(priority,
@@ -868,7 +857,6 @@ class HistoryService : public CancelableRequestProvider,
                   const ArgB& b) {
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     if (consumer)
       AddRequest(request, consumer);
     ScheduleTask(priority,
@@ -891,7 +879,6 @@ class HistoryService : public CancelableRequestProvider,
                   const ArgC& c) {
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     if (consumer)
       AddRequest(request, consumer);
     ScheduleTask(priority,
@@ -916,7 +903,6 @@ class HistoryService : public CancelableRequestProvider,
                   const ArgD& d) {
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     if (consumer)
       AddRequest(request, consumer);
     ScheduleTask(priority,
@@ -935,7 +921,6 @@ class HistoryService : public CancelableRequestProvider,
                          BackendFunc func) {  // Function to call on backend.
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     ScheduleTask(priority, base::Bind(func, history_backend_.get()));
   }
 
@@ -945,7 +930,6 @@ class HistoryService : public CancelableRequestProvider,
                          const ArgA& a) {
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     ScheduleTask(priority, base::Bind(func, history_backend_.get(), a));
   }
 
@@ -956,7 +940,6 @@ class HistoryService : public CancelableRequestProvider,
                          const ArgB& b) {
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     ScheduleTask(priority, base::Bind(func, history_backend_.get(), a, b));
   }
 
@@ -968,7 +951,6 @@ class HistoryService : public CancelableRequestProvider,
                          const ArgC& c) {
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     ScheduleTask(priority, base::Bind(func, history_backend_.get(), a, b, c));
   }
 
@@ -985,7 +967,6 @@ class HistoryService : public CancelableRequestProvider,
                          const ArgD& d) {
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     ScheduleTask(priority, base::Bind(func, history_backend_.get(),
                                       a, b, c, d));
   }
@@ -1005,7 +986,6 @@ class HistoryService : public CancelableRequestProvider,
                          const ArgE& e) {
     DCHECK(thread_) << "History service being called after cleanup";
     DCHECK(thread_checker_.CalledOnValidThread());
-    LoadBackendIfNecessary();
     ScheduleTask(priority, base::Bind(func, history_backend_.get(),
                                       a, b, c, d, e));
   }
@@ -1050,10 +1030,6 @@ class HistoryService : public CancelableRequestProvider,
   // completed.
   bool backend_loaded_;
 
-  // The id of the current backend. This is only valid when history_backend_
-  // is not NULL.
-  int current_backend_id_;
-
   // Cached values from Init(), used whenever we need to reload the backend.
   base::FilePath history_dir_;
   BookmarkService* bookmark_service_;