| OLD | NEW | 
|    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 // The InMemoryHistoryBackend is a wrapper around the in-memory URL database. |    5 // The InMemoryHistoryBackend is a wrapper around the in-memory URL database. | 
|    6 // It maintains an in-memory cache of a subset of history that is required for |    6 // It maintains an in-memory cache of a subset of history that is required for | 
|    7 // low-latency operations, such as in-line autocomplete. |    7 // low-latency operations, such as in-line autocomplete. | 
|    8 // |    8 // | 
|    9 // The in-memory cache provides the following guarantees: |    9 // The in-memory cache provides the following guarantees: | 
|   10 //  (1.) It will always contain URLRows that either have a |typed_count| > 0; or |   10 //  (1.) It will always contain URLRows that either have a |typed_count| > 0; or | 
|   11 //       that have a corresponding search term, in which case information about |   11 //       that have a corresponding search term, in which case information about | 
|   12 //       the search term is also stored. |   12 //       the search term is also stored. | 
|   13 //  (2.) It will be an actual subset, i.e., it will contain verbatim data, and |   13 //  (2.) It will be an actual subset, i.e., it will contain verbatim data, and | 
|   14 //       will never contain more data that can be found in the main database. |   14 //       will never contain more data that can be found in the main database. | 
|   15 // |   15 // | 
|   16 // The InMemoryHistoryBackend is created on the history thread and passed to the |   16 // The InMemoryHistoryBackend is created on the history thread and passed to the | 
|   17 // main thread where operations can be completed synchronously. It listens for |   17 // main thread where operations can be completed synchronously. It listens for | 
|   18 // notifications from the "regular" history backend and keeps itself in sync. |   18 // notifications from the "regular" history backend and keeps itself in sync. | 
|   19  |   19  | 
|   20 #ifndef CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_ |   20 #ifndef CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_ | 
|   21 #define CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_ |   21 #define CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_ | 
|   22  |   22  | 
|   23 #include <string> |   23 #include <string> | 
|   24  |   24  | 
|   25 #include "base/basictypes.h" |   25 #include "base/basictypes.h" | 
|   26 #include "base/gtest_prod_util.h" |   26 #include "base/gtest_prod_util.h" | 
|   27 #include "base/memory/scoped_ptr.h" |   27 #include "base/memory/scoped_ptr.h" | 
 |   28 #include "components/history/core/browser/history_service_observer.h" | 
|   28 #include "components/history/core/browser/keyword_id.h" |   29 #include "components/history/core/browser/keyword_id.h" | 
|   29 #include "content/public/browser/notification_observer.h" |   30 #include "content/public/browser/notification_observer.h" | 
|   30 #include "content/public/browser/notification_registrar.h" |   31 #include "content/public/browser/notification_registrar.h" | 
|   31  |   32  | 
 |   33 class HistoryService; | 
