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 "chrome/test/chromedriver/net/net_util.h" | 5 #include "chrome/test/chromedriver/net/net_util.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | 15 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
16 #include "net/url_request/url_fetcher.h" | 16 #include "net/url_request/url_fetcher.h" |
17 #include "net/url_request/url_fetcher_delegate.h" | 17 #include "net/url_request/url_fetcher_delegate.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 class SyncUrlFetcher : public net::URLFetcherDelegate { | 22 class SyncUrlFetcher : public net::URLFetcherDelegate { |
23 public: | 23 public: |
24 SyncUrlFetcher(const GURL& url, | 24 SyncUrlFetcher(const GURL& url, |
25 URLRequestContextGetter* getter, | 25 URLRequestContextGetter* getter, |
26 std::string* response) | 26 std::string* response) |
27 : url_(url), getter_(getter), response_(response), event_(false, false) {} | 27 : url_(url), |
| 28 getter_(getter), |
| 29 response_(response), |
| 30 event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 31 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
28 | 32 |
29 ~SyncUrlFetcher() override {} | 33 ~SyncUrlFetcher() override {} |
30 | 34 |
31 bool Fetch() { | 35 bool Fetch() { |
32 getter_->GetNetworkTaskRunner()->PostTask( | 36 getter_->GetNetworkTaskRunner()->PostTask( |
33 FROM_HERE, | 37 FROM_HERE, |
34 base::Bind(&SyncUrlFetcher::FetchOnIOThread, base::Unretained(this))); | 38 base::Bind(&SyncUrlFetcher::FetchOnIOThread, base::Unretained(this))); |
35 event_.Wait(); | 39 event_.Wait(); |
36 return success_; | 40 return success_; |
37 } | 41 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 88 |
85 int NetAddress::port() const { | 89 int NetAddress::port() const { |
86 return port_; | 90 return port_; |
87 } | 91 } |
88 | 92 |
89 bool FetchUrl(const std::string& url, | 93 bool FetchUrl(const std::string& url, |
90 URLRequestContextGetter* getter, | 94 URLRequestContextGetter* getter, |
91 std::string* response) { | 95 std::string* response) { |
92 return SyncUrlFetcher(GURL(url), getter, response).Fetch(); | 96 return SyncUrlFetcher(GURL(url), getter, response).Fetch(); |
93 } | 97 } |
OLD | NEW |