Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/search_engines/template_url_fetcher.h

Issue 371333003: No content dependencies in TemplateURLFetcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/search_engines/template_url_fetcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_
7 7
8 #include "base/callback_forward.h" 8 #include "base/callback_forward.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "components/keyed_service/core/keyed_service.h" 13 #include "components/keyed_service/core/keyed_service.h"
14 14
15 class GURL; 15 class GURL;
16 class TemplateURL; 16 class TemplateURL;
17 class TemplateURLService; 17 class TemplateURLService;
18 18
19 namespace content {
20 class WebContents;
21 }
22
23 namespace net { 19 namespace net {
20 class URLFetcher;
24 class URLRequestContextGetter; 21 class URLRequestContextGetter;
25 } 22 }
26 23
27 // TemplateURLFetcher is responsible for downloading OpenSearch description 24 // TemplateURLFetcher is responsible for downloading OpenSearch description
28 // documents, creating a TemplateURL from the OSDD, and adding the TemplateURL 25 // documents, creating a TemplateURL from the OSDD, and adding the TemplateURL
29 // to the TemplateURLService. Downloading is done in the background. 26 // to the TemplateURLService. Downloading is done in the background.
30 // 27 //
31 class TemplateURLFetcher : public KeyedService { 28 class TemplateURLFetcher : public KeyedService {
32 public: 29 public:
33 typedef base::Callback<void( 30 typedef base::Callback<void(
31 net::URLFetcher* url_fetcher)> URLFetcherCustomizeCallback;
32 typedef base::Callback<void(
34 scoped_ptr<TemplateURL> template_url)> ConfirmAddSearchProviderCallback; 33 scoped_ptr<TemplateURL> template_url)> ConfirmAddSearchProviderCallback;
35 34
36 enum ProviderType { 35 enum ProviderType {
37 AUTODETECTED_PROVIDER, 36 AUTODETECTED_PROVIDER,
38 EXPLICIT_PROVIDER // Supplied by Javascript. 37 EXPLICIT_PROVIDER // Supplied by Javascript.
39 }; 38 };
40 39
41 // Creates a TemplateURLFetcher. 40 // Creates a TemplateURLFetcher.
42 TemplateURLFetcher(TemplateURLService* template_url_service, 41 TemplateURLFetcher(TemplateURLService* template_url_service,
43 net::URLRequestContextGetter* request_context); 42 net::URLRequestContextGetter* request_context);
44 virtual ~TemplateURLFetcher(); 43 virtual ~TemplateURLFetcher();
45 44
46 // If TemplateURLFetcher is not already downloading the OSDD for osdd_url, 45 // If TemplateURLFetcher is not already downloading the OSDD for osdd_url,
47 // it is downloaded. If successful and the result can be parsed, a TemplateURL 46 // it is downloaded. If successful and the result can be parsed, a TemplateURL
48 // is added to the TemplateURLService. Takes ownership of |callbacks|. 47 // is added to the TemplateURLService.
49 // 48 //
50 // If |provider_type| is AUTODETECTED_PROVIDER, |keyword| must be non-empty, 49 // If |provider_type| is AUTODETECTED_PROVIDER, |keyword| must be non-empty,
51 // and if there's already a non-replaceable TemplateURL in the model for 50 // and if there's already a non-replaceable TemplateURL in the model for
52 // |keyword|, or we're already downloading an OSDD for this keyword, no 51 // |keyword|, or we're already downloading an OSDD for this keyword, no
53 // download is started. If |provider_type| is EXPLICIT_PROVIDER, |keyword| is 52 // download is started. If |provider_type| is EXPLICIT_PROVIDER, |keyword| is
54 // ignored. 53 // ignored.
55 // 54 //
56 // |web_contents| specifies which WebContents displays the page the OSDD is 55 // If |url_fetcher_customize_callback| is not null, it's run after a
57 // downloaded for. |web_contents| must not be NULL, except during tests. 56 // URLFetcher is created. This callback can be used to set additional
58 void ScheduleDownload(const base::string16& keyword, 57 // parameters on the URLFetcher.
59 const GURL& osdd_url, 58 void ScheduleDownload(
60 const GURL& favicon_url, 59 const base::string16& keyword,
61 content::WebContents* web_contents, 60 const GURL& osdd_url,
62 const ConfirmAddSearchProviderCallback& callback, 61 const GURL& favicon_url,
63 ProviderType provider_type); 62 const URLFetcherCustomizeCallback& url_fetcher_customize_callback,
63 const ConfirmAddSearchProviderCallback& confirm_add_callback,
64 ProviderType provider_type);
64 65
65 // The current number of outstanding requests. 66 // The current number of outstanding requests.
66 int requests_count() const { return requests_.size(); } 67 int requests_count() const { return requests_.size(); }
67 68
68 private: 69 private:
69 // A RequestDelegate is created to download each OSDD. When done downloading 70 // A RequestDelegate is created to download each OSDD. When done downloading
70 // RequestCompleted is invoked back on the TemplateURLFetcher. 71 // RequestCompleted is invoked back on the TemplateURLFetcher.
71 class RequestDelegate; 72 class RequestDelegate;
72 friend class RequestDelegate; 73 friend class RequestDelegate;
73 74
74 typedef ScopedVector<RequestDelegate> Requests; 75 typedef ScopedVector<RequestDelegate> Requests;
75 76
76 // Invoked from the RequestDelegate when done downloading. 77 // Invoked from the RequestDelegate when done downloading.
77 void RequestCompleted(RequestDelegate* request); 78 void RequestCompleted(RequestDelegate* request);
78 79
79 TemplateURLService* template_url_service_; 80 TemplateURLService* template_url_service_;
80 scoped_refptr<net::URLRequestContextGetter> request_context_; 81 scoped_refptr<net::URLRequestContextGetter> request_context_;
81 82
82 // In progress requests. 83 // In progress requests.
83 Requests requests_; 84 Requests requests_;
84 85
85 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcher); 86 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcher);
86 }; 87 };
87 88
88 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ 89 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search_engines/template_url_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698