| 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 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | 7 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
| 8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
| 9 #include "net/url_request/url_fetcher.h" | 9 #include "net/url_request/url_fetcher.h" |
| 10 #include "net/url_request/url_fetcher_delegate.h" | 10 #include "net/url_request/url_fetcher_delegate.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 MessageLoop loop; | 22 MessageLoop loop; |
| 23 scoped_ptr<net::URLFetcher> fetcher_( | 23 scoped_ptr<net::URLFetcher> fetcher_( |
| 24 net::URLFetcher::Create(url, net::URLFetcher::GET, this)); | 24 net::URLFetcher::Create(url, net::URLFetcher::GET, this)); |
| 25 fetcher_->SetRequestContext(getter); | 25 fetcher_->SetRequestContext(getter); |
| 26 response_ = response; | 26 response_ = response; |
| 27 fetcher_->Start(); | 27 fetcher_->Start(); |
| 28 loop.Run(); | 28 loop.Run(); |
| 29 return success_; | 29 return success_; |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual void OnURLFetchComplete(const net::URLFetcher* source) { | 32 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { |
| 33 success_ = (source->GetResponseCode() == 200); | 33 success_ = (source->GetResponseCode() == 200); |
| 34 if (success_) | 34 if (success_) |
| 35 success_ = source->GetResponseAsString(response_); | 35 success_ = source->GetResponseAsString(response_); |
| 36 MessageLoop::current()->Quit(); | 36 MessageLoop::current()->Quit(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 bool success_; | 40 bool success_; |
| 41 std::string* response_; | 41 std::string* response_; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 bool FetchUrl(const GURL& url, | 46 bool FetchUrl(const GURL& url, |
| 47 URLRequestContextGetter* getter, | 47 URLRequestContextGetter* getter, |
| 48 std::string* response) { | 48 std::string* response) { |
| 49 return SyncUrlFetcher().Fetch(url, getter, response); | 49 return SyncUrlFetcher().Fetch(url, getter, response); |
| 50 } | 50 } |
| OLD | NEW |