| OLD | NEW |
| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| 11 #include "ui/gfx/native_widget_types.h" | 11 #include "ui/gfx/native_widget_types.h" |
| 12 | 12 |
| 13 class GURL; | 13 class GURL; |
| 14 class Profile; | 14 class Profile; |
| 15 class TemplateURL; | 15 class TemplateURL; |
| 16 class TemplateURLFetcherCallbacks; | 16 class TemplateURLFetcherCallbacks; |
| 17 | 17 |
| 18 namespace content { |
| 19 class WebContents; |
| 20 } |
| 21 |
| 18 // TemplateURLFetcher is responsible for downloading OpenSearch description | 22 // TemplateURLFetcher is responsible for downloading OpenSearch description |
| 19 // documents, creating a TemplateURL from the OSDD, and adding the TemplateURL | 23 // documents, creating a TemplateURL from the OSDD, and adding the TemplateURL |
| 20 // to the TemplateURLService. Downloading is done in the background. | 24 // to the TemplateURLService. Downloading is done in the background. |
| 21 // | 25 // |
| 22 class TemplateURLFetcher { | 26 class TemplateURLFetcher { |
| 23 public: | 27 public: |
| 24 enum ProviderType { | 28 enum ProviderType { |
| 25 AUTODETECTED_PROVIDER, | 29 AUTODETECTED_PROVIDER, |
| 26 EXPLICIT_PROVIDER // Supplied by Javascript. | 30 EXPLICIT_PROVIDER // Supplied by Javascript. |
| 27 }; | 31 }; |
| 28 | 32 |
| 29 // Creates a TemplateURLFetcher with the specified Profile. | 33 // Creates a TemplateURLFetcher with the specified Profile. |
| 30 explicit TemplateURLFetcher(Profile* profile); | 34 explicit TemplateURLFetcher(Profile* profile); |
| 31 ~TemplateURLFetcher(); | 35 ~TemplateURLFetcher(); |
| 32 | 36 |
| 33 // If TemplateURLFetcher is not already downloading the OSDD for osdd_url, | 37 // If TemplateURLFetcher is not already downloading the OSDD for osdd_url, |
| 34 // it is downloaded. If successful and the result can be parsed, a TemplateURL | 38 // it is downloaded. If successful and the result can be parsed, a TemplateURL |
| 35 // is added to the TemplateURLService. Takes ownership of |callbacks|. | 39 // is added to the TemplateURLService. Takes ownership of |callbacks|. |
| 36 void ScheduleDownload(const string16& keyword, | 40 void ScheduleDownload(const string16& keyword, |
| 37 const GURL& osdd_url, | 41 const GURL& osdd_url, |
| 38 const GURL& favicon_url, | 42 const GURL& favicon_url, |
| 43 content::WebContents* web_contents, |
| 39 TemplateURLFetcherCallbacks* callbacks, | 44 TemplateURLFetcherCallbacks* callbacks, |
| 40 ProviderType provider_type); | 45 ProviderType provider_type); |
| 41 | 46 |
| 42 // The current number of outstanding requests. | 47 // The current number of outstanding requests. |
| 43 int requests_count() const { return requests_->size(); } | 48 int requests_count() const { return requests_->size(); } |
| 44 | 49 |
| 45 private: | 50 private: |
| 46 friend class RequestDelegate; | 51 friend class RequestDelegate; |
| 47 | 52 |
| 48 // A RequestDelegate is created to download each OSDD. When done downloading | 53 // A RequestDelegate is created to download each OSDD. When done downloading |
| 49 // RequestCompleted is invoked back on the TemplateURLFetcher. | 54 // RequestCompleted is invoked back on the TemplateURLFetcher. |
| 50 class RequestDelegate; | 55 class RequestDelegate; |
| 51 | 56 |
| 52 Profile* profile() const { return profile_; } | 57 Profile* profile() const { return profile_; } |
| 53 | 58 |
| 54 // Invoked from the RequestDelegate when done downloading. | 59 // Invoked from the RequestDelegate when done downloading. |
| 55 void RequestCompleted(RequestDelegate* request); | 60 void RequestCompleted(RequestDelegate* request); |
| 56 | 61 |
| 57 Profile* profile_; | 62 Profile* profile_; |
| 58 | 63 |
| 59 // In progress requests. | 64 // In progress requests. |
| 60 ScopedVector<RequestDelegate> requests_; | 65 ScopedVector<RequestDelegate> requests_; |
| 61 | 66 |
| 62 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcher); | 67 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcher); |
| 63 }; | 68 }; |
| 64 | 69 |
| 65 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ | 70 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ |
| OLD | NEW |