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

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

Issue 2498053002: Add field to monitor last visited time for each search engine (Closed)
Patch Set: Add unit test for last_visited field. Created 4 years, 1 month 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
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 #include "components/search_engines/template_url_service.h" 5 #include "components/search_engines/template_url_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 DefaultSearchManager::Source source; 717 DefaultSearchManager::Source source;
718 const TemplateURLData* new_dse = 718 const TemplateURLData* new_dse =
719 default_search_manager_.GetDefaultSearchEngine(&source); 719 default_search_manager_.GetDefaultSearchEngine(&source);
720 // ApplyDefaultSearchChange will notify observers once it is done. 720 // ApplyDefaultSearchChange will notify observers once it is done.
721 ApplyDefaultSearchChange(new_dse, source); 721 ApplyDefaultSearchChange(new_dse, source);
722 } else { 722 } else {
723 NotifyObservers(); 723 NotifyObservers();
724 } 724 }
725 } 725 }
726 726
727 void TemplateURLService::UpdateTemplateURLVisitTime(TemplateURL* url) {
728 TemplateURLData data(url->data());
729 data.last_visited = clock_->Now();
730 if(UpdateNoNotify(url, TemplateURL(data)))
Peter Kasting 2016/11/21 03:35:08 Nit: There must be a space between "if" and "("; s
ltian 2016/11/28 22:08:02 Done.
731 NotifyObservers();
Peter Kasting 2016/11/21 03:35:08 Nit: There are at least a couple other places that
ltian 2016/11/28 22:08:02 There are only two places simply doing "if (Update
Peter Kasting 2016/11/28 22:20:24 Hmm, I see four, plus the one you're adding: http
ltian 2016/11/30 00:22:18 Do you mean my update function also needs to call
Peter Kasting 2016/11/30 00:39:37 No. The caller would do that. Your function woul
Peter Kasting 2016/12/01 07:38:24 Note: This whole conversation was about the Update
732 }
733
727 void TemplateURLService::AddObserver(TemplateURLServiceObserver* observer) { 734 void TemplateURLService::AddObserver(TemplateURLServiceObserver* observer) {
728 model_observers_.AddObserver(observer); 735 model_observers_.AddObserver(observer);
729 } 736 }
730 737
731 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { 738 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) {
732 model_observers_.RemoveObserver(observer); 739 model_observers_.RemoveObserver(observer);
733 } 740 }
734 741
735 void TemplateURLService::Load() { 742 void TemplateURLService::Load() {
736 if (loaded_ || load_handle_ || disable_load_) 743 if (loaded_ || load_handle_ || disable_load_)
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 se_specifics->set_search_url_post_params(turl.search_url_post_params()); 1265 se_specifics->set_search_url_post_params(turl.search_url_post_params());
1259 if (!turl.suggestions_url_post_params().empty()) { 1266 if (!turl.suggestions_url_post_params().empty()) {
1260 se_specifics->set_suggestions_url_post_params( 1267 se_specifics->set_suggestions_url_post_params(
1261 turl.suggestions_url_post_params()); 1268 turl.suggestions_url_post_params());
1262 } 1269 }
1263 if (!turl.instant_url_post_params().empty()) 1270 if (!turl.instant_url_post_params().empty())
1264 se_specifics->set_instant_url_post_params(turl.instant_url_post_params()); 1271 se_specifics->set_instant_url_post_params(turl.instant_url_post_params());
1265 if (!turl.image_url_post_params().empty()) 1272 if (!turl.image_url_post_params().empty())
1266 se_specifics->set_image_url_post_params(turl.image_url_post_params()); 1273 se_specifics->set_image_url_post_params(turl.image_url_post_params());
1267 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); 1274 se_specifics->set_last_modified(turl.last_modified().ToInternalValue());
1275 se_specifics->set_last_visited(turl.last_visited().ToInternalValue());
Peter Kasting 2016/11/21 03:35:08 I'm confused. I thought you weren't going to sync
ltian 2016/11/28 22:08:02 For sync part, there are operations for UPDATE and
Peter Kasting 2016/11/28 22:20:24 How would the app crash? Can you say more? I am
ltian 2016/11/30 00:22:18 So for current code, the |last_visited| will be se
Peter Kasting 2016/11/30 00:39:37 I would leave it as whatever the default value pro
1268 se_specifics->set_sync_guid(turl.sync_guid()); 1276 se_specifics->set_sync_guid(turl.sync_guid());
1269 for (size_t i = 0; i < turl.alternate_urls().size(); ++i) 1277 for (size_t i = 0; i < turl.alternate_urls().size(); ++i)
1270 se_specifics->add_alternate_urls(turl.alternate_urls()[i]); 1278 se_specifics->add_alternate_urls(turl.alternate_urls()[i]);
1271 se_specifics->set_search_terms_replacement_key( 1279 se_specifics->set_search_terms_replacement_key(
1272 turl.search_terms_replacement_key()); 1280 turl.search_terms_replacement_key());
1273 1281
1274 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(), 1282 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(),
1275 se_specifics->keyword(), 1283 se_specifics->keyword(),
1276 specifics); 1284 specifics);
1277 } 1285 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 data.input_encodings = base::SplitString( 1339 data.input_encodings = base::SplitString(
1332 specifics.input_encodings(), ";", 1340 specifics.input_encodings(), ";",
1333 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 1341 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1334 // If the server data has duplicate encodings, we'll want to push an update 1342 // If the server data has duplicate encodings, we'll want to push an update
1335 // below to correct it. Note that we also fix this in 1343 // below to correct it. Note that we also fix this in
1336 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct 1344 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct
1337 // local problems for clients which have disabled search engine sync. 1345 // local problems for clients which have disabled search engine sync.
1338 bool deduped = DeDupeEncodings(&data.input_encodings); 1346 bool deduped = DeDupeEncodings(&data.input_encodings);
1339 data.date_created = base::Time::FromInternalValue(specifics.date_created()); 1347 data.date_created = base::Time::FromInternalValue(specifics.date_created());
1340 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); 1348 data.last_modified = base::Time::FromInternalValue(specifics.last_modified());
1349 // TODO(ltian): sync separtely for this field.
1350 // Now if existing_turl is existed, keep last_visited locally without sync.
1351 if(existing_turl == nullptr) {
1352 data.last_visited = base::Time::FromInternalValue(specifics.last_visited());
1353 }
1341 data.prepopulate_id = specifics.prepopulate_id(); 1354 data.prepopulate_id = specifics.prepopulate_id();
1342 data.sync_guid = specifics.sync_guid(); 1355 data.sync_guid = specifics.sync_guid();
1343 data.alternate_urls.clear(); 1356 data.alternate_urls.clear();
1344 for (int i = 0; i < specifics.alternate_urls_size(); ++i) 1357 for (int i = 0; i < specifics.alternate_urls_size(); ++i)
1345 data.alternate_urls.push_back(specifics.alternate_urls(i)); 1358 data.alternate_urls.push_back(specifics.alternate_urls(i));
1346 data.search_terms_replacement_key = specifics.search_terms_replacement_key(); 1359 data.search_terms_replacement_key = specifics.search_terms_replacement_key();
1347 1360
1348 std::unique_ptr<TemplateURL> turl(new TemplateURL(data)); 1361 std::unique_ptr<TemplateURL> turl(new TemplateURL(data));
1349 // If this TemplateURL matches a built-in prepopulated template URL, it's 1362 // If this TemplateURL matches a built-in prepopulated template URL, it's
1350 // possible that sync is trying to modify fields that should not be touched. 1363 // possible that sync is trying to modify fields that should not be touched.
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 2486
2474 if (most_recently_intalled_default) { 2487 if (most_recently_intalled_default) {
2475 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2488 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2476 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2489 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2477 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2490 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2478 most_recently_intalled_default->data()); 2491 most_recently_intalled_default->data());
2479 } else { 2492 } else {
2480 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2493 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2481 } 2494 }
2482 } 2495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698