| OLD | NEW |
| 1 // Copyright (c) 2010 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" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 35 // NotificationObserver: | 35 // NotificationObserver: |
| 36 virtual void Observe(NotificationType type, | 36 virtual void Observe(NotificationType type, |
| 37 const NotificationSource& source, | 37 const NotificationSource& source, |
| 38 const NotificationDetails& details); | 38 const NotificationDetails& details); |
| 39 | 39 |
| 40 // URLFetcher::Delegate: | 40 // URLFetcher::Delegate: |
| 41 // If data contains a valid OSDD, a TemplateURL is created and added to | 41 // If data contains a valid OSDD, a TemplateURL is created and added to |
| 42 // the TemplateURLModel. | 42 // the TemplateURLModel. |
| 43 virtual void OnURLFetchComplete(const URLFetcher* source, | 43 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 44 const GURL& url, | 44 const GURL& url, |
| 45 const URLRequestStatus& status, | 45 const net::URLRequestStatus& status, |
| 46 int response_code, | 46 int response_code, |
| 47 const ResponseCookies& cookies, | 47 const ResponseCookies& cookies, |
| 48 const std::string& data); | 48 const std::string& data); |
| 49 | 49 |
| 50 // URL of the OSDD. | 50 // URL of the OSDD. |
| 51 const GURL& url() const { return osdd_url_; } | 51 const GURL& url() const { return osdd_url_; } |
| 52 | 52 |
| 53 // Keyword to use. | 53 // Keyword to use. |
| 54 const std::wstring keyword() const { return keyword_; } | 54 const std::wstring keyword() const { return keyword_; } |
| 55 | 55 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 if (!template_url_.get()) | 113 if (!template_url_.get()) |
| 114 return; | 114 return; |
| 115 AddSearchProvider(); | 115 AddSearchProvider(); |
| 116 // WARNING: AddSearchProvider deletes us. | 116 // WARNING: AddSearchProvider deletes us. |
| 117 } | 117 } |
| 118 | 118 |
| 119 void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete( | 119 void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete( |
| 120 const URLFetcher* source, | 120 const URLFetcher* source, |
| 121 const GURL& url, | 121 const GURL& url, |
| 122 const URLRequestStatus& status, | 122 const net::URLRequestStatus& status, |
| 123 int response_code, | 123 int response_code, |
| 124 const ResponseCookies& cookies, | 124 const ResponseCookies& cookies, |
| 125 const std::string& data) { | 125 const std::string& data) { |
| 126 template_url_.reset(new TemplateURL()); | 126 template_url_.reset(new TemplateURL()); |
| 127 | 127 |
| 128 // Validation checks. | 128 // Validation checks. |
| 129 // Make sure we can still replace the keyword, i.e. the fetch was successful. | 129 // Make sure we can still replace the keyword, i.e. the fetch was successful. |
| 130 // If the OSDD file was loaded HTTP, we also have to check the response_code. | 130 // If the OSDD file was loaded HTTP, we also have to check the response_code. |
| 131 // For other schemes, e.g. when the OSDD file is bundled with an extension, | 131 // For other schemes, e.g. when the OSDD file is bundled with an extension, |
| 132 // the response_code is not applicable and should be -1. Also, ensure that | 132 // the response_code is not applicable and should be -1. Also, ensure that |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 new RequestDelegate(this, keyword, osdd_url, favicon_url, | 319 new RequestDelegate(this, keyword, osdd_url, favicon_url, |
| 320 owned_callbacks.release(), provider_type)); | 320 owned_callbacks.release(), provider_type)); |
| 321 } | 321 } |
| 322 | 322 |
| 323 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { | 323 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { |
| 324 DCHECK(find(requests_->begin(), requests_->end(), request) != | 324 DCHECK(find(requests_->begin(), requests_->end(), request) != |
| 325 requests_->end()); | 325 requests_->end()); |
| 326 requests_->erase(find(requests_->begin(), requests_->end(), request)); | 326 requests_->erase(find(requests_->begin(), requests_->end(), request)); |
| 327 delete request; | 327 delete request; |
| 328 } | 328 } |
| OLD | NEW |