Chromium Code Reviews| 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 namespace api { | |
| 23 namespace dial { | |
| 24 | |
| 25 class DialDeviceDescriptionData; | |
| 26 | |
| 27 // An instance of this class is used to make a single HTTP GET request with | |
|
Wez
2017/01/05 22:29:24
nit: No need for "An instance of this class" - can
mark a. foltz
2017/01/09 21:38:07
Done.
| |
| 28 // |device_description_url| to fetch a uPnP device description. If successful, | |
|
Wez
2017/01/05 22:29:24
nit: Is this description retrieval specific to DIA
mark a. foltz
2017/01/09 21:38:07
It has DIAL-specific logic like retrieving the app
Wez
2017/01/09 22:12:58
Acknowledged.
| |
| 29 // |success_cb| is invoked with the result; otherwise, |error_cb| is invoked | |
| 30 // with an error reason. This class is not thread safe and must be run on the | |
| 31 // UI thread. | |
|
Wez
2017/01/05 22:29:24
nit: Re thread-safety, must this class be construc
mark a. foltz
2017/01/09 21:38:07
s/run/used/
Wez
2017/01/09 22:12:58
Acknowledged.
| |
| 32 class DeviceDescriptionFetcher : public net::URLFetcherDelegate { | |
| 33 public: | |
| 34 // Used to identify the net::URLFetcher instance. | |
| 35 static constexpr int kURLFetcherID = 1; | |
|
Wez
2017/01/05 22:29:24
nit: This is only public for testing, and the purp
mark a. foltz
2017/01/09 21:38:07
I don't need multiple request IDs to test this cla
Wez
2017/01/09 22:12:58
Acknowledged.
| |
| 36 | |
| 37 DeviceDescriptionFetcher( | |
| 38 const GURL& device_description_url, | |
| 39 Profile* profile, | |
|
Wez
2017/01/05 22:29:24
Is the caller responsible for ensuring that the in
mark a. foltz
2017/01/09 21:38:07
The DIAL API is a BrowserContext-keyed service, it
Wez
2017/01/09 22:12:58
No, I think this is fine, so long as the lifetime
mark a. foltz
2017/01/10 00:36:13
Done.
| |
| 40 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb, | |
| 41 base::OnceCallback<void(const std::string&)> error_cb); | |
| 42 | |
| 43 ~DeviceDescriptionFetcher() override; | |
| 44 | |
| 45 void Start(); | |
|
Wez
2017/01/05 22:29:24
nit: Do we need a separate Start() API, or could w
mark a. foltz
2017/01/09 21:38:07
Generally it's not a good idea to write constructo
Wez
2017/01/09 22:12:58
Granted, but it would be reasonable to have a stat
mark a. foltz
2017/01/10 00:36:13
Acknowledged.
| |
| 46 | |
| 47 private: | |
| 48 // net::URLFetcherDelegate | |
|
Wez
2017/01/05 22:29:24
nit: "|class| implementation." or "|class| interfa
mark a. foltz
2017/01/09 21:38:07
Done.
| |
| 49 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 50 void OnURLFetchDownloadProgress(const net::URLFetcher* source, | |
| 51 int64_t current, | |
| 52 int64_t total, | |
| 53 int64_t current_network_bytes) override; | |
| 54 void OnURLFetchUploadProgress(const net::URLFetcher* source, | |
| 55 int64_t current, | |
| 56 int64_t total) override; | |
| 57 | |
| 58 // Runs |error_cb_| with |message|. | |
|
Wez
2017/01/05 22:29:24
nit: Not obvious from the comment, but it Run()s a
mark a. foltz
2017/01/09 21:38:07
Updated comment, but as error_cb is a OnceCallback
Wez
2017/01/09 22:12:58
Acknowledged.
| |
| 59 void ReportError(const std::string& message); | |
| 60 | |
| 61 const GURL device_description_url_; | |
| 62 Profile* const profile_; | |
| 63 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb_; | |
| 64 base::OnceCallback<void(const std::string&)> error_cb_; | |
| 65 std::unique_ptr<net::URLFetcher> fetcher_; | |
| 66 }; | |
| 67 | |
| 68 } // namespace dial | |
| 69 } // namespace api | |
| 70 } // namespace extensions | |
| 71 | |
| 72 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ | |
| OLD | NEW |