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 |
| 24 // Traffic annotation for RequestDelegate. |
| 25 constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = |
| 26 net::DefineNetworkTrafficAnnotation("open_search", R"( |
| 27 semantics { |
| 28 sender: "Omnibox" |
| 29 description: |
| 30 "Web pages can include an OpenSearch description doc in their HTML. " |
| 31 "In this case Chromium downloads and parses the file. The " |
| 32 "corresponding search engine is added to the list in the browser " |
| 33 "settings (chrome://settings/searchEngines)." |
| 34 trigger: |
| 35 "User visits a web page containing a <link rel="search"> tag." |
| 36 data: "None" |
| 37 destination: WEBSITE |
| 38 } |
| 39 policy { |
| 40 cookies_allowed: false |
| 41 setting: "This feature cannot be disabled in settings." |
| 42 policy_exception_justification: |
| 43 "Not implemented, considered not useful as this feature does not " |
| 44 "upload any data." |
| 45 })"); |
| 46 |
| 47 } // namespace |
| 48 |
21 // RequestDelegate ------------------------------------------------------------ | 49 // RequestDelegate ------------------------------------------------------------ |
22 class TemplateURLFetcher::RequestDelegate : public net::URLFetcherDelegate { | 50 class TemplateURLFetcher::RequestDelegate : public net::URLFetcherDelegate { |
23 public: | 51 public: |
24 RequestDelegate( | 52 RequestDelegate( |
25 TemplateURLFetcher* fetcher, | 53 TemplateURLFetcher* fetcher, |
26 const base::string16& keyword, | 54 const base::string16& keyword, |
27 const GURL& osdd_url, | 55 const GURL& osdd_url, |
28 const GURL& favicon_url, | 56 const GURL& favicon_url, |
29 const URLFetcherCustomizeCallback& url_fetcher_customize_callback); | 57 const URLFetcherCustomizeCallback& url_fetcher_customize_callback); |
30 | 58 |
(...skipping 23 matching lines...) Expand all Loading... |
54 | 82 |
55 DISALLOW_COPY_AND_ASSIGN(RequestDelegate); | 83 DISALLOW_COPY_AND_ASSIGN(RequestDelegate); |
56 }; | 84 }; |
57 | 85 |
58 TemplateURLFetcher::RequestDelegate::RequestDelegate( | 86 TemplateURLFetcher::RequestDelegate::RequestDelegate( |
59 TemplateURLFetcher* fetcher, | 87 TemplateURLFetcher* fetcher, |
60 const base::string16& keyword, | 88 const base::string16& keyword, |
61 const GURL& osdd_url, | 89 const GURL& osdd_url, |
62 const GURL& favicon_url, | 90 const GURL& favicon_url, |
63 const URLFetcherCustomizeCallback& url_fetcher_customize_callback) | 91 const URLFetcherCustomizeCallback& url_fetcher_customize_callback) |
64 : url_fetcher_( | 92 : url_fetcher_(net::URLFetcher::Create(osdd_url, |
65 net::URLFetcher::Create(osdd_url, net::URLFetcher::GET, this)), | 93 net::URLFetcher::GET, |
| 94 this, |
| 95 kTrafficAnnotation)), |
66 fetcher_(fetcher), | 96 fetcher_(fetcher), |
67 keyword_(keyword), | 97 keyword_(keyword), |
68 osdd_url_(osdd_url), | 98 osdd_url_(osdd_url), |
69 favicon_url_(favicon_url) { | 99 favicon_url_(favicon_url) { |
70 TemplateURLService* model = fetcher_->template_url_service_; | 100 TemplateURLService* model = fetcher_->template_url_service_; |
71 DCHECK(model); // TemplateURLFetcher::ScheduleDownload verifies this. | 101 DCHECK(model); // TemplateURLFetcher::ScheduleDownload verifies this. |
72 | 102 |
73 if (!model->loaded()) { | 103 if (!model->loaded()) { |
74 // Start the model load and set-up waiting for it. | 104 // Start the model load and set-up waiting for it. |
75 template_url_subscription_ = model->RegisterOnLoadedCallback( | 105 template_url_subscription_ = model->RegisterOnLoadedCallback( |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 251 } |
222 | 252 |
223 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { | 253 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { |
224 auto i = std::find_if(requests_.begin(), requests_.end(), | 254 auto i = std::find_if(requests_.begin(), requests_.end(), |
225 [request](const std::unique_ptr<RequestDelegate>& ptr) { | 255 [request](const std::unique_ptr<RequestDelegate>& ptr) { |
226 return ptr.get() == request; | 256 return ptr.get() == request; |
227 }); | 257 }); |
228 DCHECK(i != requests_.end()); | 258 DCHECK(i != requests_.end()); |
229 requests_.erase(i); | 259 requests_.erase(i); |
230 } | 260 } |
OLD | NEW |