Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "content/public/browser/browser_thread.h" | |
| 12 #include "net/url_request/url_fetcher_delegate.h" | 13 #include "net/url_request/url_fetcher_delegate.h" |
| 13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 14 | 15 |
| 15 class Profile; | |
| 16 | |
| 17 namespace net { | 16 namespace net { |
| 18 class URLFetcher; | 17 class URLFetcher; |
| 18 class URLRequestContextGetter; | |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 namespace api { | 22 namespace api { |
| 23 namespace dial { | 23 namespace dial { |
| 24 | 24 |
| 25 struct DialDeviceDescriptionData; | 25 struct DialDeviceDescriptionData; |
| 26 | 26 |
| 27 // Used to make a single HTTP GET request with |device_description_url| to fetch | 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 | 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 | 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. | 30 // reason. |
| 31 // This class is not thread safe and must be used on the UI or IO thread. | |
|
mark a. foltz
2017/03/01 21:44:00
It's safe to use the URLFetcher from either thread
zhaobin
2017/03/02 07:04:35
Done.
| |
| 31 class DeviceDescriptionFetcher : public net::URLFetcherDelegate { | 32 class DeviceDescriptionFetcher : public net::URLFetcherDelegate { |
|
imcheng
2017/02/22 03:45:04
I would make it clear that an instance must only b
zhaobin
2017/03/02 07:04:35
Acknowledged.
| |
| 32 public: | 33 public: |
| 33 // Used to identify the net::URLFetcher instance for tests. | 34 // Used to identify the net::URLFetcher instance for tests. |
| 34 static constexpr int kURLFetcherIDForTest = 1; | 35 static constexpr int kURLFetcherIDForTest = 1; |
| 35 | 36 |
| 36 // |profile| is unowned; the caller must ensure that this object does not | 37 // |request_context| is unowned; the caller must ensure that this object does |
| 37 // outlive it. | 38 // not outlive it. |
| 38 DeviceDescriptionFetcher( | 39 DeviceDescriptionFetcher( |
| 39 const GURL& device_description_url, | 40 const GURL& device_description_url, |
| 40 Profile* profile, | 41 net::URLRequestContextGetter* request_context, |
| 42 content::BrowserThread::ID thread_id, | |
| 41 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb, | 43 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb, |
| 42 base::OnceCallback<void(const std::string&)> error_cb); | 44 base::OnceCallback<void(const std::string&)> error_cb); |
| 43 | 45 |
| 44 ~DeviceDescriptionFetcher() override; | 46 ~DeviceDescriptionFetcher() override; |
| 45 | 47 |
| 46 void Start(); | 48 void Start(); |
| 47 | 49 |
| 48 private: | 50 private: |
| 49 // net::URLFetcherDelegate implementation. | 51 // net::URLFetcherDelegate implementation. |
| 50 void OnURLFetchComplete(const net::URLFetcher* source) override; | 52 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 51 void OnURLFetchDownloadProgress(const net::URLFetcher* source, | 53 void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| 52 int64_t current, | 54 int64_t current, |
| 53 int64_t total, | 55 int64_t total, |
| 54 int64_t current_network_bytes) override; | 56 int64_t current_network_bytes) override; |
| 55 void OnURLFetchUploadProgress(const net::URLFetcher* source, | 57 void OnURLFetchUploadProgress(const net::URLFetcher* source, |
| 56 int64_t current, | 58 int64_t current, |
| 57 int64_t total) override; | 59 int64_t total) override; |
| 58 | 60 |
| 59 // Runs |error_cb_| with |message| and clears it. | 61 // Runs |error_cb_| with |message| and clears it. |
| 60 void ReportError(const std::string& message); | 62 void ReportError(const std::string& message); |
| 61 | 63 |
| 62 const GURL device_description_url_; | 64 const GURL device_description_url_; |
| 63 Profile* const profile_; | 65 net::URLRequestContextGetter* const request_context_; |
| 66 content::BrowserThread::ID thread_id_; | |
| 67 | |
| 64 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb_; | 68 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb_; |
| 65 base::OnceCallback<void(const std::string&)> error_cb_; | 69 base::OnceCallback<void(const std::string&)> error_cb_; |
| 66 std::unique_ptr<net::URLFetcher> fetcher_; | 70 std::unique_ptr<net::URLFetcher> fetcher_; |
| 67 }; | 71 }; |
| 68 | 72 |
| 69 } // namespace dial | 73 } // namespace dial |
| 70 } // namespace api | 74 } // namespace api |
| 71 } // namespace extensions | 75 } // namespace extensions |
| 72 | 76 |
| 73 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ | 77 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
| OLD | NEW |