OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/google/google_url_tracker.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/google/google_util.h" | 15 #include "chrome/browser/google/google_util.h" |
16 #include "chrome/browser/infobars/infobar_tab_helper.h" | 16 #include "chrome/browser/infobars/infobar_tab_helper.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/search_engines/template_url.h" | 18 #include "chrome/browser/search_engines/template_url.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "content/browser/tab_contents/navigation_controller.h" | 23 #include "content/browser/tab_contents/navigation_controller.h" |
24 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
| 25 #include "content/common/net/url_fetcher.h" |
25 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
27 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
28 #include "net/base/net_util.h" | 29 #include "net/base/net_util.h" |
29 #include "net/url_request/url_request_context_getter.h" | 30 #include "net/url_request/url_request_context_getter.h" |
30 #include "net/url_request/url_request_status.h" | 31 #include "net/url_request/url_request_status.h" |
31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 net::LOAD_DO_NOT_SAVE_COOKIES); | 215 net::LOAD_DO_NOT_SAVE_COOKIES); |
215 fetcher_->set_request_context(g_browser_process->system_request_context()); | 216 fetcher_->set_request_context(g_browser_process->system_request_context()); |
216 | 217 |
217 // Configure to max_retries at most kMaxRetries times for 5xx errors. | 218 // Configure to max_retries at most kMaxRetries times for 5xx errors. |
218 static const int kMaxRetries = 5; | 219 static const int kMaxRetries = 5; |
219 fetcher_->set_max_retries(kMaxRetries); | 220 fetcher_->set_max_retries(kMaxRetries); |
220 | 221 |
221 fetcher_->Start(); | 222 fetcher_->Start(); |
222 } | 223 } |
223 | 224 |
224 void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source, | 225 void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source) { |
225 const GURL& url, | |
226 const net::URLRequestStatus& status, | |
227 int response_code, | |
228 const net::ResponseCookies& cookies, | |
229 const std::string& data) { | |
230 // Delete the fetcher on this function's exit. | 226 // Delete the fetcher on this function's exit. |
231 scoped_ptr<URLFetcher> clean_up_fetcher(fetcher_.release()); | 227 scoped_ptr<URLFetcher> clean_up_fetcher(fetcher_.release()); |
232 | 228 |
233 // Don't update the URL if the request didn't succeed. | 229 // Don't update the URL if the request didn't succeed. |
234 if (!status.is_success() || (response_code != 200)) { | 230 if (!source->status().is_success() || (source->response_code() != 200)) { |
235 already_fetched_ = false; | 231 already_fetched_ = false; |
236 return; | 232 return; |
237 } | 233 } |
238 | 234 |
239 // See if the response data was one we want to use, and if so, convert to the | 235 // See if the response data was one we want to use, and if so, convert to the |
240 // appropriate Google base URL. | 236 // appropriate Google base URL. |
241 std::string url_str; | 237 std::string url_str; |
242 TrimWhitespace(data, TRIM_ALL, &url_str); | 238 source->GetResponseAsString(&url_str); |
| 239 TrimWhitespace(url_str, TRIM_ALL, &url_str); |
243 | 240 |
244 if (!StartsWithASCII(url_str, ".google.", false)) | 241 if (!StartsWithASCII(url_str, ".google.", false)) |
245 return; | 242 return; |
246 | 243 |
247 fetched_google_url_ = GURL("http://www" + url_str); | 244 fetched_google_url_ = GURL("http://www" + url_str); |
248 GURL last_prompted_url( | 245 GURL last_prompted_url( |
249 g_browser_process->local_state()->GetString( | 246 g_browser_process->local_state()->GetString( |
250 prefs::kLastPromptedGoogleURL)); | 247 prefs::kLastPromptedGoogleURL)); |
251 need_to_prompt_ = false; | 248 need_to_prompt_ = false; |
252 | 249 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 380 |
384 // |tab_contents| can be NULL during tests. | 381 // |tab_contents| can be NULL during tests. |
385 InfoBarTabHelper* infobar_helper = NULL; | 382 InfoBarTabHelper* infobar_helper = NULL; |
386 if (tab_contents) { | 383 if (tab_contents) { |
387 TabContentsWrapper* wrapper = | 384 TabContentsWrapper* wrapper = |
388 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); | 385 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); |
389 infobar_helper = wrapper->infobar_tab_helper(); | 386 infobar_helper = wrapper->infobar_tab_helper(); |
390 } | 387 } |
391 infobar_ = (*infobar_creator_)(infobar_helper, this, fetched_google_url_); | 388 infobar_ = (*infobar_creator_)(infobar_helper, this, fetched_google_url_); |
392 } | 389 } |
OLD | NEW |