1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DEVICE_DESCRIPTION_FETCHER_H_
#define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DEVICE_DESCRIPTION_FETCHER_H_
#include <memory>
#include <optional>
#include <string>
#include "base/functional/callback.h"
#include "base/sequence_checker.h"
#include "chrome/browser/media/router/discovery/dial/dial_device_data.h"
#include "chrome/browser/media/router/discovery/dial/dial_url_fetcher.h"
#include "url/gurl.h"
namespace media_router {
struct DialDeviceDescriptionData;
// Used to make a single HTTP GET request with |device_description_url| to fetch
// a uPnP device description from a DIAL device. If successful, |success_cb| is
// invoked with the result; otherwise, |error_cb| is invoked with an error
// reason.
// This class is not sequence safe.
class DeviceDescriptionFetcher {
public:
DeviceDescriptionFetcher(
const DialDeviceData& device_data,
base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb,
base::OnceCallback<void(const std::string&)> error_cb);
DeviceDescriptionFetcher(const DeviceDescriptionFetcher&) = delete;
DeviceDescriptionFetcher& operator=(const DeviceDescriptionFetcher&) = delete;
virtual ~DeviceDescriptionFetcher();
const GURL& device_description_url() const {
return device_data_.device_description_url();
}
// Marked virtual for tests.
virtual void Start();
private:
friend class TestDeviceDescriptionFetcher;
// Processes the response from the GET request and invoke the success or
// error callback.
void ProcessResponse(const std::string& response);
// Runs |error_cb_| with |message| and clears it.
void ReportError(const std::string& message,
std::optional<int> response_code = std::nullopt);
const DialDeviceData device_data_;
base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb_;
base::OnceCallback<void(const std::string&)> error_cb_;
std::unique_ptr<DialURLFetcher> fetcher_;
SEQUENCE_CHECKER(sequence_checker_);
};
} // namespace media_router
#endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DEVICE_DESCRIPTION_FETCHER_H_
|