| 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 "webkit/glue/alt_error_page_resource_fetcher.h" | 5 #include "webkit/glue/alt_error_page_resource_fetcher.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 8 #include "webkit/glue/resource_fetcher.h" | 9 #include "webkit/glue/resource_fetcher.h" |
| 9 | 10 |
| 10 using WebKit::WebFrame; | 11 using WebKit::WebFrame; |
| 11 using WebKit::WebURLError; | 12 using WebKit::WebURLError; |
| 12 using WebKit::WebURLRequest; | 13 using WebKit::WebURLRequest; |
| 13 using WebKit::WebURLResponse; | 14 using WebKit::WebURLResponse; |
| 14 | 15 |
| 15 namespace webkit_glue { | 16 namespace webkit_glue { |
| 16 | 17 |
| 17 // Number of seconds to wait for the alternate error page server. If it takes | 18 // Number of seconds to wait for the alternate error page server. If it takes |
| 18 // too long, just use the local error page. | 19 // too long, just use the local error page. |
| 19 static const int kDownloadTimeoutSec = 3; | 20 static const int kDownloadTimeoutSec = 3; |
| 20 | 21 |
| 21 AltErrorPageResourceFetcher::AltErrorPageResourceFetcher( | 22 AltErrorPageResourceFetcher::AltErrorPageResourceFetcher( |
| 22 const GURL& url, | 23 const GURL& url, |
| 23 WebFrame* frame, | 24 WebFrame* frame, |
| 24 const WebURLError& original_error, | 25 const WebURLError& original_error, |
| 25 const Callback& callback) | 26 const Callback& callback) |
| 26 : frame_(frame), | 27 : frame_(frame), |
| 27 callback_(callback), | 28 callback_(callback), |
| 28 original_error_(original_error) { | 29 original_error_(original_error) { |
| 29 fetcher_.reset(new ResourceFetcherWithTimeout( | 30 fetcher_.reset(new ResourceFetcherWithTimeout( |
| 30 url, frame, WebURLRequest::TargetIsMainFrame, kDownloadTimeoutSec, | 31 url, frame, WebURLRequest::TargetIsMainFrame, kDownloadTimeoutSec, |
| 31 NewCallback(this, &AltErrorPageResourceFetcher::OnURLFetchComplete))); | 32 base::Bind(&AltErrorPageResourceFetcher::OnURLFetchComplete, |
| 33 base::Unretained(this)))); |
| 32 } | 34 } |
| 33 | 35 |
| 34 AltErrorPageResourceFetcher::~AltErrorPageResourceFetcher() { | 36 AltErrorPageResourceFetcher::~AltErrorPageResourceFetcher() { |
| 35 } | 37 } |
| 36 | 38 |
| 37 void AltErrorPageResourceFetcher::Cancel() { | 39 void AltErrorPageResourceFetcher::Cancel() { |
| 38 fetcher_->Cancel(); | 40 fetcher_->Cancel(); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void AltErrorPageResourceFetcher::OnURLFetchComplete( | 43 void AltErrorPageResourceFetcher::OnURLFetchComplete( |
| 42 const WebURLResponse& response, | 44 const WebURLResponse& response, |
| 43 const std::string& data) { | 45 const std::string& data) { |
| 44 // A null response indicates a network error. | 46 // A null response indicates a network error. |
| 45 if (!response.isNull() && response.httpStatusCode() == 200) { | 47 if (!response.isNull() && response.httpStatusCode() == 200) { |
| 46 callback_.Run(frame_, original_error_, data); | 48 callback_.Run(frame_, original_error_, data); |
| 47 } else { | 49 } else { |
| 48 callback_.Run(frame_, original_error_, std::string()); | 50 callback_.Run(frame_, original_error_, std::string()); |
| 49 } | 51 } |
| 50 } | 52 } |
| 51 | 53 |
| 52 } // namespace webkit_glue | 54 } // namespace webkit_glue |
| OLD | NEW |