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 #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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 next_id_(kInvalidTemplateURLID + 1), | 299 next_id_(kInvalidTemplateURLID + 1), |
300 time_provider_(&base::Time::Now), | 300 time_provider_(&base::Time::Now), |
301 models_associated_(false), | 301 models_associated_(false), |
302 processing_syncer_changes_(false), | 302 processing_syncer_changes_(false), |
303 pending_synced_default_search_(false), | 303 pending_synced_default_search_(false), |
304 dsp_change_origin_(DSP_CHANGE_NOT_SYNC) { | 304 dsp_change_origin_(DSP_CHANGE_NOT_SYNC) { |
305 Init(initializers, count); | 305 Init(initializers, count); |
306 } | 306 } |
307 | 307 |
308 TemplateURLService::~TemplateURLService() { | 308 TemplateURLService::~TemplateURLService() { |
309 if (load_handle_) { | |
310 DCHECK(service_.get()); | |
311 service_->CancelRequest(load_handle_); | |
312 } | |
313 | |
314 STLDeleteElements(&template_urls_); | |
315 } | 309 } |
316 | 310 |
317 // static | 311 // static |
318 string16 TemplateURLService::GenerateKeyword(const GURL& url) { | 312 string16 TemplateURLService::GenerateKeyword(const GURL& url) { |
319 DCHECK(url.is_valid()); | 313 DCHECK(url.is_valid()); |
320 // Strip "www." off the front of the keyword; otherwise the keyword won't work | 314 // Strip "www." off the front of the keyword; otherwise the keyword won't work |
321 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . | 315 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . |
322 // Special case: if the host was exactly "www." (not sure this can happen but | 316 // Special case: if the host was exactly "www." (not sure this can happen but |
323 // perhaps with some weird intranet and custom DNS server?), ensure we at | 317 // perhaps with some weird intranet and custom DNS server?), ensure we at |
324 // least don't return the empty string. | 318 // least don't return the empty string. |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 } else if (type == chrome::NOTIFICATION_GOOGLE_URL_UPDATED) { | 865 } else if (type == chrome::NOTIFICATION_GOOGLE_URL_UPDATED) { |
872 if (loaded_) { | 866 if (loaded_) { |
873 GoogleBaseURLChanged( | 867 GoogleBaseURLChanged( |
874 content::Details<GoogleURLTracker::UpdatedDetails>(details)->first); | 868 content::Details<GoogleURLTracker::UpdatedDetails>(details)->first); |
875 } | 869 } |
876 } else { | 870 } else { |
877 NOTREACHED(); | 871 NOTREACHED(); |
878 } | 872 } |
879 } | 873 } |
880 | 874 |
| 875 void TemplateURLService::Shutdown() { |
| 876 // This check has to be done at Shutdown() instead of in the dtor to ensure |
| 877 // that no clients of WebDataService are holding ptrs to it after the first |
| 878 // phase of the ProfileKeyedService Shutdown() process. |
| 879 if (load_handle_) { |
| 880 DCHECK(service_.get()); |
| 881 service_->CancelRequest(load_handle_); |
| 882 } |
| 883 service_ = NULL; |
| 884 STLDeleteElements(&template_urls_); |
| 885 } |
| 886 |
881 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { | 887 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { |
882 // Listen for changes to the default search from Sync. | 888 // Listen for changes to the default search from Sync. |
883 PrefService* prefs = GetPrefs(); | 889 PrefService* prefs = GetPrefs(); |
884 TemplateURL* new_default_search = GetTemplateURLForGUID( | 890 TemplateURL* new_default_search = GetTemplateURLForGUID( |
885 prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID)); | 891 prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID)); |
886 if (new_default_search && !is_default_search_managed_) { | 892 if (new_default_search && !is_default_search_managed_) { |
887 if (new_default_search != GetDefaultSearchProvider()) { | 893 if (new_default_search != GetDefaultSearchProvider()) { |
888 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 894 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
889 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); | 895 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); |
890 SetDefaultSearchProvider(new_default_search); | 896 SetDefaultSearchProvider(new_default_search); |
(...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2482 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2488 // TODO(mpcomplete): If we allow editing extension keywords, then those |
2483 // should be persisted to disk and synced. | 2489 // should be persisted to disk and synced. |
2484 if (template_url->sync_guid().empty() && | 2490 if (template_url->sync_guid().empty() && |
2485 !template_url->IsExtensionKeyword()) { | 2491 !template_url->IsExtensionKeyword()) { |
2486 template_url->data_.sync_guid = base::GenerateGUID(); | 2492 template_url->data_.sync_guid = base::GenerateGUID(); |
2487 if (service_.get()) | 2493 if (service_.get()) |
2488 service_->UpdateKeyword(template_url->data()); | 2494 service_->UpdateKeyword(template_url->data()); |
2489 } | 2495 } |
2490 } | 2496 } |
2491 } | 2497 } |
OLD | NEW |