Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Unified Diff: net/url_request/sdch_dictionary_fetcher.h

Issue 901303002: Make SDCH dictionaries persistent across browser restart. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More fixes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..af26f798b00edc0ee2499714bd2536639e5cbcbf 100644
--- a/net/url_request/sdch_dictionary_fetcher.h
+++ b/net/url_request/sdch_dictionary_fetcher.h
@@ -45,18 +45,21 @@ 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.
+ virtual void Schedule(const GURL& dictionary_url,
+ const OnDictionaryFetchedCallback& callback);
Randy Smith (Not in Mondays) 2015/02/16 01:10:05 nit, confusion: Bad indentation? But if 'git cl f
Elly Fong-Jones 2015/02/17 20:35:29 Done.
+
+ // Request a dictionary fetch from cache only. The callback will be called
+ // only if the dictionary is successfully fetched.
+ virtual void 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 +75,34 @@ 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.
+ 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 +115,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 +145,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);

Powered by Google App Engine
This is Rietveld 408576698