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

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

Issue 8375039: Create a content::UrlFetcher interface that lives in content/public/common and convert users to i... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 9 years, 2 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 "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"
(...skipping 25 matching lines...) Expand all
36 ProviderType provider_type); 36 ProviderType provider_type);
37 37
38 // content::NotificationObserver: 38 // content::NotificationObserver:
39 virtual void Observe(int type, 39 virtual void Observe(int type,
40 const content::NotificationSource& source, 40 const content::NotificationSource& source,
41 const content::NotificationDetails& details); 41 const content::NotificationDetails& details);
42 42
43 // content::URLFetcherDelegate: 43 // content::URLFetcherDelegate:
44 // If data contains a valid OSDD, a TemplateURL is created and added to 44 // If data contains a valid OSDD, a TemplateURL is created and added to
45 // the TemplateURLService. 45 // the TemplateURLService.
46 virtual void OnURLFetchComplete(const URLFetcher* source); 46 virtual void OnURLFetchComplete(const content::URLFetcher* source);
47 47
48 // URL of the OSDD. 48 // URL of the OSDD.
49 GURL url() const { return osdd_url_; } 49 GURL url() const { return osdd_url_; }
50 50
51 // Keyword to use. 51 // Keyword to use.
52 string16 keyword() const { return keyword_; } 52 string16 keyword() const { return keyword_; }
53 53
54 // The type of search provider being fetched. 54 // The type of search provider being fetched.
55 ProviderType provider_type() const { return provider_type_; } 55 ProviderType provider_type() const { return provider_type_; }
56 56
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 DCHECK(model); // TemplateURLFetcher::ScheduleDownload verifies this. 92 DCHECK(model); // TemplateURLFetcher::ScheduleDownload verifies this.
93 93
94 if (!model->loaded()) { 94 if (!model->loaded()) {
95 // Start the model load and set-up waiting for it. 95 // Start the model load and set-up waiting for it.
96 registrar_.Add(this, 96 registrar_.Add(this,
97 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, 97 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
98 content::Source<TemplateURLService>(model)); 98 content::Source<TemplateURLService>(model));
99 model->Load(); 99 model->Load();
100 } 100 }
101 101
102 url_fetcher_.set_request_context(fetcher->profile()->GetRequestContext()); 102 url_fetcher_.SetRequestContext(fetcher->profile()->GetRequestContext());
103 url_fetcher_.Start(); 103 url_fetcher_.Start();
104 } 104 }
105 105
106 void TemplateURLFetcher::RequestDelegate::Observe( 106 void TemplateURLFetcher::RequestDelegate::Observe(
107 int type, 107 int type,
108 const content::NotificationSource& source, 108 const content::NotificationSource& source,
109 const content::NotificationDetails& details) { 109 const content::NotificationDetails& details) {
110 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); 110 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED);
111 111
112 if (!template_url_.get()) 112 if (!template_url_.get())
113 return; 113 return;
114 AddSearchProvider(); 114 AddSearchProvider();
115 // WARNING: AddSearchProvider deletes us. 115 // WARNING: AddSearchProvider deletes us.
116 } 116 }
117 117
118 void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete( 118 void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete(
119 const URLFetcher* source) { 119 const content::URLFetcher* source) {
120 template_url_.reset(new TemplateURL()); 120 template_url_.reset(new TemplateURL());
121 121
122 // Validation checks. 122 // Validation checks.
123 // Make sure we can still replace the keyword, i.e. the fetch was successful. 123 // Make sure we can still replace the keyword, i.e. the fetch was successful.
124 // If the OSDD file was loaded HTTP, we also have to check the response_code. 124 // If the OSDD file was loaded HTTP, we also have to check the response_code.
125 // For other schemes, e.g. when the OSDD file is bundled with an extension, 125 // For other schemes, e.g. when the OSDD file is bundled with an extension,
126 // the response_code is not applicable and should be -1. Also, ensure that 126 // the response_code is not applicable and should be -1. Also, ensure that
127 // the returned information results in a valid search URL. 127 // the returned information results in a valid search URL.
128 std::string data; 128 std::string data;
129 if (!source->status().is_success() || 129 if (!source->GetStatus().is_success() ||
130 ((source->response_code() != -1) && (source->response_code() != 200)) || 130 ((source->GetResponseCode() != -1) &&
131 (source->GetResponseCode() != 200)) ||
131 !source->GetResponseAsString(&data) || 132 !source->GetResponseAsString(&data) ||
132 !TemplateURLParser::Parse( 133 !TemplateURLParser::Parse(
133 reinterpret_cast<const unsigned char*>(data.c_str()), 134 reinterpret_cast<const unsigned char*>(data.c_str()),
134 data.length(), 135 data.length(),
135 NULL, 136 NULL,
136 template_url_.get()) || 137 template_url_.get()) ||
137 !template_url_->url() || !template_url_->url()->SupportsReplacement()) { 138 !template_url_->url() || !template_url_->url()->SupportsReplacement()) {
138 fetcher_->RequestCompleted(this); 139 fetcher_->RequestCompleted(this);
139 // WARNING: RequestCompleted deletes us. 140 // WARNING: RequestCompleted deletes us.
140 return; 141 return;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 new RequestDelegate(this, keyword, osdd_url, favicon_url, 319 new RequestDelegate(this, keyword, osdd_url, favicon_url,
319 owned_callbacks.release(), provider_type)); 320 owned_callbacks.release(), provider_type));
320 } 321 }
321 322
322 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { 323 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) {
323 DCHECK(find(requests_->begin(), requests_->end(), request) != 324 DCHECK(find(requests_->begin(), requests_->end(), request) !=
324 requests_->end()); 325 requests_->end());
325 requests_->erase(find(requests_->begin(), requests_->end(), request)); 326 requests_->erase(find(requests_->begin(), requests_->end(), request));
326 delete request; 327 delete request;
327 } 328 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_test.cc ('k') | chrome/browser/spellchecker/spellcheck_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698