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 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback_list.h" | 14 #include "base/callback_list.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
18 #include "base/prefs/pref_change_registrar.h" | 18 #include "base/prefs/pref_change_registrar.h" |
19 #include "chrome/browser/webdata/web_data_service.h" | 19 #include "chrome/browser/webdata/keyword_web_data_service.h" |
20 #include "components/google/core/browser/google_url_tracker.h" | 20 #include "components/google/core/browser/google_url_tracker.h" |
21 #include "components/keyed_service/core/keyed_service.h" | 21 #include "components/keyed_service/core/keyed_service.h" |
22 #include "components/search_engines/default_search_manager.h" | 22 #include "components/search_engines/default_search_manager.h" |
| 23 #include "components/search_engines/template_url.h" |
23 #include "components/search_engines/template_url_id.h" | 24 #include "components/search_engines/template_url_id.h" |
| 25 #include "components/webdata/common/web_data_service_consumer.h" |
24 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
25 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
26 #include "sync/api/sync_change.h" | 28 #include "sync/api/sync_change.h" |
27 #include "sync/api/syncable_service.h" | 29 #include "sync/api/syncable_service.h" |
28 | 30 |
29 class GURL; | 31 class GURL; |
30 class PrefService; | 32 class PrefService; |
31 class Profile; | 33 class Profile; |
32 class SearchHostToURLsMap; | 34 class SearchHostToURLsMap; |
33 class SearchTermsData; | 35 class SearchTermsData; |
(...skipping 11 matching lines...) Expand all Loading... |
45 } | 47 } |
46 | 48 |
47 namespace history { | 49 namespace history { |
48 struct URLVisitedDetails; | 50 struct URLVisitedDetails; |
49 } | 51 } |
50 | 52 |
51 // TemplateURLService is the backend for keywords. It's used by | 53 // TemplateURLService is the backend for keywords. It's used by |
52 // KeywordAutocomplete. | 54 // KeywordAutocomplete. |
53 // | 55 // |
54 // TemplateURLService stores a vector of TemplateURLs. The TemplateURLs are | 56 // TemplateURLService stores a vector of TemplateURLs. The TemplateURLs are |
55 // persisted to the database maintained by WebDataService. *ALL* mutations | 57 // persisted to the database maintained by KeywordWebDataService. |
56 // to the TemplateURLs must funnel through TemplateURLService. This allows | 58 // *ALL* mutations to the TemplateURLs must funnel through TemplateURLService. |
57 // TemplateURLService to notify listeners of changes as well as keep the | 59 // This allows TemplateURLService to notify listeners of changes as well as keep |
58 // database in sync. | 60 // the database in sync. |
59 // | 61 // |
60 // There is a TemplateURLService per Profile. | 62 // There is a TemplateURLService per Profile. |
61 // | 63 // |
62 // TemplateURLService does not load the vector of TemplateURLs in its | 64 // TemplateURLService does not load the vector of TemplateURLs in its |
63 // constructor (except for testing). Use the Load method to trigger a load. | 65 // constructor (except for testing). Use the Load method to trigger a load. |
64 // When TemplateURLService has completed loading, observers are notified via | 66 // When TemplateURLService has completed loading, observers are notified via |
65 // OnTemplateURLServiceChanged, or by a callback registered prior to calling | 67 // OnTemplateURLServiceChanged, or by a callback registered prior to calling |
66 // the Load method. | 68 // the Load method. |
67 // | 69 // |
68 // TemplateURLService takes ownership of any TemplateURL passed to it. If there | 70 // TemplateURLService takes ownership of any TemplateURL passed to it. If there |
69 // is a WebDataService, deletion is handled by WebDataService, otherwise | 71 // is a KeywordWebDataService, deletion is handled by KeywordWebDataService, |
70 // TemplateURLService handles deletion. | 72 // otherwise TemplateURLService handles deletion. |
71 | 73 |
72 class TemplateURLService : public WebDataServiceConsumer, | 74 class TemplateURLService : public WebDataServiceConsumer, |
73 public KeyedService, | 75 public KeyedService, |
74 public content::NotificationObserver, | 76 public content::NotificationObserver, |
75 public syncer::SyncableService { | 77 public syncer::SyncableService { |
76 public: | 78 public: |
77 typedef std::map<std::string, std::string> QueryTerms; | 79 typedef std::map<std::string, std::string> QueryTerms; |
78 typedef std::vector<TemplateURL*> TemplateURLVector; | 80 typedef std::vector<TemplateURL*> TemplateURLVector; |
79 // Type for a static function pointer that acts as a time source. | 81 // Type for a static function pointer that acts as a time source. |
80 typedef base::Time(TimeProvider)(); | 82 typedef base::Time(TimeProvider)(); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 void set_loaded(bool value) { loaded_ = value; } | 282 void set_loaded(bool value) { loaded_ = value; } |
281 #endif | 283 #endif |
282 | 284 |
283 // Whether or not the keywords have been loaded. | 285 // Whether or not the keywords have been loaded. |
284 bool loaded() { return loaded_; } | 286 bool loaded() { return loaded_; } |
285 | 287 |
286 // Notification that the keywords have been loaded. | 288 // Notification that the keywords have been loaded. |
287 // This is invoked from WebDataService, and should not be directly | 289 // This is invoked from WebDataService, and should not be directly |
288 // invoked. | 290 // invoked. |
289 virtual void OnWebDataServiceRequestDone( | 291 virtual void OnWebDataServiceRequestDone( |
290 WebDataService::Handle h, | 292 KeywordWebDataService::Handle h, |
291 const WDTypedResult* result) OVERRIDE; | 293 const WDTypedResult* result) OVERRIDE; |
292 | 294 |
293 // Returns the locale-direction-adjusted short name for the given keyword. | 295 // Returns the locale-direction-adjusted short name for the given keyword. |
294 // Also sets the out param to indicate whether the keyword belongs to an | 296 // Also sets the out param to indicate whether the keyword belongs to an |
295 // Omnibox extension. | 297 // Omnibox extension. |
296 base::string16 GetKeywordShortName(const base::string16& keyword, | 298 base::string16 GetKeywordShortName(const base::string16& keyword, |
297 bool* is_omnibox_api_extension_keyword); | 299 bool* is_omnibox_api_extension_keyword); |
298 | 300 |
299 // content::NotificationObserver implementation. | 301 // content::NotificationObserver implementation. |
300 virtual void Observe(int type, | 302 virtual void Observe(int type, |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 | 685 |
684 // Whether the keywords have been loaded. | 686 // Whether the keywords have been loaded. |
685 bool loaded_; | 687 bool loaded_; |
686 | 688 |
687 // Set when the web data service fails to load properly. This prevents | 689 // Set when the web data service fails to load properly. This prevents |
688 // further communication with sync or writing to prefs, so we don't persist | 690 // further communication with sync or writing to prefs, so we don't persist |
689 // inconsistent state data anywhere. | 691 // inconsistent state data anywhere. |
690 bool load_failed_; | 692 bool load_failed_; |
691 | 693 |
692 // If non-zero, we're waiting on a load. | 694 // If non-zero, we're waiting on a load. |
693 WebDataService::Handle load_handle_; | 695 KeywordWebDataService::Handle load_handle_; |
694 | 696 |
695 // Service used to store entries. | 697 // Service used to store entries. |
696 scoped_refptr<WebDataService> service_; | 698 scoped_refptr<KeywordWebDataService> web_data_service_; |
697 | 699 |
698 // All visits that occurred before we finished loading. Once loaded | 700 // All visits that occurred before we finished loading. Once loaded |
699 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. | 701 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. |
700 std::vector<history::URLVisitedDetails> visits_to_add_; | 702 std::vector<history::URLVisitedDetails> visits_to_add_; |
701 | 703 |
702 // Once loaded, the default search provider. This is a pointer to a | 704 // Once loaded, the default search provider. This is a pointer to a |
703 // TemplateURL owned by |template_urls_|. | 705 // TemplateURL owned by |template_urls_|. |
704 TemplateURL* default_search_provider_; | 706 TemplateURL* default_search_provider_; |
705 | 707 |
706 // A temporary location for the DSE until Web Data has been loaded and it can | 708 // A temporary location for the DSE until Web Data has been loaded and it can |
(...skipping 20 matching lines...) Expand all Loading... |
727 // true, we ignore any local search engine changes, since we triggered them. | 729 // true, we ignore any local search engine changes, since we triggered them. |
728 bool processing_syncer_changes_; | 730 bool processing_syncer_changes_; |
729 | 731 |
730 // Sync's syncer::SyncChange handler. We push all our changes through this. | 732 // Sync's syncer::SyncChange handler. We push all our changes through this. |
731 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 733 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
732 | 734 |
733 // Sync's error handler. We use it to create a sync error. | 735 // Sync's error handler. We use it to create a sync error. |
734 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; | 736 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; |
735 | 737 |
736 // A set of sync GUIDs denoting TemplateURLs that have been removed from this | 738 // A set of sync GUIDs denoting TemplateURLs that have been removed from this |
737 // model or the underlying WebDataService prior to MergeDataAndStartSyncing. | 739 // model or the underlying KeywordWebDataService prior to |
| 740 // MergeDataAndStartSyncing. |
738 // This set is used to determine what entries from the server we want to | 741 // This set is used to determine what entries from the server we want to |
739 // ignore locally and return a delete command for. | 742 // ignore locally and return a delete command for. |
740 std::set<std::string> pre_sync_deletes_; | 743 std::set<std::string> pre_sync_deletes_; |
741 | 744 |
742 // This is used to log the origin of changes to the default search provider. | 745 // This is used to log the origin of changes to the default search provider. |
743 // We set this value to increasingly specific values when we know what is the | 746 // We set this value to increasingly specific values when we know what is the |
744 // cause/origin of a default search change. | 747 // cause/origin of a default search change. |
745 DefaultSearchChangeOrigin dsp_change_origin_; | 748 DefaultSearchChangeOrigin dsp_change_origin_; |
746 | 749 |
747 // Stores a list of callbacks to be run after TemplateURLService has loaded. | 750 // Stores a list of callbacks to be run after TemplateURLService has loaded. |
748 base::CallbackList<void(void)> on_loaded_callbacks_; | 751 base::CallbackList<void(void)> on_loaded_callbacks_; |
749 | 752 |
750 // Helper class to manage the default search engine. | 753 // Helper class to manage the default search engine. |
751 DefaultSearchManager default_search_manager_; | 754 DefaultSearchManager default_search_manager_; |
752 | 755 |
753 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_; | 756 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_; |
754 | 757 |
755 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 758 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
756 }; | 759 }; |
757 | 760 |
758 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 761 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
OLD | NEW |