|   32 class Profile; |   34 class Profile; | 
|   33  |   35  | 
|   34 namespace base { |   36 namespace base { | 
|   35 class FilePath; |   37 class FilePath; | 
|   36 } |   38 } | 
|   37  |   39  | 
|   38 namespace history { |   40 namespace history { | 
|   39  |   41  | 
|   40 class InMemoryDatabase; |   42 class InMemoryDatabase; | 
|   41 struct KeywordSearchUpdatedDetails; |   43 struct KeywordSearchUpdatedDetails; | 
|   42 struct KeywordSearchDeletedDetails; |   44 struct KeywordSearchDeletedDetails; | 
|   43 class URLDatabase; |   45 class URLDatabase; | 
|   44 class URLRow; |   46 class URLRow; | 
|   45 struct URLsDeletedDetails; |   47 struct URLsDeletedDetails; | 
|   46 struct URLsModifiedDetails; |   48 struct URLsModifiedDetails; | 
|   47  |   49  | 
|   48 class InMemoryHistoryBackend : public content::NotificationObserver { |   50 class InMemoryHistoryBackend : public HistoryServiceObserver, | 
 |   51                                public content::NotificationObserver { | 
|   49  public: |   52  public: | 
|   50   InMemoryHistoryBackend(); |   53   InMemoryHistoryBackend(); | 
|   51   virtual ~InMemoryHistoryBackend(); |   54   virtual ~InMemoryHistoryBackend(); | 
|   52  |   55  | 
|   53   // Initializes the backend from the history database pointed to by the |   56   // Initializes the backend from the history database pointed to by the | 
|   54   // full path in |history_filename|. |   57   // full path in |history_filename|. | 
|   55   bool Init(const base::FilePath& history_filename); |   58   bool Init(const base::FilePath& history_filename); | 
|   56  |   59  | 
|   57   // Does initialization work when this object is attached to the history |   60   // Does initialization work when this object is attached to the history | 
|   58   // system on the main thread. The argument is the profile with which the |   61   // system on the main thread. The argument is the profile with which the | 
|   59   // attached history service is under. |   62   // attached history service is under. | 
|   60   void AttachToHistoryService(Profile* profile); |   63   void AttachToHistoryService(Profile* profile, | 
 |   64                               HistoryService* history_service); | 
|   61  |   65  | 
|   62   // Deletes all search terms for the specified keyword. |   66   // Deletes all search terms for the specified keyword. | 
|   63   void DeleteAllSearchTermsForKeyword(KeywordID keyword_id); |   67   void DeleteAllSearchTermsForKeyword(KeywordID keyword_id); | 
|   64  |   68  | 
|   65   // Returns the underlying database associated with this backend. The current |   69   // Returns the underlying database associated with this backend. The current | 
|   66   // autocomplete code was written fro this, but it should probably be removed |   70   // autocomplete code was written fro this, but it should probably be removed | 
|   67   // so that it can deal directly with this object, rather than the DB. |   71   // so that it can deal directly with this object, rather than the DB. | 
|   68   InMemoryDatabase* db() const { |   72   InMemoryDatabase* db() const { | 
|   69     return db_.get(); |   73     return db_.get(); | 
|   70   } |   74   } | 
|   71  |   75  | 
 |   76   // HistoryServiceObserver: | 
 |   77   virtual void OnURLVisited(HistoryService* history_service, | 
 |   78                             ui::PageTransition transition, | 
 |   79                             const URLRow& row, | 
 |   80                             const RedirectList& redirects, | 
 |   81                             base::Time visit_time) OVERRIDE; | 
 |   82  | 
|   72   // Notification callback. |   83   // Notification callback. | 
|   73   virtual void Observe(int type, |   84   virtual void Observe(int type, | 
|   74                        const content::NotificationSource& source, |   85                        const content::NotificationSource& source, | 
|   75                        const content::NotificationDetails& details) override; |   86                        const content::NotificationDetails& details) override; | 
|   76  |   87  | 
|   77  private: |   88  private: | 
|   78   FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll); |   89   FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, DeleteAll); | 
|   79  |   90  | 
|   80   // Handler for HISTORY_URL_VISITED and HISTORY_URLS_MODIFIED. |   91   // Handler for HISTORY_URL_VISITED and HISTORY_URLS_MODIFIED. | 
|   81   void OnURLVisitedOrModified(const URLRow& url_row); |   92   void OnURLVisitedOrModified(const URLRow& url_row); | 
|   82  |   93  | 
|   83   // Handler for HISTORY_URLS_DELETED. |   94   // Handler for HISTORY_URLS_DELETED. | 
|   84   void OnURLsDeleted(const URLsDeletedDetails& details); |   95   void OnURLsDeleted(const URLsDeletedDetails& details); | 
|   85  |   96  | 
|   86   // Handler for HISTORY_KEYWORD_SEARCH_TERM_UPDATED. |   97   // Handler for HISTORY_KEYWORD_SEARCH_TERM_UPDATED. | 
|   87   void OnKeywordSearchTermUpdated(const KeywordSearchUpdatedDetails& details); |   98   void OnKeywordSearchTermUpdated(const KeywordSearchUpdatedDetails& details); | 
|   88  |   99  | 
|   89   // Handler for HISTORY_KEYWORD_SEARCH_TERM_DELETED. |  100   // Handler for HISTORY_KEYWORD_SEARCH_TERM_DELETED. | 
|   90   void OnKeywordSearchTermDeleted(const KeywordSearchDeletedDetails& details); |  101   void OnKeywordSearchTermDeleted(const KeywordSearchDeletedDetails& details); | 
|   91  |  102  | 
|   92   content::NotificationRegistrar registrar_; |  103   content::NotificationRegistrar registrar_; | 
|   93  |  104  | 
|   94   scoped_ptr<InMemoryDatabase> db_; |  105   scoped_ptr<InMemoryDatabase> db_; | 
|   95  |  106  | 
|   96   // The profile that this object is attached. May be NULL before |  107   // The profile that this object is attached. May be NULL before | 
|   97   // initialization. |  108   // initialization. | 
|   98   Profile* profile_; |  109   Profile* profile_; | 
 |  110   HistoryService* history_service_; | 
|   99  |  111  | 
|  100   DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackend); |  112   DISALLOW_COPY_AND_ASSIGN(InMemoryHistoryBackend); | 
|  101 }; |  113 }; | 
|  102  |  114  | 
|  103 }  // namespace history |  115 }  // namespace history | 
|  104  |  116  | 
|  105 #endif  // CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_ |  117 #endif  // CHROME_BROWSER_HISTORY_IN_MEMORY_HISTORY_BACKEND_H_ | 
| OLD | NEW |