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

Side by Side Diff: chrome/browser/search_engines/template_url_service.h

Issue 23710022: Convert NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED to CallbackList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
OLDNEW
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/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/observer_list.h" 17 #include "base/observer_list.h"
17 #include "base/prefs/pref_change_registrar.h" 18 #include "base/prefs/pref_change_registrar.h"
18 #include "chrome/browser/search_engines/template_url_id.h" 19 #include "chrome/browser/search_engines/template_url_id.h"
19 #include "chrome/browser/webdata/web_data_service.h" 20 #include "chrome/browser/webdata/web_data_service.h"
20 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 21 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
21 #include "content/public/browser/notification_observer.h" 22 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h" 23 #include "content/public/browser/notification_registrar.h"
23 #include "sync/api/sync_change.h" 24 #include "sync/api/sync_change.h"
(...skipping 22 matching lines...) Expand all
46 // persisted to the database maintained by WebDataService. *ALL* mutations 47 // persisted to the database maintained by WebDataService. *ALL* mutations
47 // to the TemplateURLs must funnel through TemplateURLService. This allows 48 // to the TemplateURLs must funnel through TemplateURLService. This allows
48 // TemplateURLService to notify listeners of changes as well as keep the 49 // TemplateURLService to notify listeners of changes as well as keep the
49 // database in sync. 50 // database in sync.
50 // 51 //
51 // There is a TemplateURLService per Profile. 52 // There is a TemplateURLService per Profile.
52 // 53 //
53 // TemplateURLService does not load the vector of TemplateURLs in its 54 // TemplateURLService does not load the vector of TemplateURLs in its
54 // constructor (except for testing). Use the Load method to trigger a load. 55 // constructor (except for testing). Use the Load method to trigger a load.
55 // When TemplateURLService has completed loading, observers are notified via 56 // When TemplateURLService has completed loading, observers are notified via
56 // OnTemplateURLServiceChanged as well as the TEMPLATE_URL_SERVICE_LOADED 57 // OnTemplateURLServiceChanged, or by a callback registered prior to calling
57 // notification message. 58 // the Load method.
58 // 59 //
59 // TemplateURLService takes ownership of any TemplateURL passed to it. If there 60 // TemplateURLService takes ownership of any TemplateURL passed to it. If there
60 // is a WebDataService, deletion is handled by WebDataService, otherwise 61 // is a WebDataService, deletion is handled by WebDataService, otherwise
61 // TemplateURLService handles deletion. 62 // TemplateURLService handles deletion.
62 63
63 class TemplateURLService : public WebDataServiceConsumer, 64 class TemplateURLService : public WebDataServiceConsumer,
64 public BrowserContextKeyedService, 65 public BrowserContextKeyedService,
65 public content::NotificationObserver, 66 public content::NotificationObserver,
66 public syncer::SyncableService { 67 public syncer::SyncableService {
67 public: 68 public:
68 typedef std::map<std::string, std::string> QueryTerms; 69 typedef std::map<std::string, std::string> QueryTerms;
69 typedef std::vector<TemplateURL*> TemplateURLVector; 70 typedef std::vector<TemplateURL*> TemplateURLVector;
70 // Type for a static function pointer that acts as a time source. 71 // Type for a static function pointer that acts as a time source.
71 typedef base::Time(TimeProvider)(); 72 typedef base::Time(TimeProvider)();
72 typedef std::map<std::string, syncer::SyncData> SyncDataMap; 73 typedef std::map<std::string, syncer::SyncData> SyncDataMap;
74 typedef base::CallbackList<void(void)>::Subscription Subscription;
73 75
74 // Struct used for initializing the data store with fake data. 76 // Struct used for initializing the data store with fake data.
75 // Each initializer is mapped to a TemplateURL. 77 // Each initializer is mapped to a TemplateURL.
76 struct Initializer { 78 struct Initializer {
77 const char* const keyword; 79 const char* const keyword;
78 const char* const url; 80 const char* const url;
79 const char* const content; 81 const char* const content;
80 }; 82 };
81 83
82 // Struct describes a search engine added by an extension. 84 // Struct describes a search engine added by an extension.
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // TemplateURLService does NOT delete the observers when deleted. 258 // TemplateURLService does NOT delete the observers when deleted.
257 void AddObserver(TemplateURLServiceObserver* observer); 259 void AddObserver(TemplateURLServiceObserver* observer);
258 void RemoveObserver(TemplateURLServiceObserver* observer); 260 void RemoveObserver(TemplateURLServiceObserver* observer);
259 261
260 // Loads the keywords. This has no effect if the keywords have already been 262 // Loads the keywords. This has no effect if the keywords have already been
261 // loaded. 263 // loaded.
262 // Observers are notified when loading completes via the method 264 // Observers are notified when loading completes via the method
263 // OnTemplateURLServiceChanged. 265 // OnTemplateURLServiceChanged.
264 void Load(); 266 void Load();
265 267
268 // Registers a callback to be called when the service has loaded.
269 //
270 // If the service has already loaded, this function does nothing.
271 scoped_ptr<Subscription> RegisterOnLoadedCallback(
272 const base::Closure& callback);
273
266 #if defined(UNIT_TEST) 274 #if defined(UNIT_TEST)
267 void set_loaded(bool value) { loaded_ = value; } 275 void set_loaded(bool value) { loaded_ = value; }
268 #endif 276 #endif
269 277
270 // Whether or not the keywords have been loaded. 278 // Whether or not the keywords have been loaded.
271 bool loaded() { return loaded_; } 279 bool loaded() { return loaded_; }
272 280
273 // Notification that the keywords have been loaded. 281 // Notification that the keywords have been loaded.
274 // This is invoked from WebDataService, and should not be directly 282 // This is invoked from WebDataService, and should not be directly
275 // invoked. 283 // invoked.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 // This does NOT notify the delegate or the database. 439 // This does NOT notify the delegate or the database.
432 // 440 //
433 // This transfers ownership of the elements in |urls| to |this|, and may 441 // This transfers ownership of the elements in |urls| to |this|, and may
434 // delete some elements, so it's not safe for callers to access any elements 442 // delete some elements, so it's not safe for callers to access any elements
435 // after calling; to reinforce this, this function clears |urls| on exit. 443 // after calling; to reinforce this, this function clears |urls| on exit.
436 void SetTemplateURLs(TemplateURLVector* urls); 444 void SetTemplateURLs(TemplateURLVector* urls);
437 445
438 // Transitions to the loaded state. 446 // Transitions to the loaded state.
439 void ChangeToLoadedState(); 447 void ChangeToLoadedState();
440 448
441 // If there is a notification service, sends TEMPLATE_URL_SERVICE_LOADED
442 // notification.
443 void NotifyLoaded();
444
445 // Saves enough of url to preferences so that it can be loaded from 449 // Saves enough of url to preferences so that it can be loaded from
446 // preferences on start up. 450 // preferences on start up.
447 void SaveDefaultSearchProviderToPrefs(const TemplateURL* url); 451 void SaveDefaultSearchProviderToPrefs(const TemplateURL* url);
448 452
449 // Creates a TemplateURL that was previously saved to prefs via 453 // Creates a TemplateURL that was previously saved to prefs via
450 // SaveDefaultSearchProviderToPrefs or set via policy. 454 // SaveDefaultSearchProviderToPrefs or set via policy.
451 // Returns true if successful, false otherwise. 455 // Returns true if successful, false otherwise.
452 // If the user or the policy has opted for no default search, this 456 // If the user or the policy has opted for no default search, this
453 // returns true but default_provider is set to NULL. 457 // returns true but default_provider is set to NULL.
454 // |*is_managed| specifies whether the default is managed via policy. 458 // |*is_managed| specifies whether the default is managed via policy.
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 // model or the underlying WebDataService prior to MergeDataAndStartSyncing. 728 // model or the underlying WebDataService prior to MergeDataAndStartSyncing.
725 // This set is used to determine what entries from the server we want to 729 // This set is used to determine what entries from the server we want to
726 // ignore locally and return a delete command for. 730 // ignore locally and return a delete command for.
727 std::set<std::string> pre_sync_deletes_; 731 std::set<std::string> pre_sync_deletes_;
728 732
729 // This is used to log the origin of changes to the default search provider. 733 // This is used to log the origin of changes to the default search provider.
730 // We set this value to increasingly specific values when we know what is the 734 // We set this value to increasingly specific values when we know what is the
731 // cause/origin of a default search change. 735 // cause/origin of a default search change.
732 DefaultSearchChangeOrigin dsp_change_origin_; 736 DefaultSearchChangeOrigin dsp_change_origin_;
733 737
738 // Stores a list of callbacks to be run after TemplateURLService has loaded.
739 base::CallbackList<void(void)> on_loaded_callbacks_;
740
734 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); 741 DISALLOW_COPY_AND_ASSIGN(TemplateURLService);
735 }; 742 };
736 743
737 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 744 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_scraper_unittest.cc ('k') | chrome/browser/search_engines/template_url_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698