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 | |
| 24 constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = | |
| 25 net::DefineNetworkTrafficAnnotation("...", R"( | |
|
vasilii
2017/02/24 14:42:38
open_search
Ramin Halavati
2017/02/24 14:57:56
Done.
| |
| 26 semantics { | |
| 27 sender: "..." | |
|
vasilii
2017/02/24 14:42:38
open_search_fetcher
Ramin Halavati
2017/02/24 14:57:56
Done.
| |
| 28 description: "..." | |
|
vasilii
2017/02/24 14:42:38
The web pages can include an OpenSearch descriptio
Ramin Halavati
2017/02/24 14:57:56
Done.
| |
| 29 trigger: "..." | |
|
vasilii
2017/02/24 14:42:38
User visits a web page containing <link rel="sear
Ramin Halavati
2017/02/24 14:57:56
Done.
| |
| 30 data: "..." | |
|
vasilii
2017/02/24 14:42:38
Nothing is uploaded.
Ramin Halavati
2017/02/24 14:57:56
Done.
| |
| 31 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
|
vasilii
2017/02/24 14:42:38
WEBSITE
Ramin Halavati
2017/02/24 14:57:57
Done.
| |
| 32 } | |
| 33 policy { | |
| 34 cookies_allowed: false/true | |
|
vasilii
2017/02/24 14:42:38
true
Ramin Halavati
2017/02/24 14:57:56
Done.
| |
| 35 cookies_store: "..." | |
|
vasilii
2017/02/24 14:42:38
user
Ramin Halavati
2017/02/24 14:57:56
Done.
| |
| 36 setting: "..." | |
|
vasilii
2017/02/24 14:42:38
N/A
Ramin Halavati
2017/02/24 14:57:56
Done.
| |
| 37 policy { | |
| 38 [POLICY_NAME] { | |
| 39 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
| 40 value: ... | |
| 41 } | |
| 42 } | |
| 43 policy_exception_justification: "..." | |
|
vasilii
2017/02/24 14:42:37
It's a web feature?
Ramin Halavati
2017/02/24 14:57:57
Done.
| |
| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 } | 246 } |
| 219 | 247 |
| 220 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { | 248 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { |
| 221 auto i = std::find_if(requests_.begin(), requests_.end(), | 249 auto i = std::find_if(requests_.begin(), requests_.end(), |
| 222 [request](const std::unique_ptr<RequestDelegate>& ptr) { | 250 [request](const std::unique_ptr<RequestDelegate>& ptr) { |
| 223 return ptr.get() == request; | 251 return ptr.get() == request; |
| 224 }); | 252 }); |
| 225 DCHECK(i != requests_.end()); | 253 DCHECK(i != requests_.end()); |
| 226 requests_.erase(i); | 254 requests_.erase(i); |
| 227 } | 255 } |
| OLD | NEW |