| 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..c7e45572e2d140f7c95742fc693f1402f8617f98 100644
|
| --- a/net/url_request/sdch_dictionary_fetcher.h
|
| +++ b/net/url_request/sdch_dictionary_fetcher.h
|
| @@ -45,18 +45,23 @@ 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);
|
| + explicit 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. Returns true if a
|
| + // request for |dictionary_url| has been scheduled, and false otherwise.
|
| + virtual bool 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. Returns true if a request
|
| + // for |dictionary_url| has been scheduled, and false otherwise.
|
| + virtual bool ScheduleReload(const GURL& dictionary_url,
|
| + const OnDictionaryFetchedCallback& callback);
|
|
|
| // Cancel any in-progress requests.
|
| - void Cancel();
|
| + virtual void Cancel();
|
|
|
| // Implementation of URLRequest::Delegate methods.
|
| void OnResponseStarted(URLRequest* request) override;
|
| @@ -72,6 +77,35 @@ class NET_EXPORT SdchDictionaryFetcher : public URLRequest::Delegate,
|
| STATE_REQUEST_COMPLETE,
|
| };
|
|
|
| + // Represents an entry in the queue of SDCH dictionaries to fetch. |url| is
|
| + // the URL to fetch from, |download_only_from_cache| is true if the fetch
|
| + // should only be served from cache, and |callback| is called when this queued
|
| + // fetch is complete.
|
| + struct QueuedFetchInfo {
|
| + QueuedFetchInfo();
|
| + QueuedFetchInfo(const GURL& url,
|
| + bool download_only_from_cache,
|
| + const OnDictionaryFetchedCallback& callback);
|
| + QueuedFetchInfo(const QueuedFetchInfo& rhs);
|
| + QueuedFetchInfo& operator=(const QueuedFetchInfo& rhs);
|
| +
|
| + ~QueuedFetchInfo();
|
| +
|
| + GURL url;
|
| + bool download_only_from_cache;
|
| + OnDictionaryFetchedCallback callback;
|
| + };
|
| +
|
| + // Schedule implementation. Returns true if a request for |dictionary_url| has
|
| + // been added to the queue, and false otherwise.
|
| + bool 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 +118,13 @@ 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_;
|
| + std::queue<QueuedFetchInfo> 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 +148,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);
|
|
|