OLD | NEW |
---|---|
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/search_provider_install_data.h" | 5 #include "chrome/browser/search_engines/search_provider_install_data.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 install_data_->OnGoogleURLChange(google_base_url); | 97 install_data_->OnGoogleURLChange(google_base_url); |
98 } | 98 } |
99 | 99 |
100 // Notices changes in the Google base URL and sends them along | 100 // Notices changes in the Google base URL and sends them along |
101 // to the SearchProviderInstallData on the I/O thread. | 101 // to the SearchProviderInstallData on the I/O thread. |
102 class GoogleURLObserver : public NotificationObserver { | 102 class GoogleURLObserver : public NotificationObserver { |
103 public: | 103 public: |
104 GoogleURLObserver( | 104 GoogleURLObserver( |
105 GoogleURLChangeNotifier* change_notifier, | 105 GoogleURLChangeNotifier* change_notifier, |
106 int ui_death_notification, | 106 int ui_death_notification, |
107 const NotificationSource& ui_death_source); | 107 const NotificationSource& ui_death_source, |
108 Profile* profile); | |
108 | 109 |
109 // Implementation of NotificationObserver. | 110 // Implementation of NotificationObserver. |
110 virtual void Observe(int type, | 111 virtual void Observe(int type, |
111 const NotificationSource& source, | 112 const NotificationSource& source, |
112 const NotificationDetails& details); | 113 const NotificationDetails& details); |
113 | 114 |
114 private: | 115 private: |
115 virtual ~GoogleURLObserver() {} | 116 virtual ~GoogleURLObserver() {} |
116 | 117 |
117 scoped_refptr<GoogleURLChangeNotifier> change_notifier_; | 118 scoped_refptr<GoogleURLChangeNotifier> change_notifier_; |
118 NotificationRegistrar registrar_; | 119 NotificationRegistrar registrar_; |
120 Profile* const profile_; | |
119 | 121 |
120 DISALLOW_COPY_AND_ASSIGN(GoogleURLObserver); | 122 DISALLOW_COPY_AND_ASSIGN(GoogleURLObserver); |
121 }; | 123 }; |
122 | 124 |
123 GoogleURLObserver::GoogleURLObserver( | 125 GoogleURLObserver::GoogleURLObserver( |
124 GoogleURLChangeNotifier* change_notifier, | 126 GoogleURLChangeNotifier* change_notifier, |
125 int ui_death_notification, | 127 int ui_death_notification, |
126 const NotificationSource& ui_death_source) | 128 const NotificationSource& ui_death_source, |
127 : change_notifier_(change_notifier) { | 129 Profile* profile) |
130 : change_notifier_(change_notifier), | |
131 profile_(profile) { | |
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
129 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 133 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
130 NotificationService::AllSources()); | 134 NotificationService::AllSources()); |
131 registrar_.Add(this, ui_death_notification, ui_death_source); | 135 registrar_.Add(this, ui_death_notification, ui_death_source); |
132 } | 136 } |
133 | 137 |
134 void GoogleURLObserver::Observe(int type, | 138 void GoogleURLObserver::Observe(int type, |
135 const NotificationSource& source, | 139 const NotificationSource& source, |
136 const NotificationDetails& details) { | 140 const NotificationDetails& details) { |
137 if (type == chrome::NOTIFICATION_GOOGLE_URL_UPDATED) { | 141 if (type == chrome::NOTIFICATION_GOOGLE_URL_UPDATED) { |
138 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 142 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
139 NewRunnableMethod(change_notifier_.get(), | 143 NewRunnableMethod(change_notifier_.get(), |
140 &GoogleURLChangeNotifier::OnChange, | 144 &GoogleURLChangeNotifier::OnChange, |
141 UIThreadSearchTermsData().GoogleBaseURLValue())); | 145 UIThreadSearchTermsData(profile_).GoogleBaseURLValue())); |
Peter Kasting
2011/08/10 20:54:06
Neither caller in this file is asking for the inst
| |
142 } else { | 146 } else { |
143 // This must be the death notification. | 147 // This must be the death notification. |
144 delete this; | 148 delete this; |
145 } | 149 } |
146 } | 150 } |
147 | 151 |
148 // Indicates if the two inputs have the same security origin. | 152 // Indicates if the two inputs have the same security origin. |
149 // |requested_origin| should only be a security origin (no path, etc.). | 153 // |requested_origin| should only be a security origin (no path, etc.). |
150 // It is ok if |template_url| is NULL. | 154 // It is ok if |template_url| is NULL. |
151 static bool IsSameOrigin(const GURL& requested_origin, | 155 static bool IsSameOrigin(const GURL& requested_origin, |
152 const TemplateURL* template_url, | 156 const TemplateURL* template_url, |
153 const SearchTermsData& search_terms_data) { | 157 const SearchTermsData& search_terms_data) { |
154 DCHECK(requested_origin == requested_origin.GetOrigin()); | 158 DCHECK(requested_origin == requested_origin.GetOrigin()); |
155 return template_url && requested_origin == | 159 return template_url && requested_origin == |
156 TemplateURLService::GenerateSearchURLUsingTermsData( | 160 TemplateURLService::GenerateSearchURLUsingTermsData( |
157 template_url, | 161 template_url, |
158 search_terms_data).GetOrigin(); | 162 search_terms_data).GetOrigin(); |
159 } | 163 } |
160 | 164 |
161 } // namespace | 165 } // namespace |
162 | 166 |
163 SearchProviderInstallData::SearchProviderInstallData( | 167 SearchProviderInstallData::SearchProviderInstallData( |
164 WebDataService* web_service, | 168 WebDataService* web_service, |
165 int ui_death_notification, | 169 int ui_death_notification, |
166 const NotificationSource& ui_death_source) | 170 const NotificationSource& ui_death_source, |
171 Profile* profile) | |
167 : web_service_(web_service), | 172 : web_service_(web_service), |
168 load_handle_(0), | 173 load_handle_(0), |
169 google_base_url_(UIThreadSearchTermsData().GoogleBaseURLValue()) { | 174 google_base_url_(UIThreadSearchTermsData(profile).GoogleBaseURLValue()) { |
170 // GoogleURLObserver is responsible for killing itself when | 175 // GoogleURLObserver is responsible for killing itself when |
171 // the given notification occurs. | 176 // the given notification occurs. |
172 new GoogleURLObserver(new GoogleURLChangeNotifier(AsWeakPtr()), | 177 new GoogleURLObserver(new GoogleURLChangeNotifier(AsWeakPtr()), |
173 ui_death_notification, ui_death_source); | 178 ui_death_notification, ui_death_source, profile); |
174 DetachFromThread(); | 179 DetachFromThread(); |
175 } | 180 } |
176 | 181 |
177 SearchProviderInstallData::~SearchProviderInstallData() { | 182 SearchProviderInstallData::~SearchProviderInstallData() { |
178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
179 | 184 |
180 if (load_handle_) { | 185 if (load_handle_) { |
181 DCHECK(web_service_.get()); | 186 DCHECK(web_service_.get()); |
182 web_service_->CancelRequest(load_handle_); | 187 web_service_->CancelRequest(load_handle_); |
183 } | 188 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 void SearchProviderInstallData::NotifyLoaded() { | 303 void SearchProviderInstallData::NotifyLoaded() { |
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
300 | 305 |
301 task_queue_.Run(); | 306 task_queue_.Run(); |
302 | 307 |
303 // Since we expect this request to be rare, clear out the information. This | 308 // Since we expect this request to be rare, clear out the information. This |
304 // also keeps the responses current as the search providers change. | 309 // also keeps the responses current as the search providers change. |
305 provider_map_.reset(); | 310 provider_map_.reset(); |
306 SetDefault(NULL); | 311 SetDefault(NULL); |
307 } | 312 } |
OLD | NEW |