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

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

Issue 8342049: Added Protector, hooked up DSE verification with error bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comment Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/search_engines/template_url_service.h" 5 #include "chrome/browser/search_engines/template_url_service.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/string_split.h" 13 #include "base/string_split.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/google/google_url_tracker.h" 18 #include "chrome/browser/google/google_url_tracker.h"
19 #include "chrome/browser/history/history.h" 19 #include "chrome/browser/history/history.h"
20 #include "chrome/browser/history/history_notifications.h" 20 #include "chrome/browser/history/history_notifications.h"
21 #include "chrome/browser/net/url_fixer_upper.h" 21 #include "chrome/browser/net/url_fixer_upper.h"
22 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
23 #include "chrome/browser/prefs/pref_set_observer.h" 23 #include "chrome/browser/prefs/pref_set_observer.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/protector/protector.h"
26 #include "chrome/browser/protector/setting_change.h"
25 #include "chrome/browser/rlz/rlz.h" 27 #include "chrome/browser/rlz/rlz.h"
26 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 28 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
27 #include "chrome/browser/search_engines/search_terms_data.h" 29 #include "chrome/browser/search_engines/search_terms_data.h"
28 #include "chrome/browser/search_engines/template_url.h" 30 #include "chrome/browser/search_engines/template_url.h"
29 #include "chrome/browser/search_engines/template_url_service_observer.h" 31 #include "chrome/browser/search_engines/template_url_service_observer.h"
30 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 32 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
31 #include "chrome/browser/search_engines/util.h" 33 #include "chrome/browser/search_engines/util.h"
32 #include "chrome/browser/sync/api/sync_change.h" 34 #include "chrome/browser/sync/api/sync_change.h"
33 #include "chrome/browser/sync/protocol/search_engine_specifics.pb.h" 35 #include "chrome/browser/sync/protocol/search_engine_specifics.pb.h"
34 #include "chrome/common/chrome_notification_types.h" 36 #include "chrome/common/chrome_notification_types.h"
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 if (is_default_search_managed_) { 437 if (is_default_search_managed_) {
436 NOTREACHED(); 438 NOTREACHED();
437 return; 439 return;
438 } 440 }
439 if (default_search_provider_ == url) 441 if (default_search_provider_ == url)
440 return; 442 return;
441 SetDefaultSearchProviderNoNotify(url); 443 SetDefaultSearchProviderNoNotify(url);
442 NotifyObservers(); 444 NotifyObservers();
443 } 445 }
444 446
447 void TemplateURLService::ForceSetDefaultSearchProvider(
sky 2011/10/21 21:34:11 Having to expose a method like this is icky. Can y
whywhat 2011/10/24 15:30:17 Done. I think using the fact that setting dsp to N
448 const TemplateURL* url) {
449 if (is_default_search_managed_) {
450 NOTREACHED();
451 return;
452 }
453 SetDefaultSearchProviderNoNotify(url);
454 NotifyObservers();
455 }
456
445 const TemplateURL* TemplateURLService::GetDefaultSearchProvider() { 457 const TemplateURL* TemplateURLService::GetDefaultSearchProvider() {
446 if (loaded_ && !load_failed_) 458 if (loaded_ && !load_failed_)
447 return default_search_provider_; 459 return default_search_provider_;
448 460
449 // We're not loaded, rely on the default search provider stored in prefs. 461 // We're not loaded, rely on the default search provider stored in prefs.
450 return initial_default_search_provider_.get(); 462 return initial_default_search_provider_.get();
451 } 463 }
452 464
453 void TemplateURLService::AddObserver(TemplateURLServiceObserver* observer) { 465 void TemplateURLService::AddObserver(TemplateURLServiceObserver* observer) {
454 model_observers_.AddObserver(observer); 466 model_observers_.AddObserver(observer);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 int new_resource_keyword_version = 0; 511 int new_resource_keyword_version = 0;
500 GetSearchProvidersUsingKeywordResult(*result, 512 GetSearchProvidersUsingKeywordResult(*result,
501 service_.get(), 513 service_.get(),
502 GetPrefs(), 514 GetPrefs(),
503 &template_urls, 515 &template_urls,
504 &default_search_provider, 516 &default_search_provider,
505 &new_resource_keyword_version); 517 &new_resource_keyword_version);
506 518
507 bool database_specified_a_default = NULL != default_search_provider; 519 bool database_specified_a_default = NULL != default_search_provider;
508 520
521 // Check if the default search provider has been changed and notify
522 // Protector instance about it.
523 const TemplateURL* backup_default_search_provider = NULL;
524 if (DidDefaultSearchProviderChange(
525 *result,
526 template_urls,
527 &backup_default_search_provider)) {
528 // Protector will delete itself when it's needed no longer.
529 protector::Protector* protector = new protector::Protector(profile());
530 protector->ShowChange(protector::CreateDefaultSearchProviderChange(
531 default_search_provider,
sky 2011/10/21 21:34:11 Should we ignore this if managed? Protector seems
whywhat 2011/10/24 15:30:17 Done.
532 backup_default_search_provider));
533 }
534
509 // Check if default search provider is now managed. 535 // Check if default search provider is now managed.
510 scoped_ptr<TemplateURL> default_from_prefs; 536 scoped_ptr<TemplateURL> default_from_prefs;
511 LoadDefaultSearchProviderFromPrefs(&default_from_prefs, 537 LoadDefaultSearchProviderFromPrefs(&default_from_prefs,
512 &is_default_search_managed_); 538 &is_default_search_managed_);
513 539
514 // Remove entries that were created because of policy as they may have 540 // Remove entries that were created because of policy as they may have
515 // changed since the database was saved. 541 // changed since the database was saved.
516 RemoveProvidersCreatedByPolicy(&template_urls, 542 RemoveProvidersCreatedByPolicy(&template_urls,
517 &default_search_provider, 543 &default_search_provider,
518 default_from_prefs.get()); 544 default_from_prefs.get());
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } else { 1740 } else {
1715 // Change the local TURL's GUID to the server's GUID and push an update to 1741 // Change the local TURL's GUID to the server's GUID and push an update to
1716 // Sync. This ensures that the rest of local_url's fields are sync'd up to 1742 // Sync. This ensures that the rest of local_url's fields are sync'd up to
1717 // the server, and the next time local_url is synced, it is recognized by 1743 // the server, and the next time local_url is synced, it is recognized by
1718 // having the same GUID. 1744 // having the same GUID.
1719 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); 1745 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid());
1720 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); 1746 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl);
1721 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); 1747 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data));
1722 } 1748 }
1723 } 1749 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698