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

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

Issue 20378: Reduce the amount of included header files. Vast change like in "Oh God! This... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/search_engines/template_url_fetcher.h" 5 #include "chrome/browser/search_engines/template_url_fetcher.h"
6 6
7 #include "chrome/browser/net/url_fetcher.h"
7 #include "chrome/browser/profile.h" 8 #include "chrome/browser/profile.h"
8 #include "chrome/browser/search_engines/template_url.h" 9 #include "chrome/browser/search_engines/template_url.h"
9 #include "chrome/browser/search_engines/template_url_model.h" 10 #include "chrome/browser/search_engines/template_url_model.h"
10 #include "chrome/browser/search_engines/template_url_parser.h" 11 #include "chrome/browser/search_engines/template_url_parser.h"
11 #include "chrome/browser/views/edit_keyword_controller.h" 12 #include "chrome/browser/views/edit_keyword_controller.h"
12 13
13 // RequestDelegate ------------------------------------------------------------ 14 // RequestDelegate ------------------------------------------------------------
15 class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate {
16 public:
17 RequestDelegate(TemplateURLFetcher* fetcher,
18 const std::wstring& keyword,
19 const GURL& osdd_url,
20 const GURL& favicon_url,
21 gfx::NativeView parent_window,
22 bool autodetected)
23 #pragma warning(disable:4355)
24 : url_fetcher_(osdd_url, URLFetcher::GET, this),
25 fetcher_(fetcher),
26 keyword_(keyword),
27 osdd_url_(osdd_url),
28 favicon_url_(favicon_url),
29 parent_window_(parent_window),
30 autodetected_(autodetected) {
31 url_fetcher_.set_request_context(fetcher->profile()->GetRequestContext());
32 url_fetcher_.Start();
33 }
34
35 // If data contains a valid OSDD, a TemplateURL is created and added to
36 // the TemplateURLModel.
37 virtual void OnURLFetchComplete(const URLFetcher* source,
38 const GURL& url,
39 const URLRequestStatus& status,
40 int response_code,
41 const ResponseCookies& cookies,
42 const std::string& data);
43
44 // URL of the OSDD.
45 const GURL& url() const { return osdd_url_; }
46
47 // Keyword to use.
48 const std::wstring keyword() const { return keyword_; }
49
50 private:
51 URLFetcher url_fetcher_;
52 TemplateURLFetcher* fetcher_;
53 const std::wstring keyword_;
54 const GURL osdd_url_;
55 const GURL favicon_url_;
56 bool autodetected_;
57
58 // Used to determine where to place a confirmation dialog. May be NULL,
59 // in which case the confirmation will be centered in the screen if needed.
60 gfx::NativeView parent_window_;
61
62 DISALLOW_COPY_AND_ASSIGN(RequestDelegate);
63 };
64
14 65
15 void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete( 66 void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete(
16 const URLFetcher* source, 67 const URLFetcher* source,
17 const GURL& url, 68 const GURL& url,
18 const URLRequestStatus& status, 69 const URLRequestStatus& status,
19 int response_code, 70 int response_code,
20 const ResponseCookies& cookies, 71 const ResponseCookies& cookies,
21 const std::string& data) { 72 const std::string& data) {
22 // Make sure we can still replace the keyword. 73 // Make sure we can still replace the keyword.
23 if (response_code != 200) { 74 if (response_code != 200) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 fetcher_->RequestCompleted(this); 133 fetcher_->RequestCompleted(this);
83 // WARNING: RequestCompleted deletes us. 134 // WARNING: RequestCompleted deletes us.
84 } 135 }
85 136
86 // TemplateURLFetcher --------------------------------------------------------- 137 // TemplateURLFetcher ---------------------------------------------------------
87 138
88 TemplateURLFetcher::TemplateURLFetcher(Profile* profile) : profile_(profile) { 139 TemplateURLFetcher::TemplateURLFetcher(Profile* profile) : profile_(profile) {
89 DCHECK(profile_); 140 DCHECK(profile_);
90 } 141 }
91 142
143 TemplateURLFetcher::~TemplateURLFetcher() {
144 }
145
92 void TemplateURLFetcher::ScheduleDownload(const std::wstring& keyword, 146 void TemplateURLFetcher::ScheduleDownload(const std::wstring& keyword,
93 const GURL& osdd_url, 147 const GURL& osdd_url,
94 const GURL& favicon_url, 148 const GURL& favicon_url,
95 const HWND parent_window, 149 const HWND parent_window,
96 bool autodetected) { 150 bool autodetected) {
97 DCHECK(!keyword.empty() && osdd_url.is_valid()); 151 DCHECK(!keyword.empty() && osdd_url.is_valid());
98 // Make sure we aren't already downloading this request. 152 // Make sure we aren't already downloading this request.
99 for (std::vector<RequestDelegate*>::iterator i = requests_->begin(); 153 for (std::vector<RequestDelegate*>::iterator i = requests_->begin();
100 i != requests_->end(); ++i) { 154 i != requests_->end(); ++i) {
101 if ((*i)->url() == osdd_url || (*i)->keyword() == keyword) 155 if ((*i)->url() == osdd_url || (*i)->keyword() == keyword)
102 return; 156 return;
103 } 157 }
104 158
105 requests_->push_back( 159 requests_->push_back(
106 new RequestDelegate(this, keyword, osdd_url, favicon_url, parent_window, 160 new RequestDelegate(this, keyword, osdd_url, favicon_url, parent_window,
107 autodetected)); 161 autodetected));
108 } 162 }
109 163
110 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { 164 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) {
111 DCHECK(find(requests_->begin(), requests_->end(), request) != 165 DCHECK(find(requests_->begin(), requests_->end(), request) !=
112 requests_->end()); 166 requests_->end());
113 requests_->erase(find(requests_->begin(), requests_->end(), request)); 167 requests_->erase(find(requests_->begin(), requests_->end(), request));
114 delete request; 168 delete request;
115 } 169 }
116 170
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698