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. | |
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
| |
29 class DeviceDescriptionFetcher : public net::URLFetcherDelegate { | |
30 public: | |
31 // Used to identify the net::URLFetcher instance. | |
32 static constexpr int kURLFetcherID = 1; | |
33 | |
34 DeviceDescriptionFetcher( | |
35 const GURL& device_description_url, | |
36 Profile* profile, | |
37 base::OnceCallback<void(const DialDeviceDescription&)> success_cb, | |
38 base::OnceCallback<void(const std::string&)> error_cb); | |
39 | |
40 ~DeviceDescriptionFetcher() override; | |
41 | |
42 void Start(); | |
43 | |
44 private: | |
45 // net::URLFetcherDelegate | |
46 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
47 void OnURLFetchDownloadProgress(const net::URLFetcher* source, | |
48 int64_t current, | |
49 int64_t total, | |
50 int64_t current_network_bytes) override; | |
51 void OnURLFetchUploadProgress(const net::URLFetcher* source, | |
52 int64_t current, | |
53 int64_t total) override; | |
54 | |
55 // Runs |error_cb_| with |message|. | |
56 void ReportError(const std::string& message); | |
57 | |
58 const GURL device_description_url_; | |
59 Profile* profile_; | |
imcheng
2016/12/28 05:36:45
Profile* const
mark a. foltz
2017/01/04 00:20:16
Done.
| |
60 base::OnceCallback<void(const DialDeviceDescription&)> success_cb_; | |
61 base::OnceCallback<void(const std::string&)> error_cb_; | |
62 std::unique_ptr<net::URLFetcher> fetcher_; | |
63 | |
64 // TODO: Add a thread checker | |
65 }; | |
66 | |
67 } // namespace extensions | |
68 | |
69 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ | |
OLD | NEW |