Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / search_engines / template_url_fetcher.h
blob230837f1e099d6b504f5c06a4bf69d22444f41e8
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/browser_context_keyed_service/browser_context_keyed_service.h"
11 #include "ui/gfx/native_widget_types.h"
13 class GURL;
14 class Profile;
15 class TemplateURL;
16 class TemplateURLFetcherCallbacks;
18 namespace content {
19 class WebContents;
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 BrowserContextKeyedService {
27 public:
28 enum ProviderType {
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
45 // ignored.
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,
50 const GURL& osdd_url,
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(); }
59 private:
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);
72 Profile* profile_;
74 // In progress requests.
75 Requests requests_;
77 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcher);
80 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_