2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-02-20 22:38:28 +00:00
|
|
|
#ifndef MEDIA_BASE_HTTP_FETCHER_H_
|
|
|
|
#define MEDIA_BASE_HTTP_FETCHER_H_
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-02-20 22:38:28 +00:00
|
|
|
#include "base/compiler_specific.h"
|
2013-12-16 17:13:29 +00:00
|
|
|
#include "media/base/status.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Defines a generic http fetcher interface.
|
2014-02-20 22:38:28 +00:00
|
|
|
class HttpFetcher {
|
2013-12-16 17:13:29 +00:00
|
|
|
public:
|
2014-02-20 22:38:28 +00:00
|
|
|
HttpFetcher();
|
|
|
|
virtual ~HttpFetcher();
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Fetch content using HTTP GET.
|
|
|
|
/// @param url specifies the content URL.
|
|
|
|
/// @param[out] response will contain the body of the http response on
|
|
|
|
/// success. It should not be NULL.
|
|
|
|
/// @return OK on success.
|
2014-02-20 22:38:28 +00:00
|
|
|
virtual Status Get(const std::string& url, std::string* response) = 0;
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Fetch content using HTTP POST.
|
|
|
|
/// @param url specifies the content URL.
|
|
|
|
/// @param[out] response will contain the body of the http response on
|
|
|
|
/// success. It should not be NULL.
|
|
|
|
/// @return OK on success.
|
2014-02-20 22:38:28 +00:00
|
|
|
virtual Status Post(const std::string& url,
|
|
|
|
const std::string& data,
|
|
|
|
std::string* response) = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(HttpFetcher);
|
|
|
|
};
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// A simple HttpFetcher implementation using happyhttp.
|
2014-02-20 22:38:28 +00:00
|
|
|
class SimpleHttpFetcher : public HttpFetcher {
|
|
|
|
public:
|
|
|
|
SimpleHttpFetcher();
|
|
|
|
virtual ~SimpleHttpFetcher();
|
|
|
|
|
|
|
|
// HttpFetcher implementation overrides.
|
|
|
|
virtual Status Get(const std::string& url, std::string* response) OVERRIDE;
|
|
|
|
virtual Status Post(const std::string& url,
|
|
|
|
const std::string& data,
|
|
|
|
std::string* response) OVERRIDE;
|
2013-12-16 17:13:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Internal implementation of HTTP functions, e.g. Get and Post.
|
|
|
|
Status FetchInternal(const std::string& method, const std::string& url,
|
|
|
|
const std::string& data, std::string* response);
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
// Track whether WSAStartup executes successfully.
|
|
|
|
bool wsa_startup_succeeded_;
|
|
|
|
#endif
|
|
|
|
|
2014-02-20 22:38:28 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(SimpleHttpFetcher);
|
2013-12-16 17:13:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
|
2014-02-20 22:38:28 +00:00
|
|
|
#endif // MEDIA_BASE_HTTP_FETCHER_H_
|
2013-12-16 17:13:29 +00:00
|
|
|
|