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; |
34 class TemplateURL; | 36 class TemplateURL; |
35 struct TemplateURLData; | 37 struct TemplateURLData; |
36 class TemplateURLServiceObserver; | 38 class TemplateURLServiceObserver; |
37 | 39 |
38 namespace syncer { | 40 namespace syncer { |
39 class SyncData; | 41 class SyncData; |
40 class SyncErrorFactory; | 42 class SyncErrorFactory; |
41 } | 43 } |
42 | 44 |
43 namespace history { | 45 namespace history { |
44 struct URLVisitedDetails; | 46 struct URLVisitedDetails; |
45 } | 47 } |
46 | 48 |
47 // TemplateURLService is the backend for keywords. It's used by | 49 // TemplateURLService is the backend for keywords. It's used by |
48 // KeywordAutocomplete. | 50 // KeywordAutocomplete. |
49 // | 51 // |
50 // TemplateURLService stores a vector of TemplateURLs. The TemplateURLs are | 52 // TemplateURLService stores a vector of TemplateURLs. The TemplateURLs are |
51 // persisted to the database maintained by WebDataService. *ALL* mutations | 53 // persisted to the database maintained by KeywordWebDataService. |
52 // to the TemplateURLs must funnel through TemplateURLService. This allows | 54 // *ALL* mutations to the TemplateURLs must funnel through TemplateURLService. |
53 // TemplateURLService to notify listeners of changes as well as keep the | 55 // This allows TemplateURLService to notify listeners of changes as well as keep |
54 // database in sync. | 56 // the database in sync. |
55 // | 57 // |
56 // There is a TemplateURLService per Profile. | 58 // There is a TemplateURLService per Profile. |
57 // | 59 // |
58 // TemplateURLService does not load the vector of TemplateURLs in its | 60 // TemplateURLService does not load the vector of TemplateURLs in its |
59 // constructor (except for testing). Use the Load method to trigger a load. | 61 // constructor (except for testing). Use the Load method to trigger a load. |
60 // When TemplateURLService has completed loading, observers are notified via | 62 // When TemplateURLService has completed loading, observers are notified via |
61 // OnTemplateURLServiceChanged, or by a callback registered prior to calling | 63 // OnTemplateURLServiceChanged, or by a callback registered prior to calling |
62 // the Load method. | 64 // the Load method. |
63 // | 65 // |
64 // TemplateURLService takes ownership of any TemplateURL passed to it. If there | 66 // TemplateURLService takes ownership of any TemplateURL passed to it. If there |
65 // is a WebDataService, deletion is handled by WebDataService, otherwise | 67 // is a KeywordWebDataService, deletion is handled by KeywordWebDataService, |
66 // TemplateURLService handles deletion. | 68 // otherwise TemplateURLService handles deletion. |
67 | 69 |
68 class TemplateURLService : public WebDataServiceConsumer, | 70 class TemplateURLService : public WebDataServiceConsumer, |
69 public KeyedService, | 71 public KeyedService, |
70 public content::NotificationObserver, | 72 public content::NotificationObserver, |
71 public syncer::SyncableService { | 73 public syncer::SyncableService { |
72 public: | 74 public: |
73 typedef std::map<std::string, std::string> QueryTerms; | 75 typedef std::map<std::string, std::string> QueryTerms; |
74 typedef std::vector<TemplateURL*> TemplateURLVector; | 76 typedef std::vector<TemplateURL*> TemplateURLVector; |
75 // Type for a static function pointer that acts as a time source. | 77 // Type for a static function pointer that acts as a time source. |
76 typedef base::Time(TimeProvider)(); | 78 typedef base::Time(TimeProvider)(); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 void set_loaded(bool value) { loaded_ = value; } | 277 void set_loaded(bool value) { loaded_ = value; } |
276 #endif | 278 #endif |
277 | 279 |
278 // Whether or not the keywords have been loaded. | 280 // Whether or not the keywords have been loaded. |
279 bool loaded() { return loaded_; } | 281 bool loaded() { return loaded_; } |
280 | 282 |
281 // Notification that the keywords have been loaded. | 283 // Notification that the keywords have been loaded. |
282 // This is invoked from WebDataService, and should not be directly | 284 // This is invoked from WebDataService, and should not be directly |
283 // invoked. | 285 // invoked. |
284 virtual void OnWebDataServiceRequestDone( | 286 virtual void OnWebDataServiceRequestDone( |
285 WebDataService::Handle h, | 287 KeywordWebDataService::Handle h, |
286 const WDTypedResult* result) OVERRIDE; | 288 const WDTypedResult* result) OVERRIDE; |
287 | 289 |
288 // Returns the locale-direction-adjusted short name for the given keyword. | 290 // Returns the locale-direction-adjusted short name for the given keyword. |
289 // Also sets the out param to indicate whether the keyword belongs to an | 291 // Also sets the out param to indicate whether the keyword belongs to an |
290 // Omnibox extension. | 292 // Omnibox extension. |
291 base::string16 GetKeywordShortName(const base::string16& keyword, | 293 base::string16 GetKeywordShortName(const base::string16& keyword, |
292 bool* is_omnibox_api_extension_keyword); | 294 bool* is_omnibox_api_extension_keyword); |
293 | 295 |
294 // content::NotificationObserver implementation. | 296 // content::NotificationObserver implementation. |
295 virtual void Observe(int type, | 297 virtual void Observe(int type, |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 680 |
679 // Whether the keywords have been loaded. | 681 // Whether the keywords have been loaded. |
680 bool loaded_; | 682 bool loaded_; |
681 | 683 |
682 // Set when the web data service fails to load properly. This prevents | 684 // Set when the web data service fails to load properly. This prevents |
683 // further communication with sync or writing to prefs, so we don't persist | 685 // further communication with sync or writing to prefs, so we don't persist |
684 // inconsistent state data anywhere. | 686 // inconsistent state data anywhere. |
685 bool load_failed_; | 687 bool load_failed_; |
686 | 688 |
687 // If non-zero, we're waiting on a load. | 689 // If non-zero, we're waiting on a load. |
688 WebDataService::Handle load_handle_; | 690 KeywordWebDataService::Handle load_handle_; |
689 | 691 |
690 // Service used to store entries. | 692 // Service used to store entries. |
691 scoped_refptr<WebDataService> service_; | 693 scoped_refptr<KeywordWebDataService> web_data_service_; |
692 | 694 |
693 // All visits that occurred before we finished loading. Once loaded | 695 // All visits that occurred before we finished loading. Once loaded |
694 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. | 696 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. |
695 std::vector<history::URLVisitedDetails> visits_to_add_; | 697 std::vector<history::URLVisitedDetails> visits_to_add_; |
696 | 698 |
697 // Once loaded, the default search provider. This is a pointer to a | 699 // Once loaded, the default search provider. This is a pointer to a |
698 // TemplateURL owned by |template_urls_|. | 700 // TemplateURL owned by |template_urls_|. |
699 TemplateURL* default_search_provider_; | 701 TemplateURL* default_search_provider_; |
700 | 702 |
701 // A temporary location for the DSE until Web Data has been loaded and it can | 703 // A temporary location for the DSE until Web Data has been loaded and it can |
(...skipping 20 matching lines...) Expand all Loading... |
722 // true, we ignore any local search engine changes, since we triggered them. | 724 // true, we ignore any local search engine changes, since we triggered them. |
723 bool processing_syncer_changes_; | 725 bool processing_syncer_changes_; |
724 | 726 |
725 // Sync's syncer::SyncChange handler. We push all our changes through this. | 727 // Sync's syncer::SyncChange handler. We push all our changes through this. |
726 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 728 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
727 | 729 |
728 // Sync's error handler. We use it to create a sync error. | 730 // Sync's error handler. We use it to create a sync error. |
729 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; | 731 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; |
730 | 732 |
731 // A set of sync GUIDs denoting TemplateURLs that have been removed from this | 733 // A set of sync GUIDs denoting TemplateURLs that have been removed from this |
732 // model or the underlying WebDataService prior to MergeDataAndStartSyncing. | 734 // model or the underlying KeywordWebDataService prior to |
| 735 // MergeDataAndStartSyncing. |
733 // This set is used to determine what entries from the server we want to | 736 // This set is used to determine what entries from the server we want to |
734 // ignore locally and return a delete command for. | 737 // ignore locally and return a delete command for. |
735 std::set<std::string> pre_sync_deletes_; | 738 std::set<std::string> pre_sync_deletes_; |
736 | 739 |
737 // This is used to log the origin of changes to the default search provider. | 740 // This is used to log the origin of changes to the default search provider. |
738 // We set this value to increasingly specific values when we know what is the | 741 // We set this value to increasingly specific values when we know what is the |
739 // cause/origin of a default search change. | 742 // cause/origin of a default search change. |
740 DefaultSearchChangeOrigin dsp_change_origin_; | 743 DefaultSearchChangeOrigin dsp_change_origin_; |
741 | 744 |
742 // Stores a list of callbacks to be run after TemplateURLService has loaded. | 745 // Stores a list of callbacks to be run after TemplateURLService has loaded. |
743 base::CallbackList<void(void)> on_loaded_callbacks_; | 746 base::CallbackList<void(void)> on_loaded_callbacks_; |
744 | 747 |
745 // Helper class to manage the default search engine. | 748 // Helper class to manage the default search engine. |
746 DefaultSearchManager default_search_manager_; | 749 DefaultSearchManager default_search_manager_; |
747 | 750 |
748 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_; | 751 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_; |
749 | 752 |
750 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); | 753 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); |
751 }; | 754 }; |
752 | 755 |
753 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ | 756 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ |
OLD | NEW |