Chromium Code Reviews| Index: chrome/browser/extensions/api/dial/device_description_fetcher.h |
| diff --git a/chrome/browser/extensions/api/dial/device_description_fetcher.h b/chrome/browser/extensions/api/dial/device_description_fetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c5f0eff9caa5b257d75246fed699381ce79ff198 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/dial/device_description_fetcher.h |
| @@ -0,0 +1,69 @@ |
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
| + |
| +#include <memory> |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| +#include "url/gurl.h" |
| + |
| +class Profile; |
| + |
| +namespace net { |
| +class URLFetcher; |
| +} |
| + |
| +namespace extensions { |
| + |
| +class DialDeviceDescription; |
| + |
| +// An instance of this class is used to make a single HTTP GET request with |
| +// |device_description_url| to fetch a uPnP device description. If successful, |
| +// |success_cb| is invoked with the result; otherwise, |error_cb| is invoked |
| +// with an error reason. This class is not thread safe. |
|
imcheng
2016/12/28 05:36:45
Also document on which thread the class is run on?
mark a. foltz
2017/01/04 00:20:16
Done. Also use DCHECK_CURRENTLY_ON to enforce tha
|
| +class DeviceDescriptionFetcher : public net::URLFetcherDelegate { |
| + public: |
| + // Used to identify the net::URLFetcher instance. |
| + static constexpr int kURLFetcherID = 1; |
| + |
| + DeviceDescriptionFetcher( |
| + const GURL& device_description_url, |
| + Profile* profile, |
| + base::OnceCallback<void(const DialDeviceDescription&)> success_cb, |
| + base::OnceCallback<void(const std::string&)> error_cb); |
| + |
| + ~DeviceDescriptionFetcher() override; |
| + |
| + void Start(); |
| + |
| + private: |
| + // net::URLFetcherDelegate |
| + void OnURLFetchComplete(const net::URLFetcher* source) override; |
| + void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| + int64_t current, |
| + int64_t total, |
| + int64_t current_network_bytes) override; |
| + void OnURLFetchUploadProgress(const net::URLFetcher* source, |
| + int64_t current, |
| + int64_t total) override; |
| + |
| + // Runs |error_cb_| with |message|. |
| + void ReportError(const std::string& message); |
| + |
| + const GURL device_description_url_; |
| + Profile* profile_; |
|
imcheng
2016/12/28 05:36:45
Profile* const
mark a. foltz
2017/01/04 00:20:16
Done.
|
| + base::OnceCallback<void(const DialDeviceDescription&)> success_cb_; |
| + base::OnceCallback<void(const std::string&)> error_cb_; |
| + std::unique_ptr<net::URLFetcher> fetcher_; |
| + |
| + // TODO: Add a thread checker |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |