Chromium Code Reviews| Index: net/url_request/sdch_dictionary_fetcher.h |
| diff --git a/net/url_request/sdch_dictionary_fetcher.h b/net/url_request/sdch_dictionary_fetcher.h |
| index 4ca25034e8e5467a7082c9efd18b40e77017eb20..a09d0fc3a26ece7ad64292bd9314a5765fb0a58f 100644 |
| --- a/net/url_request/sdch_dictionary_fetcher.h |
| +++ b/net/url_request/sdch_dictionary_fetcher.h |
| @@ -45,15 +45,18 @@ class NET_EXPORT SdchDictionaryFetcher : public URLRequest::Delegate, |
| OnDictionaryFetchedCallback; |
| // The consumer must guarantee that |*context| outlives this object. |
| - // |callback| will be called on successful dictionary fetch |
| - // requested through Schedule(). |callback| will not be called |
| - // after object destruction. |
| - SdchDictionaryFetcher(URLRequestContext* context, |
| - const OnDictionaryFetchedCallback& callback); |
| + SdchDictionaryFetcher(URLRequestContext* context); |
| ~SdchDictionaryFetcher() override; |
| - // Request a new dictionary fetch. |
| - void Schedule(const GURL& dictionary_url); |
| + // Request a new dictionary fetch. The callback will be called |
| + // only if the dictionary is successfully fetched. |
| + void Schedule(const GURL& dictionary_url, |
| + const OnDictionaryFetchedCallback& callback); |
| + |
| + // Request a dictionary fetch from cache only. The callback will be called |
| + // only if the dictionary is successfully fetched. |
| + void ScheduleReload(const GURL& dictionary_url, |
| + const OnDictionaryFetchedCallback& callback); |
| // Cancel any in-progress requests. |
| void Cancel(); |
| @@ -72,6 +75,30 @@ class NET_EXPORT SdchDictionaryFetcher : public URLRequest::Delegate, |
| STATE_REQUEST_COMPLETE, |
| }; |
| + struct QueuedInfo { |
| + const GURL url; |
| + bool download_only_from_cache; |
| + OnDictionaryFetchedCallback callback; |
| + |
| + QueuedInfo(); |
| + QueuedInfo(const GURL& url, |
| + bool download_only_from_cache, |
| + const OnDictionaryFetchedCallback& callback); |
| + QueuedInfo(const QueuedInfo& rhs) = default; |
|
Bernhard Bauer
2015/02/06 16:40:27
Hm... I think technically this defines the constru
Elly Fong-Jones
2015/02/06 18:44:09
Done. We can only have an operator= if the GURL me
Bernhard Bauer
2015/02/06 20:12:18
Makes sense, if we allow assignment.
(What does t
|
| + QueuedInfo& operator=(const QueuedInfo& rhs) = default; |
| + |
| + ~QueuedInfo(); |
| + }; |
| + |
| + // Schedule implementation. |
| + void ScheduleInternal(const GURL& dictionary_url, |
| + bool reload, |
| + const OnDictionaryFetchedCallback& callback); |
| + |
| + // Null out the current request and push the state machine to the |
| + // next request, if any. |
| + void ResetRequest(); |
| + |
| // State machine implementation. |
| int DoLoop(int rv); |
| int DoSendRequest(int rv); |
| @@ -84,12 +111,15 @@ class NET_EXPORT SdchDictionaryFetcher : public URLRequest::Delegate, |
| bool in_loop_; |
| // A queue of URLs that are being used to download dictionaries. |
| - std::queue<GURL> fetch_queue_; |
| + // |fetch_queue_[n].second| indicated whether the download should occur |
| + // only from cache. |
| + std::queue<QueuedInfo> fetch_queue_; |
| - // The request and buffer used for getting the current dictionary |
| - // Both are null when a fetch is not in progress. |
| + // The request, buffer, and consumer supplied data used for getting |
| + // the current dictionary. All are null when a fetch is not in progress. |
| scoped_ptr<URLRequest> current_request_; |
| scoped_refptr<IOBuffer> buffer_; |
| + OnDictionaryFetchedCallback current_callback_; |
| // The currently accumulating dictionary. |
| std::string dictionary_; |
| @@ -113,8 +143,6 @@ class NET_EXPORT SdchDictionaryFetcher : public URLRequest::Delegate, |
| // use while fetching. |
| URLRequestContext* const context_; |
| - const OnDictionaryFetchedCallback dictionary_fetched_callback_; |
| - |
| base::WeakPtrFactory<SdchDictionaryFetcher> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); |