Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Support modularity by calling to load a new SDCH filter dictionary. | 5 // Support modularity by calling to load a new SDCH filter dictionary. |
| 6 // Note that this sort of calling can't be done in the /net directory, as it has | 6 // Note that this sort of calling can't be done in the /net directory, as it has |
| 7 // no concept of the HTTP cache (which is only visible at the browser level). | 7 // no concept of the HTTP cache (which is only visible at the browser level). |
| 8 | 8 |
| 9 #ifndef CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ | 9 #ifndef CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ |
| 10 #define CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ | 10 #define CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 namespace net { | 22 namespace net { |
| 23 class URLFetcher; | 23 class URLFetcher; |
| 24 class URLRequestContextGetter; | 24 class URLRequestContextGetter; |
| 25 } // namespace net | 25 } // namespace net |
| 26 | 26 |
| 27 class SdchDictionaryFetcher | 27 class SdchDictionaryFetcher |
| 28 : public net::URLFetcherDelegate, | 28 : public net::URLFetcherDelegate, |
| 29 public net::SdchFetcher, | 29 public net::SdchFetcher, |
| 30 public base::NonThreadSafe { | 30 public base::NonThreadSafe { |
| 31 public: | 31 public: |
| 32 explicit SdchDictionaryFetcher(net::URLRequestContextGetter* context); | 32 // Consumer must guarantee that the SdchManager pointer outlives |
| 33 // this object. Usually this is done by making sure the manager | |
| 34 // owns this object. | |
| 35 SdchDictionaryFetcher(net::SdchManager* manager, | |
| 36 net::URLRequestContextGetter* context); | |
| 33 virtual ~SdchDictionaryFetcher(); | 37 virtual ~SdchDictionaryFetcher(); |
| 34 | 38 |
| 35 // Stop fetching dictionaries, and abandon any current URLFetcheer operations | |
| 36 // so that the IO thread can be stopped. | |
| 37 static void Shutdown(); | |
|
jar (doing other things)
2014/05/27 17:53:09
Given that the dictionary fetch is very async... I
Randy Smith (Not in Mondays)
2014/06/04 22:04:52
I believe what I currently have is equivalent to t
| |
| 38 | |
| 39 // Implementation of SdchFetcher class. | 39 // Implementation of SdchFetcher class. |
| 40 // This method gets the requested dictionary, and then calls back into the | 40 // This method gets the requested dictionary, and then calls back into the |
| 41 // SdchManager class with the dictionary's text. | 41 // SdchManager class with the dictionary's text. |
| 42 virtual void Schedule(const GURL& dictionary_url) OVERRIDE; | 42 virtual void Schedule(const GURL& dictionary_url) OVERRIDE; |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 // Delay in ms between Schedule and actual download. | 45 // Delay in ms between Schedule and actual download. |
| 46 // This leaves the URL in a queue, which is de-duped, so that there is less | 46 // This leaves the URL in a queue, which is de-duped, so that there is less |
| 47 // chance we'll try to load the same URL multiple times when a pile of | 47 // chance we'll try to load the same URL multiple times when a pile of |
| 48 // page subresources (or tabs opened in parallel) all suggest the dictionary. | 48 // page subresources (or tabs opened in parallel) all suggest the dictionary. |
| 49 static const int kMsDelayFromRequestTillDownload = 100; | 49 static const int kMsDelayFromRequestTillDownload = 100; |
| 50 | 50 |
| 51 // Ensure the download after the above delay. | 51 // Ensure the download after the above delay. |
| 52 void ScheduleDelayedRun(); | 52 void ScheduleDelayedRun(); |
| 53 | 53 |
| 54 // Make sure we're processing (or waiting for) the the arrival of the next URL | 54 // Make sure we're processing (or waiting for) the the arrival of the next URL |
| 55 // in the |fetch_queue_|. | 55 // in the |fetch_queue_|. |
| 56 void StartFetching(); | 56 void StartFetching(); |
| 57 | 57 |
| 58 // Implementation of net::URLFetcherDelegate. Called after transmission | 58 // Implementation of net::URLFetcherDelegate. Called after transmission |
| 59 // completes (either successfully or with failure). | 59 // completes (either successfully or with failure). |
| 60 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 60 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 61 | 61 |
| 62 net::SdchManager* manager_; | |
| 63 | |
| 62 // A queue of URLs that are being used to download dictionaries. | 64 // A queue of URLs that are being used to download dictionaries. |
| 63 std::queue<GURL> fetch_queue_; | 65 std::queue<GURL> fetch_queue_; |
| 64 // The currently outstanding URL fetch of a dicitonary. | 66 // The currently outstanding URL fetch of a dicitonary. |
| 65 // If this is null, then there is no outstanding request. | 67 // If this is null, then there is no outstanding request. |
| 66 scoped_ptr<net::URLFetcher> current_fetch_; | 68 scoped_ptr<net::URLFetcher> current_fetch_; |
| 67 | 69 |
| 68 // Always spread out the dictionary fetches, so that they don't steal | 70 // Always spread out the dictionary fetches, so that they don't steal |
| 69 // bandwidth from the actual page load. Create delayed tasks to spread out | 71 // bandwidth from the actual page load. Create delayed tasks to spread out |
| 70 // the download. | 72 // the download. |
| 71 base::WeakPtrFactory<SdchDictionaryFetcher> weak_factory_; | 73 base::WeakPtrFactory<SdchDictionaryFetcher> weak_factory_; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 87 std::set<GURL> attempted_load_; | 89 std::set<GURL> attempted_load_; |
| 88 | 90 |
| 89 // Store the system_url_request_context_getter to use it when we start | 91 // Store the system_url_request_context_getter to use it when we start |
| 90 // fetching. | 92 // fetching. |
| 91 scoped_refptr<net::URLRequestContextGetter> context_; | 93 scoped_refptr<net::URLRequestContextGetter> context_; |
| 92 | 94 |
| 93 DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); | 95 DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); |
| 94 }; | 96 }; |
| 95 | 97 |
| 96 #endif // CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ | 98 #endif // CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ |
| OLD | NEW |