| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_TEMPLATE_URL_FETCHER_H__ | |
| 6 #define CHROME_BROWSER_TEMPLATE_URL_FETCHER_H__ | |
| 7 | |
| 8 #include "chrome/browser/profile.h" | |
| 9 #include "chrome/browser/url_fetcher.h" | |
| 10 #include "chrome/common/scoped_vector.h" | |
| 11 | |
| 12 class GURL; | |
| 13 class Profile; | |
| 14 class TemplateURL; | |
| 15 class WebContents; | |
| 16 | |
| 17 // TemplateURLFetcher is responsible for downloading OpenSearch description | |
| 18 // documents, creating a TemplateURL from the OSDD, and adding the TemplateURL | |
| 19 // to the TemplateURLModel. Downloading is done in the background. | |
| 20 // | |
| 21 class TemplateURLFetcher { | |
| 22 public: | |
| 23 // Creates a TemplateURLFetcher with the specified Profile. | |
| 24 explicit TemplateURLFetcher(Profile* profile); | |
| 25 | |
| 26 // If TemplateURLFetcher is not already downloading the OSDD for osdd_url, | |
| 27 // it is downloaded. If successful and the result can be parsed, a TemplateURL | |
| 28 // is added to the TemplateURLModel. | |
| 29 void ScheduleDownload(const std::wstring& keyword, | |
| 30 const GURL& osdd_url, | |
| 31 const GURL& favicon_url, | |
| 32 const HWND parent_window, | |
| 33 bool autodetected); | |
| 34 | |
| 35 private: | |
| 36 friend class RequestDelegate; | |
| 37 | |
| 38 // A RequestDelegate is created to download each OSDD. When done downloading | |
| 39 // RequestCompleted is invoked back on the TemplateURLFetcher. | |
| 40 class RequestDelegate : public URLFetcher::Delegate { | |
| 41 public: | |
| 42 RequestDelegate(TemplateURLFetcher* fetcher, | |
| 43 const std::wstring& keyword, | |
| 44 const GURL& osdd_url, | |
| 45 const GURL& favicon_url, | |
| 46 const HWND parent_window, | |
| 47 bool autodetected) | |
| 48 #pragma warning(disable:4355) | |
| 49 : url_fetcher_(osdd_url, URLFetcher::GET, this), | |
| 50 fetcher_(fetcher), | |
| 51 keyword_(keyword), | |
| 52 osdd_url_(osdd_url), | |
| 53 favicon_url_(favicon_url), | |
| 54 parent_window_(parent_window), | |
| 55 autodetected_(autodetected) { | |
| 56 url_fetcher_.set_request_context(fetcher->profile()->GetRequestContext()); | |
| 57 url_fetcher_.Start(); | |
| 58 } | |
| 59 | |
| 60 // If data contains a valid OSDD, a TemplateURL is created and added to | |
| 61 // the TemplateURLModel. | |
| 62 virtual void OnURLFetchComplete(const URLFetcher* source, | |
| 63 const GURL& url, | |
| 64 const URLRequestStatus& status, | |
| 65 int response_code, | |
| 66 const ResponseCookies& cookies, | |
| 67 const std::string& data); | |
| 68 | |
| 69 // URL of the OSDD. | |
| 70 const GURL& url() const { return osdd_url_; } | |
| 71 | |
| 72 // Keyword to use. | |
| 73 const std::wstring keyword() const { return keyword_; } | |
| 74 | |
| 75 private: | |
| 76 URLFetcher url_fetcher_; | |
| 77 TemplateURLFetcher* fetcher_; | |
| 78 const std::wstring keyword_; | |
| 79 const GURL osdd_url_; | |
| 80 const GURL favicon_url_; | |
| 81 bool autodetected_; | |
| 82 | |
| 83 // Used to determine where to place a confirmation dialog. May be NULL, | |
| 84 // in which case the confirmation will be centered in the screen if needed. | |
| 85 const HWND parent_window_; | |
| 86 | |
| 87 DISALLOW_EVIL_CONSTRUCTORS(RequestDelegate); | |
| 88 }; | |
| 89 | |
| 90 Profile* profile() const { return profile_; } | |
| 91 | |
| 92 // Invoked from the RequestDelegate when done downloading. | |
| 93 void RequestCompleted(RequestDelegate* request); | |
| 94 | |
| 95 Profile* profile_; | |
| 96 | |
| 97 // In progress requests. | |
| 98 ScopedVector<RequestDelegate> requests_; | |
| 99 | |
| 100 DISALLOW_EVIL_CONSTRUCTORS(TemplateURLFetcher); | |
| 101 }; | |
| 102 | |
| 103 #endif // CHROME_BROWSER_OSDD_FETCHER_H__ | |
| 104 | |
| OLD | NEW |