1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_
8 #include "base/memory/scoped_vector.h"
9 #include "base/strings/string16.h"
10 #include "components/keyed_service/core/keyed_service.h"
11 #include "ui/gfx/native_widget_types.h"
16 class TemplateURLFetcherCallbacks
;
22 // TemplateURLFetcher is responsible for downloading OpenSearch description
23 // documents, creating a TemplateURL from the OSDD, and adding the TemplateURL
24 // to the TemplateURLService. Downloading is done in the background.
26 class TemplateURLFetcher
: public KeyedService
{
29 AUTODETECTED_PROVIDER
,
30 EXPLICIT_PROVIDER
// Supplied by Javascript.
33 // Creates a TemplateURLFetcher with the specified Profile.
34 explicit TemplateURLFetcher(Profile
* profile
);
35 virtual ~TemplateURLFetcher();
37 // If TemplateURLFetcher is not already downloading the OSDD for osdd_url,
38 // it is downloaded. If successful and the result can be parsed, a TemplateURL
39 // is added to the TemplateURLService. Takes ownership of |callbacks|.
41 // If |provider_type| is AUTODETECTED_PROVIDER, |keyword| must be non-empty,
42 // and if there's already a non-replaceable TemplateURL in the model for
43 // |keyword|, or we're already downloading an OSDD for this keyword, no
44 // download is started. If |provider_type| is EXPLICIT_PROVIDER, |keyword| is
47 // |web_contents| specifies which WebContents displays the page the OSDD is
48 // downloaded for. |web_contents| must not be NULL, except during tests.
49 void ScheduleDownload(const base::string16
& keyword
,
51 const GURL
& favicon_url
,
52 content::WebContents
* web_contents
,
53 TemplateURLFetcherCallbacks
* callbacks
,
54 ProviderType provider_type
);
56 // The current number of outstanding requests.
57 int requests_count() const { return requests_
.size(); }
60 // A RequestDelegate is created to download each OSDD. When done downloading
61 // RequestCompleted is invoked back on the TemplateURLFetcher.
62 class RequestDelegate
;
63 friend class RequestDelegate
;
65 typedef ScopedVector
<RequestDelegate
> Requests
;
67 Profile
* profile() const { return profile_
; }
69 // Invoked from the RequestDelegate when done downloading.
70 void RequestCompleted(RequestDelegate
* request
);
74 // In progress requests.
77 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcher
);
80 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_