Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/template_url_fetcher.h" | 5 #include "components/search_engines/template_url_fetcher.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "components/search_engines/template_url.h" | 12 #include "components/search_engines/template_url.h" |
| 13 #include "components/search_engines/template_url_parser.h" | 13 #include "components/search_engines/template_url_parser.h" |
| 14 #include "components/search_engines/template_url_service.h" | 14 #include "components/search_engines/template_url_service.h" |
| 15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
| 16 #include "net/traffic_annotation/network_traffic_annotation.h" | |
| 16 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
| 17 #include "net/url_request/url_fetcher_delegate.h" | 18 #include "net/url_request/url_fetcher_delegate.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
| 19 #include "net/url_request/url_request_status.h" | 20 #include "net/url_request/url_request_status.h" |
| 20 | 21 |
| 22 namespace { | |
| 23 // Traffic annotation for ReqeustDelegate | |
|
Peter Kasting
2017/02/28 01:00:15
Nit: RequestDelegate. Also, add trailing period.
Ramin Halavati
2017/02/28 07:33:22
Done.
| |
| 24 constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = | |
| 25 net::DefineNetworkTrafficAnnotation("open_search", R"( | |
| 26 semantics { | |
| 27 sender: "Omnibox" | |
| 28 description: | |
| 29 "Web pages can include an OpenSearch description doc in their HTML. " | |
| 30 "In this case Chromium downloads and parses the file. The " | |
| 31 "corresponding search engine is added to the list in the browser " | |
|
Peter Kasting
2017/02/28 01:00:15
Nit: browser -> browser settings (or just "setting
Ramin Halavati
2017/02/28 07:33:22
Done.
| |
| 32 "(chrome://settings/searchEngines)." | |
| 33 trigger: | |
| 34 "User visits a web page containing a <link rel="search"> tag." | |
| 35 data: "None" | |
| 36 destination: WEBSITE | |
| 37 } | |
| 38 policy { | |
| 39 cookies_allowed: false | |
| 40 setting: "This feature cannot be disabled in settings." | |
| 41 policy_exception_justification: | |
| 42 "Not implemented, considered not useful as this feature does not " | |
| 43 "upload any data." | |
| 44 })"); | |
| 45 } // namespace | |
| 46 | |
| 21 // RequestDelegate ------------------------------------------------------------ | 47 // RequestDelegate ------------------------------------------------------------ |
| 22 class TemplateURLFetcher::RequestDelegate : public net::URLFetcherDelegate { | 48 class TemplateURLFetcher::RequestDelegate : public net::URLFetcherDelegate { |
| 23 public: | 49 public: |
| 24 RequestDelegate( | 50 RequestDelegate( |
| 25 TemplateURLFetcher* fetcher, | 51 TemplateURLFetcher* fetcher, |
| 26 const base::string16& keyword, | 52 const base::string16& keyword, |
| 27 const GURL& osdd_url, | 53 const GURL& osdd_url, |
| 28 const GURL& favicon_url, | 54 const GURL& favicon_url, |
| 29 const URLFetcherCustomizeCallback& url_fetcher_customize_callback); | 55 const URLFetcherCustomizeCallback& url_fetcher_customize_callback); |
| 30 | 56 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 54 | 80 |
| 55 DISALLOW_COPY_AND_ASSIGN(RequestDelegate); | 81 DISALLOW_COPY_AND_ASSIGN(RequestDelegate); |
| 56 }; | 82 }; |
| 57 | 83 |
| 58 TemplateURLFetcher::RequestDelegate::RequestDelegate( | 84 TemplateURLFetcher::RequestDelegate::RequestDelegate( |
| 59 TemplateURLFetcher* fetcher, | 85 TemplateURLFetcher* fetcher, |
| 60 const base::string16& keyword, | 86 const base::string16& keyword, |
| 61 const GURL& osdd_url, | 87 const GURL& osdd_url, |
| 62 const GURL& favicon_url, | 88 const GURL& favicon_url, |
| 63 const URLFetcherCustomizeCallback& url_fetcher_customize_callback) | 89 const URLFetcherCustomizeCallback& url_fetcher_customize_callback) |
| 64 : url_fetcher_( | 90 : url_fetcher_(net::URLFetcher::Create(osdd_url, |
| 65 net::URLFetcher::Create(osdd_url, net::URLFetcher::GET, this)), | 91 net::URLFetcher::GET, |
| 92 this, | |
| 93 kTrafficAnnotation)), | |
| 66 fetcher_(fetcher), | 94 fetcher_(fetcher), |
| 67 keyword_(keyword), | 95 keyword_(keyword), |
| 68 osdd_url_(osdd_url), | 96 osdd_url_(osdd_url), |
| 69 favicon_url_(favicon_url) { | 97 favicon_url_(favicon_url) { |
| 70 TemplateURLService* model = fetcher_->template_url_service_; | 98 TemplateURLService* model = fetcher_->template_url_service_; |
| 71 DCHECK(model); // TemplateURLFetcher::ScheduleDownload verifies this. | 99 DCHECK(model); // TemplateURLFetcher::ScheduleDownload verifies this. |
| 72 | 100 |
| 73 if (!model->loaded()) { | 101 if (!model->loaded()) { |
| 74 // Start the model load and set-up waiting for it. | 102 // Start the model load and set-up waiting for it. |
| 75 template_url_subscription_ = model->RegisterOnLoadedCallback( | 103 template_url_subscription_ = model->RegisterOnLoadedCallback( |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 } | 249 } |
| 222 | 250 |
| 223 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { | 251 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { |
| 224 auto i = std::find_if(requests_.begin(), requests_.end(), | 252 auto i = std::find_if(requests_.begin(), requests_.end(), |
| 225 [request](const std::unique_ptr<RequestDelegate>& ptr) { | 253 [request](const std::unique_ptr<RequestDelegate>& ptr) { |
| 226 return ptr.get() == request; | 254 return ptr.get() == request; |
| 227 }); | 255 }); |
| 228 DCHECK(i != requests_.end()); | 256 DCHECK(i != requests_.end()); |
| 229 requests_.erase(i); | 257 requests_.erase(i); |
| 230 } | 258 } |
| OLD | NEW |