Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(903)

Side by Side Diff: chrome/browser/extensions/api/dial/device_description_fetcher.h

Issue 2583853004: [chrome.dial] Adds chrome.dial.fetchDeviceDecription API. (Closed)
Patch Set: Clean up some unneeded code in unittest. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017 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 namespace api {
23 namespace dial {
24
25 struct DialDeviceDescriptionData;
26
27 // Used to make a single HTTP GET request with |device_description_url| to fetch
28 // a uPnP device description from a DIAL device. If successful, |success_cb| is
29 // invoked with the result; otherwise, |error_cb| is invoked with an error
30 // reason. This class is not thread safe and must be used on the UI thread.
31 class DeviceDescriptionFetcher : public net::URLFetcherDelegate {
32 public:
33 // Used to identify the net::URLFetcher instance for tests.
34 static constexpr int kURLFetcherIDForTest = 1;
35
36 DeviceDescriptionFetcher(
37 const GURL& device_description_url,
38 Profile* profile,
39 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb,
40 base::OnceCallback<void(const std::string&)> error_cb);
41
42 ~DeviceDescriptionFetcher() override;
43
44 void Start();
45
46 private:
47 // net::URLFetcherDelegate implementation.
48 void OnURLFetchComplete(const net::URLFetcher* source) override;
49 void OnURLFetchDownloadProgress(const net::URLFetcher* source,
50 int64_t current,
51 int64_t total,
52 int64_t current_network_bytes) override;
53 void OnURLFetchUploadProgress(const net::URLFetcher* source,
54 int64_t current,
55 int64_t total) override;
56
57 // Runs |error_cb_| with |message| and clears it.
58 void ReportError(const std::string& message);
59
60 const GURL device_description_url_;
61 Profile* const profile_;
62 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb_;
63 base::OnceCallback<void(const std::string&)> error_cb_;
64 std::unique_ptr<net::URLFetcher> fetcher_;
65 };
66
67 } // namespace dial
68 } // namespace api
69 } // namespace extensions
70
71 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698