OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/callback.h" |
| 12 #include "net/url_request/url_fetcher_delegate.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 class Profile; |
| 16 |
| 17 namespace net { |
| 18 class URLFetcher; |
| 19 } |
| 20 |
| 21 namespace extensions { |
| 22 |
| 23 class DialDeviceDescription; |
| 24 |
| 25 // An instance of this class is used to make a single HTTP GET request with |
| 26 // |device_description_url| to fetch a uPnP device description. If successful, |
| 27 // |success_cb| is invoked with the result; otherwise, |error_cb| is invoked |
| 28 // with an error reason. This class is not thread safe and must be run on the |
| 29 // UI thread. |
| 30 class DeviceDescriptionFetcher : public net::URLFetcherDelegate { |
| 31 public: |
| 32 // Used to identify the net::URLFetcher instance. |
| 33 static constexpr int kURLFetcherID = 1; |
| 34 |
| 35 DeviceDescriptionFetcher( |
| 36 const GURL& device_description_url, |
| 37 Profile* profile, |
| 38 base::OnceCallback<void(const DialDeviceDescription&)> success_cb, |
| 39 base::OnceCallback<void(const std::string&)> error_cb); |
| 40 |
| 41 ~DeviceDescriptionFetcher() override; |
| 42 |
| 43 void Start(); |
| 44 |
| 45 private: |
| 46 // net::URLFetcherDelegate |
| 47 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 48 void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| 49 int64_t current, |
| 50 int64_t total, |
| 51 int64_t current_network_bytes) override; |
| 52 void OnURLFetchUploadProgress(const net::URLFetcher* source, |
| 53 int64_t current, |
| 54 int64_t total) override; |
| 55 |
| 56 // Runs |error_cb_| with |message|. |
| 57 void ReportError(const std::string& message); |
| 58 |
| 59 const GURL device_description_url_; |
| 60 Profile* const profile_; |
| 61 base::OnceCallback<void(const DialDeviceDescription&)> success_cb_; |
| 62 base::OnceCallback<void(const std::string&)> error_cb_; |
| 63 std::unique_ptr<net::URLFetcher> fetcher_; |
| 64 }; |
| 65 |
| 66 } // namespace extensions |
| 67 |
| 68 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
OLD | NEW |