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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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/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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/task.h" 12 #include "base/task.h"
13 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 13 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
14 #include "chrome/browser/search_engines/search_terms_data.h" 14 #include "chrome/browser/search_engines/search_terms_data.h"
15 #include "chrome/browser/search_engines/template_url.h" 15 #include "chrome/browser/search_engines/template_url.h"
16 #include "chrome/browser/search_engines/template_url_service.h" 16 #include "chrome/browser/search_engines/template_url_service.h"
17 #include "chrome/browser/search_engines/util.h" 17 #include "chrome/browser/search_engines/util.h"
18 #include "chrome/browser/webdata/web_data_service.h" 18 #include "chrome/browser/webdata/web_data_service.h"
19 #include "chrome/common/chrome_notification_types.h"
19 #include "content/browser/browser_thread.h" 20 #include "content/browser/browser_thread.h"
20 #include "content/common/notification_observer.h" 21 #include "content/common/notification_observer.h"
21 #include "content/common/notification_registrar.h" 22 #include "content/common/notification_registrar.h"
22 #include "content/common/notification_service.h" 23 #include "content/common/notification_service.h"
23 #include "content/common/notification_source.h" 24 #include "content/common/notification_source.h"
24 #include "content/common/notification_type.h"
25 25
26 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet; 26 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet;
27 27
28 namespace { 28 namespace {
29 29
30 // Implementation of SearchTermsData that may be used on the I/O thread. 30 // Implementation of SearchTermsData that may be used on the I/O thread.
31 class IOThreadSearchTermsData : public SearchTermsData { 31 class IOThreadSearchTermsData : public SearchTermsData {
32 public: 32 public:
33 explicit IOThreadSearchTermsData(const std::string& google_base_url); 33 explicit IOThreadSearchTermsData(const std::string& google_base_url);
34 34
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 if (install_data_) 96 if (install_data_)
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 NotificationType ui_death_notification, 106 int ui_death_notification,
107 const NotificationSource& ui_death_source); 107 const NotificationSource& ui_death_source);
108 108
109 // Implementation of NotificationObserver. 109 // Implementation of NotificationObserver.
110 virtual void Observe(NotificationType type, 110 virtual void Observe(int type,
111 const NotificationSource& source, 111 const NotificationSource& source,
112 const NotificationDetails& details); 112 const NotificationDetails& details);
113 113
114 private: 114 private:
115 virtual ~GoogleURLObserver() {} 115 virtual ~GoogleURLObserver() {}
116 116
117 scoped_refptr<GoogleURLChangeNotifier> change_notifier_; 117 scoped_refptr<GoogleURLChangeNotifier> change_notifier_;
118 NotificationRegistrar registrar_; 118 NotificationRegistrar registrar_;
119 119
120 DISALLOW_COPY_AND_ASSIGN(GoogleURLObserver); 120 DISALLOW_COPY_AND_ASSIGN(GoogleURLObserver);
121 }; 121 };
122 122
123 GoogleURLObserver::GoogleURLObserver( 123 GoogleURLObserver::GoogleURLObserver(
124 GoogleURLChangeNotifier* change_notifier, 124 GoogleURLChangeNotifier* change_notifier,
125 NotificationType ui_death_notification, 125 int ui_death_notification,
126 const NotificationSource& ui_death_source) 126 const NotificationSource& ui_death_source)
127 : change_notifier_(change_notifier) { 127 : change_notifier_(change_notifier) {
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
129 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED, 129 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
130 NotificationService::AllSources()); 130 NotificationService::AllSources());
131 registrar_.Add(this, ui_death_notification, ui_death_source); 131 registrar_.Add(this, ui_death_notification, ui_death_source);
132 } 132 }
133 133
134 void GoogleURLObserver::Observe(NotificationType type, 134 void GoogleURLObserver::Observe(int type,
135 const NotificationSource& source, 135 const NotificationSource& source,
136 const NotificationDetails& details) { 136 const NotificationDetails& details) {
137 if (type == NotificationType::GOOGLE_URL_UPDATED) { 137 if (type == chrome::NOTIFICATION_GOOGLE_URL_UPDATED) {
138 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 138 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
139 NewRunnableMethod(change_notifier_.get(), 139 NewRunnableMethod(change_notifier_.get(),
140 &GoogleURLChangeNotifier::OnChange, 140 &GoogleURLChangeNotifier::OnChange,
141 UIThreadSearchTermsData().GoogleBaseURLValue())); 141 UIThreadSearchTermsData().GoogleBaseURLValue()));
142 } else { 142 } else {
143 // This must be the death notification. 143 // This must be the death notification.
144 delete this; 144 delete this;
145 } 145 }
146 } 146 }
147 147
148 // Indicates if the two inputs have the same security origin. 148 // Indicates if the two inputs have the same security origin.
149 // |requested_origin| should only be a security origin (no path, etc.). 149 // |requested_origin| should only be a security origin (no path, etc.).
150 // It is ok if |template_url| is NULL. 150 // It is ok if |template_url| is NULL.
151 static bool IsSameOrigin(const GURL& requested_origin, 151 static bool IsSameOrigin(const GURL& requested_origin,
152 const TemplateURL* template_url, 152 const TemplateURL* template_url,
153 const SearchTermsData& search_terms_data) { 153 const SearchTermsData& search_terms_data) {
154 DCHECK(requested_origin == requested_origin.GetOrigin()); 154 DCHECK(requested_origin == requested_origin.GetOrigin());
155 return template_url && requested_origin == 155 return template_url && requested_origin ==
156 TemplateURLService::GenerateSearchURLUsingTermsData( 156 TemplateURLService::GenerateSearchURLUsingTermsData(
157 template_url, 157 template_url,
158 search_terms_data).GetOrigin(); 158 search_terms_data).GetOrigin();
159 } 159 }
160 160
161 } // namespace 161 } // namespace
162 162
163 SearchProviderInstallData::SearchProviderInstallData( 163 SearchProviderInstallData::SearchProviderInstallData(
164 WebDataService* web_service, 164 WebDataService* web_service,
165 NotificationType ui_death_notification, 165 int ui_death_notification,
166 const NotificationSource& ui_death_source) 166 const NotificationSource& ui_death_source)
167 : web_service_(web_service), 167 : web_service_(web_service),
168 load_handle_(0), 168 load_handle_(0),
169 google_base_url_(UIThreadSearchTermsData().GoogleBaseURLValue()) { 169 google_base_url_(UIThreadSearchTermsData().GoogleBaseURLValue()) {
170 // GoogleURLObserver is responsible for killing itself when 170 // GoogleURLObserver is responsible for killing itself when
171 // the given notification occurs. 171 // the given notification occurs.
172 new GoogleURLObserver(new GoogleURLChangeNotifier(AsWeakPtr()), 172 new GoogleURLObserver(new GoogleURLChangeNotifier(AsWeakPtr()),
173 ui_death_notification, ui_death_source); 173 ui_death_notification, ui_death_source);
174 DetachFromThread(); 174 DetachFromThread();
175 } 175 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 void SearchProviderInstallData::NotifyLoaded() { 298 void SearchProviderInstallData::NotifyLoaded() {
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
300 300
301 task_queue_.Run(); 301 task_queue_.Run();
302 302
303 // Since we expect this request to be rare, clear out the information. This 303 // Since we expect this request to be rare, clear out the information. This
304 // also keeps the responses current as the search providers change. 304 // also keeps the responses current as the search providers change.
305 provider_map_.reset(); 305 provider_map_.reset();
306 SetDefault(NULL); 306 SetDefault(NULL);
307 } 307 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698