OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/scoped_ptr.h" | |
6 #include "base/message_loop.h" | |
7 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | |
8 #include "googleurl/src/gurl.h" | |
9 #include "net/url_request/url_fetcher.h" | |
10 #include "net/url_request/url_fetcher_delegate.h" | |
11 | |
12 namespace { | |
13 | |
14 class SyncUrlFetcher : public net::URLFetcherDelegate { | |
15 public: | |
16 SyncUrlFetcher() {} | |
17 virtual ~SyncUrlFetcher() {} | |
18 | |
19 bool Fetch(const GURL& url, | |
20 URLRequestContextGetter* getter, | |
21 std::string* response) { | |
22 MessageLoop loop; | |
23 scoped_ptr<net::URLFetcher> fetcher_( | |
24 net::URLFetcher::Create(url, net::URLFetcher::GET, this)); | |
25 fetcher_->SetRequestContext(getter); | |
26 response_ = response; | |
27 fetcher_->Start(); | |
28 loop.Run(); | |
29 return success_; | |
30 } | |
31 | |
32 virtual void OnURLFetchComplete(const net::URLFetcher* source) { | |
33 success_ = (source->GetResponseCode() == 200); | |
34 if (success_) | |
35 success_ &= source->GetResponseAsString(response_); | |
craigdh
2012/12/04 01:41:27
Why a bit operator here? This is a logical operati
kkania
2013/02/28 21:51:58
Whoops, I don't know what I was thinking.
| |
36 MessageLoop::current()->Quit(); | |
37 } | |
38 | |
39 private: | |
40 bool success_; | |
41 std::string* response_; | |
42 }; | |
43 | |
44 } // namespace | |
45 | |
46 bool FetchUrl(const GURL& url, | |
47 URLRequestContextGetter* getter, | |
48 std::string* response) { | |
49 return SyncUrlFetcher().Fetch(url, getter, response); | |
50 } | |
OLD | NEW |