| 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 (service_) |
| 310 Shutdown(); |
| 311 STLDeleteElements(&template_urls_); |
| 309 } | 312 } |
| 310 | 313 |
| 311 // static | 314 // static |
| 312 string16 TemplateURLService::GenerateKeyword(const GURL& url) { | 315 string16 TemplateURLService::GenerateKeyword(const GURL& url) { |
| 313 DCHECK(url.is_valid()); | 316 DCHECK(url.is_valid()); |
| 314 // Strip "www." off the front of the keyword; otherwise the keyword won't work | 317 // Strip "www." off the front of the keyword; otherwise the keyword won't work |
| 315 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . | 318 // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . |
| 316 // Special case: if the host was exactly "www." (not sure this can happen but | 319 // Special case: if the host was exactly "www." (not sure this can happen but |
| 317 // perhaps with some weird intranet and custom DNS server?), ensure we at | 320 // perhaps with some weird intranet and custom DNS server?), ensure we at |
| 318 // least don't return the empty string. | 321 // least don't return the empty string. |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 | 877 |
| 875 void TemplateURLService::Shutdown() { | 878 void TemplateURLService::Shutdown() { |
| 876 // This check has to be done at Shutdown() instead of in the dtor to ensure | 879 // 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 | 880 // that no clients of WebDataService are holding ptrs to it after the first |
| 878 // phase of the ProfileKeyedService Shutdown() process. | 881 // phase of the ProfileKeyedService Shutdown() process. |
| 879 if (load_handle_) { | 882 if (load_handle_) { |
| 880 DCHECK(service_.get()); | 883 DCHECK(service_.get()); |
| 881 service_->CancelRequest(load_handle_); | 884 service_->CancelRequest(load_handle_); |
| 882 } | 885 } |
| 883 service_ = NULL; | 886 service_ = NULL; |
| 884 STLDeleteElements(&template_urls_); | |
| 885 } | 887 } |
| 886 | 888 |
| 887 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { | 889 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { |
| 888 // Listen for changes to the default search from Sync. | 890 // Listen for changes to the default search from Sync. |
| 889 PrefService* prefs = GetPrefs(); | 891 PrefService* prefs = GetPrefs(); |
| 890 TemplateURL* new_default_search = GetTemplateURLForGUID( | 892 TemplateURL* new_default_search = GetTemplateURLForGUID( |
| 891 prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID)); | 893 prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID)); |
| 892 if (new_default_search && !is_default_search_managed_) { | 894 if (new_default_search && !is_default_search_managed_) { |
| 893 if (new_default_search != GetDefaultSearchProvider()) { | 895 if (new_default_search != GetDefaultSearchProvider()) { |
| 894 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 896 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| (...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2488 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2490 // TODO(mpcomplete): If we allow editing extension keywords, then those |
| 2489 // should be persisted to disk and synced. | 2491 // should be persisted to disk and synced. |
| 2490 if (template_url->sync_guid().empty() && | 2492 if (template_url->sync_guid().empty() && |
| 2491 !template_url->IsExtensionKeyword()) { | 2493 !template_url->IsExtensionKeyword()) { |
| 2492 template_url->data_.sync_guid = base::GenerateGUID(); | 2494 template_url->data_.sync_guid = base::GenerateGUID(); |
| 2493 if (service_.get()) | 2495 if (service_.get()) |
| 2494 service_->UpdateKeyword(template_url->data()); | 2496 service_->UpdateKeyword(template_url->data()); |
| 2495 } | 2497 } |
| 2496 } | 2498 } |
| 2497 } | 2499 } |
| OLD | NEW |