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 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ | 5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ |
| 6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ | 6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 } | 24 } |
| 25 | 25 |
| 26 // TemplateURLFetcher is responsible for downloading OpenSearch description | 26 // TemplateURLFetcher is responsible for downloading OpenSearch description |
| 27 // documents, creating a TemplateURL from the OSDD, and adding the TemplateURL | 27 // documents, creating a TemplateURL from the OSDD, and adding the TemplateURL |
| 28 // to the TemplateURLService. Downloading is done in the background. | 28 // to the TemplateURLService. Downloading is done in the background. |
| 29 // | 29 // |
| 30 class TemplateURLFetcher : public KeyedService { | 30 class TemplateURLFetcher : public KeyedService { |
| 31 public: | 31 public: |
| 32 typedef base::Callback<void( | 32 typedef base::Callback<void( |
| 33 net::URLFetcher* url_fetcher)> URLFetcherCustomizeCallback; | 33 net::URLFetcher* url_fetcher)> URLFetcherCustomizeCallback; |
| 34 typedef base::Callback<void(std::unique_ptr<TemplateURL> template_url)> | |
| 35 ConfirmAddSearchProviderCallback; | |
| 36 | |
| 37 enum ProviderType { | |
| 38 AUTODETECTED_PROVIDER, | |
| 39 EXPLICIT_PROVIDER // Supplied by Javascript. | |
| 40 }; | |
| 41 | 34 |
| 42 // Creates a TemplateURLFetcher. | 35 // Creates a TemplateURLFetcher. |
| 43 TemplateURLFetcher(TemplateURLService* template_url_service, | 36 TemplateURLFetcher(TemplateURLService* template_url_service, |
| 44 net::URLRequestContextGetter* request_context); | 37 net::URLRequestContextGetter* request_context); |
| 45 ~TemplateURLFetcher() override; | 38 ~TemplateURLFetcher() override; |
| 46 | 39 |
| 47 // If TemplateURLFetcher is not already downloading the OSDD for osdd_url, | 40 // If TemplateURLFetcher is not already downloading the OSDD for osdd_url, |
| 48 // it is downloaded. If successful and the result can be parsed, a TemplateURL | 41 // it is downloaded. If successful and the result can be parsed, a TemplateURL |
| 49 // is added to the TemplateURLService. | 42 // is added to the TemplateURLService. |
| 50 // | 43 // |
| 51 // If |provider_type| is AUTODETECTED_PROVIDER, |keyword| must be non-empty, | 44 // |keyword| must be non-empty and if there's already a non-replaceable |
|
Peter Kasting
2016/05/09 22:24:00
Nit: "non-empty and if" -> "non-empty. If"
Evan Stade
2016/05/09 22:54:53
Done.
| |
| 52 // and if there's already a non-replaceable TemplateURL in the model for | 45 // TemplateURL in the model for |keyword|, or we're already downloading an |
| 53 // |keyword|, or we're already downloading an OSDD for this keyword, no | 46 // OSDD for this keyword, no download is started. |
| 54 // download is started. If |provider_type| is EXPLICIT_PROVIDER, |keyword| is | |
| 55 // ignored. | |
| 56 // | 47 // |
| 57 // If |url_fetcher_customize_callback| is not null, it's run after a | 48 // If |url_fetcher_customize_callback| is not null, it's run after a |
| 58 // URLFetcher is created. This callback can be used to set additional | 49 // URLFetcher is created. This callback can be used to set additional |
| 59 // parameters on the URLFetcher. | 50 // parameters on the URLFetcher. |
| 60 void ScheduleDownload( | 51 void ScheduleDownload( |
| 61 const base::string16& keyword, | 52 const base::string16& keyword, |
| 62 const GURL& osdd_url, | 53 const GURL& osdd_url, |
| 63 const GURL& favicon_url, | 54 const GURL& favicon_url, |
| 64 const URLFetcherCustomizeCallback& url_fetcher_customize_callback, | 55 const URLFetcherCustomizeCallback& url_fetcher_customize_callback); |
| 65 const ConfirmAddSearchProviderCallback& confirm_add_callback, | |
| 66 ProviderType provider_type); | |
| 67 | 56 |
| 68 // The current number of outstanding requests. | 57 // The current number of outstanding requests. |
| 69 int requests_count() const { return requests_.size(); } | 58 int requests_count() const { return requests_.size(); } |
| 70 | 59 |
| 71 private: | 60 protected: |
| 72 // A RequestDelegate is created to download each OSDD. When done downloading | 61 // A RequestDelegate is created to download each OSDD. When done downloading |
| 73 // RequestCompleted is invoked back on the TemplateURLFetcher. | 62 // RequestCompleted is invoked back on the TemplateURLFetcher. |
| 74 class RequestDelegate; | 63 class RequestDelegate; |
| 64 | |
| 65 // Invoked from the RequestDelegate when done downloading. Virtual for tests. | |
| 66 virtual void RequestCompleted(RequestDelegate* request); | |
| 67 | |
| 68 private: | |
| 75 friend class RequestDelegate; | 69 friend class RequestDelegate; |
| 76 | 70 |
| 77 typedef ScopedVector<RequestDelegate> Requests; | 71 typedef ScopedVector<RequestDelegate> Requests; |
| 78 | 72 |
| 79 // Invoked from the RequestDelegate when done downloading. | |
| 80 void RequestCompleted(RequestDelegate* request); | |
| 81 | |
| 82 TemplateURLService* template_url_service_; | 73 TemplateURLService* template_url_service_; |
| 83 scoped_refptr<net::URLRequestContextGetter> request_context_; | 74 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 84 | 75 |
| 85 // In progress requests. | 76 // In progress requests. |
| 86 Requests requests_; | 77 Requests requests_; |
| 87 | 78 |
| 88 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcher); | 79 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcher); |
| 89 }; | 80 }; |
| 90 | 81 |
| 91 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ | 82 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ |
| OLD | NEW |