| 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_ |
| 11 #pragma once | 11 #pragma once |
| 12 | 12 |
| 13 #include <queue> | 13 #include <queue> |
| 14 #include <set> | 14 #include <set> |
| 15 #include <string> | 15 #include <string> |
| 16 | 16 |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/threading/non_thread_safe.h" | 19 #include "base/threading/non_thread_safe.h" |
| 20 #include "content/public/common/url_fetcher_delegate.h" | |
| 21 #include "net/base/sdch_manager.h" | 20 #include "net/base/sdch_manager.h" |
| 21 #include "net/url_request/url_fetcher_delegate.h" |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 class URLFetcher; |
| 24 class URLRequestContextGetter; | 25 class URLRequestContextGetter; |
| 25 } // namespace net | 26 } // namespace net |
| 26 | 27 |
| 27 class SdchDictionaryFetcher | 28 class SdchDictionaryFetcher |
| 28 : public content::URLFetcherDelegate, | 29 : public net::URLFetcherDelegate, |
| 29 public net::SdchFetcher, | 30 public net::SdchFetcher, |
| 30 public base::NonThreadSafe { | 31 public base::NonThreadSafe { |
| 31 public: | 32 public: |
| 32 explicit SdchDictionaryFetcher(net::URLRequestContextGetter* context); | 33 explicit SdchDictionaryFetcher(net::URLRequestContextGetter* context); |
| 33 virtual ~SdchDictionaryFetcher(); | 34 virtual ~SdchDictionaryFetcher(); |
| 34 | 35 |
| 35 // Stop fetching dictionaries, and abandon any current URLFetcheer operations | 36 // Stop fetching dictionaries, and abandon any current URLFetcheer operations |
| 36 // so that the IO thread can be stopped. | 37 // so that the IO thread can be stopped. |
| 37 static void Shutdown(); | 38 static void Shutdown(); |
| 38 | 39 |
| 39 // Implementation of SdchFetcher class. | 40 // Implementation of SdchFetcher class. |
| 40 // This method gets the requested dictionary, and then calls back into the | 41 // This method gets the requested dictionary, and then calls back into the |
| 41 // SdchManager class with the dictionary's text. | 42 // SdchManager class with the dictionary's text. |
| 42 virtual void Schedule(const GURL& dictionary_url) OVERRIDE; | 43 virtual void Schedule(const GURL& dictionary_url) OVERRIDE; |
| 43 | 44 |
| 44 private: | 45 private: |
| 45 // Delay in ms between Schedule and actual download. | 46 // 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 | 47 // 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 | 48 // 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. | 49 // page subresources (or tabs opened in parallel) all suggest the dictionary. |
| 49 static const int kMsDelayFromRequestTillDownload = 100; | 50 static const int kMsDelayFromRequestTillDownload = 100; |
| 50 | 51 |
| 51 // Ensure the download after the above delay. | 52 // Ensure the download after the above delay. |
| 52 void ScheduleDelayedRun(); | 53 void ScheduleDelayedRun(); |
| 53 | 54 |
| 54 // Make sure we're processing (or waiting for) the the arrival of the next URL | 55 // Make sure we're processing (or waiting for) the the arrival of the next URL |
| 55 // in the |fetch_queue_|. | 56 // in the |fetch_queue_|. |
| 56 void StartFetching(); | 57 void StartFetching(); |
| 57 | 58 |
| 58 // Implementation of content::URLFetcherDelegate. Called after transmission | 59 // Implementation of net::URLFetcherDelegate. Called after transmission |
| 59 // completes (either successfully or with failure). | 60 // completes (either successfully or with failure). |
| 60 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 61 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 61 | 62 |
| 62 // A queue of URLs that are being used to download dictionaries. | 63 // A queue of URLs that are being used to download dictionaries. |
| 63 std::queue<GURL> fetch_queue_; | 64 std::queue<GURL> fetch_queue_; |
| 64 // The currently outstanding URL fetch of a dicitonary. | 65 // The currently outstanding URL fetch of a dicitonary. |
| 65 // If this is null, then there is no outstanding request. | 66 // If this is null, then there is no outstanding request. |
| 66 scoped_ptr<content::URLFetcher> current_fetch_; | 67 scoped_ptr<net::URLFetcher> current_fetch_; |
| 67 | 68 |
| 68 // Always spread out the dictionary fetches, so that they don't steal | 69 // 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 | 70 // bandwidth from the actual page load. Create delayed tasks to spread out |
| 70 // the download. | 71 // the download. |
| 71 base::WeakPtrFactory<SdchDictionaryFetcher> weak_factory_; | 72 base::WeakPtrFactory<SdchDictionaryFetcher> weak_factory_; |
| 72 bool task_is_pending_; | 73 bool task_is_pending_; |
| 73 | 74 |
| 74 // Althought the SDCH spec does not preclude a server from using a single URL | 75 // Althought the SDCH spec does not preclude a server from using a single URL |
| 75 // to load several distinct dictionaries (by telling a client to load a | 76 // to load several distinct dictionaries (by telling a client to load a |
| 76 // dictionary from an URL several times), current implementations seem to have | 77 // dictionary from an URL several times), current implementations seem to have |
| (...skipping 10 matching lines...) Expand all Loading... |
| 87 std::set<GURL> attempted_load_; | 88 std::set<GURL> attempted_load_; |
| 88 | 89 |
| 89 // Store the system_url_request_context_getter to use it when we start | 90 // Store the system_url_request_context_getter to use it when we start |
| 90 // fetching. | 91 // fetching. |
| 91 scoped_refptr<net::URLRequestContextGetter> context_; | 92 scoped_refptr<net::URLRequestContextGetter> context_; |
| 92 | 93 |
| 93 DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); | 94 DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 #endif // CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ | 97 #endif // CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ |
| OLD | NEW |