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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/search_engines/template_url_fetcher.h" | 7 #include "chrome/browser/search_engines/template_url_fetcher.h" |
8 | 8 |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/search_engines/template_url.h" | 12 #include "chrome/browser/search_engines/template_url.h" |
13 #include "chrome/browser/search_engines/template_url_fetcher_callbacks.h" | 13 #include "chrome/browser/search_engines/template_url_fetcher_callbacks.h" |
14 #include "chrome/browser/search_engines/template_url_service.h" | 14 #include "chrome/browser/search_engines/template_url_service.h" |
15 #include "chrome/browser/search_engines/template_url_service_factory.h" | 15 #include "chrome/browser/search_engines/template_url_service_factory.h" |
16 #include "chrome/browser/search_engines/template_url_parser.h" | 16 #include "chrome/browser/search_engines/template_url_parser.h" |
| 17 #include "chrome/common/chrome_notification_types.h" |
17 #include "content/common/notification_observer.h" | 18 #include "content/common/notification_observer.h" |
18 #include "content/common/notification_registrar.h" | 19 #include "content/common/notification_registrar.h" |
19 #include "content/common/notification_source.h" | 20 #include "content/common/notification_source.h" |
20 #include "content/common/notification_type.h" | |
21 #include "content/common/url_fetcher.h" | 21 #include "content/common/url_fetcher.h" |
22 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
23 | 23 |
24 // RequestDelegate ------------------------------------------------------------ | 24 // RequestDelegate ------------------------------------------------------------ |
25 class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, | 25 class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, |
26 public NotificationObserver { | 26 public NotificationObserver { |
27 public: | 27 public: |
28 // Takes ownership of |callbacks|. | 28 // Takes ownership of |callbacks|. |
29 RequestDelegate(TemplateURLFetcher* fetcher, | 29 RequestDelegate(TemplateURLFetcher* fetcher, |
30 const string16& keyword, | 30 const string16& keyword, |
31 const GURL& osdd_url, | 31 const GURL& osdd_url, |
32 const GURL& favicon_url, | 32 const GURL& favicon_url, |
33 TemplateURLFetcherCallbacks* callbacks, | 33 TemplateURLFetcherCallbacks* callbacks, |
34 ProviderType provider_type); | 34 ProviderType provider_type); |
35 | 35 |
36 // NotificationObserver: | 36 // NotificationObserver: |
37 virtual void Observe(NotificationType type, | 37 virtual void Observe(int type, |
38 const NotificationSource& source, | 38 const NotificationSource& source, |
39 const NotificationDetails& details); | 39 const NotificationDetails& details); |
40 | 40 |
41 // URLFetcher::Delegate: | 41 // URLFetcher::Delegate: |
42 // If data contains a valid OSDD, a TemplateURL is created and added to | 42 // If data contains a valid OSDD, a TemplateURL is created and added to |
43 // the TemplateURLService. | 43 // the TemplateURLService. |
44 virtual void OnURLFetchComplete(const URLFetcher* source, | 44 virtual void OnURLFetchComplete(const URLFetcher* source, |
45 const GURL& url, | 45 const GURL& url, |
46 const net::URLRequestStatus& status, | 46 const net::URLRequestStatus& status, |
47 int response_code, | 47 int response_code, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 favicon_url_(favicon_url), | 90 favicon_url_(favicon_url), |
91 provider_type_(provider_type), | 91 provider_type_(provider_type), |
92 callbacks_(callbacks) { | 92 callbacks_(callbacks) { |
93 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | 93 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( |
94 fetcher_->profile()); | 94 fetcher_->profile()); |
95 DCHECK(model); // TemplateURLFetcher::ScheduleDownload verifies this. | 95 DCHECK(model); // TemplateURLFetcher::ScheduleDownload verifies this. |
96 | 96 |
97 if (!model->loaded()) { | 97 if (!model->loaded()) { |
98 // Start the model load and set-up waiting for it. | 98 // Start the model load and set-up waiting for it. |
99 registrar_.Add(this, | 99 registrar_.Add(this, |
100 NotificationType::TEMPLATE_URL_SERVICE_LOADED, | 100 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
101 Source<TemplateURLService>(model)); | 101 Source<TemplateURLService>(model)); |
102 model->Load(); | 102 model->Load(); |
103 } | 103 } |
104 | 104 |
105 url_fetcher_.set_request_context(fetcher->profile()->GetRequestContext()); | 105 url_fetcher_.set_request_context(fetcher->profile()->GetRequestContext()); |
106 url_fetcher_.Start(); | 106 url_fetcher_.Start(); |
107 } | 107 } |
108 | 108 |
109 void TemplateURLFetcher::RequestDelegate::Observe( | 109 void TemplateURLFetcher::RequestDelegate::Observe( |
110 NotificationType type, | 110 int type, |
111 const NotificationSource& source, | 111 const NotificationSource& source, |
112 const NotificationDetails& details) { | 112 const NotificationDetails& details) { |
113 DCHECK(type == NotificationType::TEMPLATE_URL_SERVICE_LOADED); | 113 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); |
114 | 114 |
115 if (!template_url_.get()) | 115 if (!template_url_.get()) |
116 return; | 116 return; |
117 AddSearchProvider(); | 117 AddSearchProvider(); |
118 // WARNING: AddSearchProvider deletes us. | 118 // WARNING: AddSearchProvider deletes us. |
119 } | 119 } |
120 | 120 |
121 void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete( | 121 void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete( |
122 const URLFetcher* source, | 122 const URLFetcher* source, |
123 const GURL& url, | 123 const GURL& url, |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 new RequestDelegate(this, keyword, osdd_url, favicon_url, | 324 new RequestDelegate(this, keyword, osdd_url, favicon_url, |
325 owned_callbacks.release(), provider_type)); | 325 owned_callbacks.release(), provider_type)); |
326 } | 326 } |
327 | 327 |
328 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { | 328 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { |
329 DCHECK(find(requests_->begin(), requests_->end(), request) != | 329 DCHECK(find(requests_->begin(), requests_->end(), request) != |
330 requests_->end()); | 330 requests_->end()); |
331 requests_->erase(find(requests_->begin(), requests_->end(), request)); | 331 requests_->erase(find(requests_->begin(), requests_->end(), request)); |
332 delete request; | 332 delete request; |
333 } | 333 } |
OLD | NEW |