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/environment.h" | 9 #include "base/environment.h" |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "chrome/browser/protector/protector_utils.h" | 28 #include "chrome/browser/protector/protector_utils.h" |
29 #include "chrome/browser/rlz/rlz.h" | 29 #include "chrome/browser/rlz/rlz.h" |
30 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 30 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
31 #include "chrome/browser/search_engines/search_terms_data.h" | 31 #include "chrome/browser/search_engines/search_terms_data.h" |
32 #include "chrome/browser/search_engines/template_url.h" | 32 #include "chrome/browser/search_engines/template_url.h" |
33 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 33 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
34 #include "chrome/browser/search_engines/template_url_service_observer.h" | 34 #include "chrome/browser/search_engines/template_url_service_observer.h" |
35 #include "chrome/browser/search_engines/util.h" | 35 #include "chrome/browser/search_engines/util.h" |
36 #include "chrome/browser/sync/api/sync_change.h" | 36 #include "chrome/browser/sync/api/sync_change.h" |
37 #include "chrome/browser/sync/api/sync_error_factory.h" | 37 #include "chrome/browser/sync/api/sync_error_factory.h" |
| 38 #include "chrome/browser/webdata/web_data_service_factory.h" |
38 #include "chrome/common/chrome_notification_types.h" | 39 #include "chrome/common/chrome_notification_types.h" |
39 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
40 #include "chrome/common/env_vars.h" | 41 #include "chrome/common/env_vars.h" |
41 #include "chrome/common/extensions/extension.h" | 42 #include "chrome/common/extensions/extension.h" |
42 #include "chrome/common/guid.h" | 43 #include "chrome/common/guid.h" |
43 #include "chrome/common/pref_names.h" | 44 #include "chrome/common/pref_names.h" |
44 #include "chrome/common/url_constants.h" | 45 #include "chrome/common/url_constants.h" |
45 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
46 #include "net/base/net_util.h" | 47 #include "net/base/net_util.h" |
47 #include "sync/protocol/search_engine_specifics.pb.h" | 48 #include "sync/protocol/search_engine_specifics.pb.h" |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 } | 549 } |
549 | 550 |
550 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { | 551 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { |
551 model_observers_.RemoveObserver(observer); | 552 model_observers_.RemoveObserver(observer); |
552 } | 553 } |
553 | 554 |
554 void TemplateURLService::Load() { | 555 void TemplateURLService::Load() { |
555 if (loaded_ || load_handle_) | 556 if (loaded_ || load_handle_) |
556 return; | 557 return; |
557 | 558 |
558 if (!service_.get()) | 559 if (!service_.get()) { |
559 service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 560 service_ = WebDataServiceFactory::GetForProfile(profile_, |
| 561 Profile::EXPLICIT_ACCESS); |
| 562 } |
560 | 563 |
561 if (service_.get()) { | 564 if (service_.get()) { |
562 load_handle_ = service_->GetKeywords(this); | 565 load_handle_ = service_->GetKeywords(this); |
563 } else { | 566 } else { |
564 ChangeToLoadedState(); | 567 ChangeToLoadedState(); |
565 NotifyLoaded(); | 568 NotifyLoaded(); |
566 } | 569 } |
567 } | 570 } |
568 | 571 |
569 void TemplateURLService::OnWebDataServiceRequestDone( | 572 void TemplateURLService::OnWebDataServiceRequestDone( |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 } | 892 } |
890 if (UpdateNoNotify(existing_turl, *turl)) | 893 if (UpdateNoNotify(existing_turl, *turl)) |
891 NotifyObservers(); | 894 NotifyObservers(); |
892 } else { | 895 } else { |
893 // Something really unexpected happened. Either we received an | 896 // Something really unexpected happened. Either we received an |
894 // ACTION_INVALID, or Sync is in a crazy state: | 897 // ACTION_INVALID, or Sync is in a crazy state: |
895 // . Trying to DELETE or UPDATE a non-existent search engine. | 898 // . Trying to DELETE or UPDATE a non-existent search engine. |
896 // . Trying to ADD a search engine that already exists. | 899 // . Trying to ADD a search engine that already exists. |
897 NOTREACHED() << "Unexpected sync change state."; | 900 NOTREACHED() << "Unexpected sync change state."; |
898 error = sync_error_factory_->CreateAndUploadError( | 901 error = sync_error_factory_->CreateAndUploadError( |
899 FROM_HERE, | 902 FROM_HERE, |
900 "ProcessSyncChanges failed on ChangeType " + | 903 "ProcessSyncChanges failed on ChangeType " + |
901 SyncChange::ChangeTypeToString(iter->change_type())); | 904 SyncChange::ChangeTypeToString(iter->change_type())); |
902 } | 905 } |
903 } | 906 } |
904 PreventDuplicateGUIDUpdates(&new_changes); | 907 PreventDuplicateGUIDUpdates(&new_changes); |
905 | 908 |
906 // If something went wrong, we want to prematurely exit to avoid pushing | 909 // If something went wrong, we want to prematurely exit to avoid pushing |
907 // inconsistent data to Sync. We return the last error we received. | 910 // inconsistent data to Sync. We return the last error we received. |
908 if (error.IsSet()) | 911 if (error.IsSet()) |
909 return error; | 912 return error; |
910 | 913 |
911 error = sync_processor_->ProcessSyncChanges(from_here, new_changes); | 914 error = sync_processor_->ProcessSyncChanges(from_here, new_changes); |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2203 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2206 // TODO(mpcomplete): If we allow editing extension keywords, then those |
2204 // should be persisted to disk and synced. | 2207 // should be persisted to disk and synced. |
2205 if (template_url->sync_guid().empty() && | 2208 if (template_url->sync_guid().empty() && |
2206 !template_url->IsExtensionKeyword()) { | 2209 !template_url->IsExtensionKeyword()) { |
2207 template_url->data_.sync_guid = guid::GenerateGUID(); | 2210 template_url->data_.sync_guid = guid::GenerateGUID(); |
2208 if (service_.get()) | 2211 if (service_.get()) |
2209 service_->UpdateKeyword(template_url->data()); | 2212 service_->UpdateKeyword(template_url->data()); |
2210 } | 2213 } |
2211 } | 2214 } |
2212 } | 2215 } |
OLD | NEW |