Index: chrome/browser/extensions/api/dial/device_description_fetcher.h |
diff --git a/chrome/browser/extensions/api/dial/device_description_fetcher.h b/chrome/browser/extensions/api/dial/device_description_fetcher.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b1a33a68c6d19cd5f88c76a8488b1937f4967e2f |
--- /dev/null |
+++ b/chrome/browser/extensions/api/dial/device_description_fetcher.h |
@@ -0,0 +1,72 @@ |
+// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
+#define CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
+ |
+#include <memory> |
+#include <string> |
+ |
+#include "base/callback.h" |
+#include "net/url_request/url_fetcher_delegate.h" |
+#include "url/gurl.h" |
+ |
+class Profile; |
+ |
+namespace net { |
+class URLFetcher; |
+} |
+ |
+namespace extensions { |
+namespace api { |
+namespace dial { |
+ |
+class DialDeviceDescriptionData; |
+ |
+// 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.
|
+// |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.
|
+// |success_cb| is invoked with the result; otherwise, |error_cb| is invoked |
+// with an error reason. This class is not thread safe and must be run on the |
+// 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.
|
+class DeviceDescriptionFetcher : public net::URLFetcherDelegate { |
+ public: |
+ // Used to identify the net::URLFetcher instance. |
+ 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.
|
+ |
+ DeviceDescriptionFetcher( |
+ const GURL& device_description_url, |
+ 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.
|
+ base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb, |
+ base::OnceCallback<void(const std::string&)> error_cb); |
+ |
+ ~DeviceDescriptionFetcher() override; |
+ |
+ 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.
|
+ |
+ private: |
+ // 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.
|
+ void OnURLFetchComplete(const net::URLFetcher* source) override; |
+ void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
+ int64_t current, |
+ int64_t total, |
+ int64_t current_network_bytes) override; |
+ void OnURLFetchUploadProgress(const net::URLFetcher* source, |
+ int64_t current, |
+ int64_t total) override; |
+ |
+ // 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.
|
+ void ReportError(const std::string& message); |
+ |
+ const GURL device_description_url_; |
+ Profile* const profile_; |
+ base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb_; |
+ base::OnceCallback<void(const std::string&)> error_cb_; |
+ std::unique_ptr<net::URLFetcher> fetcher_; |
+}; |
+ |
+} // namespace dial |
+} // namespace api |
+} // namespace extensions |
+ |
+#endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |