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

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: Rebase and fix typo. 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 // |profile| is unowned; the caller must ensure that this object does not
37 // outlive it.
38 DeviceDescriptionFetcher(
39 const GURL& device_description_url,
40 Profile* profile,
41 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb,
42 base::OnceCallback<void(const std::string&)> error_cb);
43
44 ~DeviceDescriptionFetcher() override;
45
46 void Start();
47
48 private:
49 // net::URLFetcherDelegate implementation.
50 void OnURLFetchComplete(const net::URLFetcher* source) override;
51 void OnURLFetchDownloadProgress(const net::URLFetcher* source,
52 int64_t current,
53 int64_t total,
54 int64_t current_network_bytes) override;
55 void OnURLFetchUploadProgress(const net::URLFetcher* source,
56 int64_t current,
57 int64_t total) override;
58
59 // Runs |error_cb_| with |message| and clears it.
60 void ReportError(const std::string& message);
61
62 const GURL device_description_url_;
63 Profile* const profile_;
64 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb_;
65 base::OnceCallback<void(const std::string&)> error_cb_;
66 std::unique_ptr<net::URLFetcher> fetcher_;
67 };
68
69 } // namespace dial
70 } // namespace api
71 } // namespace extensions
72
73 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/BUILD.gn ('k') | chrome/browser/extensions/api/dial/device_description_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698