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

Side by Side Diff: components/search_engines/template_url_service.h

Issue 855633002: [Clean-up] Replace the final straggler use of MockTimeProvider with Clock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error Created 5 years, 11 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
« no previous file with comments | « base/test/mock_time_provider.cc ('k') | components/search_engines/template_url_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 6 #define COMPONENTS_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 "base/time/clock.h"
19 #include "components/google/core/browser/google_url_tracker.h" 20 #include "components/google/core/browser/google_url_tracker.h"
20 #include "components/keyed_service/core/keyed_service.h" 21 #include "components/keyed_service/core/keyed_service.h"
21 #include "components/search_engines/default_search_manager.h" 22 #include "components/search_engines/default_search_manager.h"
22 #include "components/search_engines/keyword_web_data_service.h" 23 #include "components/search_engines/keyword_web_data_service.h"
23 #include "components/search_engines/template_url.h" 24 #include "components/search_engines/template_url.h"
24 #include "components/search_engines/template_url_id.h" 25 #include "components/search_engines/template_url_id.h"
25 #include "components/webdata/common/web_data_service_consumer.h" 26 #include "components/webdata/common/web_data_service_consumer.h"
26 #include "sync/api/sync_change.h" 27 #include "sync/api/sync_change.h"
27 #include "sync/api/syncable_service.h" 28 #include "sync/api/syncable_service.h"
28 29
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // TemplateURLService takes ownership of any TemplateURL passed to it. If there 63 // TemplateURLService takes ownership of any TemplateURL passed to it. If there
63 // is a KeywordWebDataService, deletion is handled by KeywordWebDataService, 64 // is a KeywordWebDataService, deletion is handled by KeywordWebDataService,
64 // otherwise TemplateURLService handles deletion. 65 // otherwise TemplateURLService handles deletion.
65 66
66 class TemplateURLService : public WebDataServiceConsumer, 67 class TemplateURLService : public WebDataServiceConsumer,
67 public KeyedService, 68 public KeyedService,
68 public syncer::SyncableService { 69 public syncer::SyncableService {
69 public: 70 public:
70 typedef std::map<std::string, std::string> QueryTerms; 71 typedef std::map<std::string, std::string> QueryTerms;
71 typedef std::vector<TemplateURL*> TemplateURLVector; 72 typedef std::vector<TemplateURL*> TemplateURLVector;
72 // Type for a static function pointer that acts as a time source.
73 typedef base::Time(TimeProvider)();
74 typedef std::map<std::string, syncer::SyncData> SyncDataMap; 73 typedef std::map<std::string, syncer::SyncData> SyncDataMap;
75 typedef base::CallbackList<void(void)>::Subscription Subscription; 74 typedef base::CallbackList<void(void)>::Subscription Subscription;
76 75
77 // Struct used for initializing the data store with fake data. 76 // Struct used for initializing the data store with fake data.
78 // Each initializer is mapped to a TemplateURL. 77 // Each initializer is mapped to a TemplateURL.
79 struct Initializer { 78 struct Initializer {
80 const char* const keyword; 79 const char* const keyword;
81 const char* const url; 80 const char* const url;
82 const char* const content; 81 const char* const content;
83 }; 82 };
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 const SearchTermsData& search_terms_data, 358 const SearchTermsData& search_terms_data,
360 TemplateURL* existing_turl, 359 TemplateURL* existing_turl,
361 const syncer::SyncData& sync_data, 360 const syncer::SyncData& sync_data,
362 syncer::SyncChangeList* change_list); 361 syncer::SyncChangeList* change_list);
363 362
364 // Returns a map mapping Sync GUIDs to pointers to syncer::SyncData. 363 // Returns a map mapping Sync GUIDs to pointers to syncer::SyncData.
365 static SyncDataMap CreateGUIDToSyncDataMap( 364 static SyncDataMap CreateGUIDToSyncDataMap(
366 const syncer::SyncDataList& sync_data); 365 const syncer::SyncDataList& sync_data);
367 366
368 #if defined(UNIT_TEST) 367 #if defined(UNIT_TEST)
369 // Sets a different time provider function, such as 368 void set_clock(scoped_ptr<base::Clock> clock) { clock_ = clock.Pass(); }
370 // base::MockTimeProvider::StaticNow, for testing calls to base::Time::Now.
371 void set_time_provider(TimeProvider* time_provider) {
372 time_provider_ = time_provider;
373 }
374 #endif 369 #endif
375 370
376 private: 371 private:
377 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, TestManagedDefaultSearch); 372 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, TestManagedDefaultSearch);
378 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, 373 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest,
379 UpdateKeywordSearchTermsForURL); 374 UpdateKeywordSearchTermsForURL);
380 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, 375 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest,
381 DontUpdateKeywordSearchForNonReplaceable); 376 DontUpdateKeywordSearchForNonReplaceable);
382 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, ChangeGoogleBaseValue); 377 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, ChangeGoogleBaseValue);
383 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, MergeDeletesUnusedProviders); 378 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, MergeDeletesUnusedProviders);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 // be merged into |template_urls_|. 694 // be merged into |template_urls_|.
700 scoped_ptr<TemplateURL> initial_default_search_provider_; 695 scoped_ptr<TemplateURL> initial_default_search_provider_;
701 696
702 // Source of the default search provider. 697 // Source of the default search provider.
703 DefaultSearchManager::Source default_search_provider_source_; 698 DefaultSearchManager::Source default_search_provider_source_;
704 699
705 // ID assigned to next TemplateURL added to this model. This is an ever 700 // ID assigned to next TemplateURL added to this model. This is an ever
706 // increasing integer that is initialized from the database. 701 // increasing integer that is initialized from the database.
707 TemplateURLID next_id_; 702 TemplateURLID next_id_;
708 703
709 // Function returning current time in base::Time units. 704 // Used to retrieve the current time, in base::Time units.
710 TimeProvider* time_provider_; 705 scoped_ptr<base::Clock> clock_;
711 706
712 // Do we have an active association between the TemplateURLs and sync models? 707 // Do we have an active association between the TemplateURLs and sync models?
713 // Set in MergeDataAndStartSyncing, reset in StopSyncing. While this is not 708 // Set in MergeDataAndStartSyncing, reset in StopSyncing. While this is not
714 // set, we ignore any local search engine changes (when we start syncing we 709 // set, we ignore any local search engine changes (when we start syncing we
715 // will look up the most recent values anyways). 710 // will look up the most recent values anyways).
716 bool models_associated_; 711 bool models_associated_;
717 712
718 // Whether we're currently processing changes from the syncer. While this is 713 // Whether we're currently processing changes from the syncer. While this is
719 // true, we ignore any local search engine changes, since we triggered them. 714 // true, we ignore any local search engine changes, since we triggered them.
720 bool processing_syncer_changes_; 715 bool processing_syncer_changes_;
(...skipping 21 matching lines...) Expand all
742 737
743 // Helper class to manage the default search engine. 738 // Helper class to manage the default search engine.
744 DefaultSearchManager default_search_manager_; 739 DefaultSearchManager default_search_manager_;
745 740
746 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_; 741 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_;
747 742
748 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); 743 DISALLOW_COPY_AND_ASSIGN(TemplateURLService);
749 }; 744 };
750 745
751 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 746 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
OLDNEW
« no previous file with comments | « base/test/mock_time_provider.cc ('k') | components/search_engines/template_url_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698