OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/task.h" | 18 #include "base/task.h" |
19 #include "content/common/net/url_fetcher.h" | 19 #include "content/public/common/url_fetcher_delegate.h" |
20 #include "net/base/sdch_manager.h" | 20 #include "net/base/sdch_manager.h" |
21 | 21 |
22 class SdchDictionaryFetcher : public URLFetcher::Delegate, | 22 class SdchDictionaryFetcher : public content::URLFetcherDelegate, |
23 public net::SdchFetcher { | 23 public net::SdchFetcher { |
24 public: | 24 public: |
25 SdchDictionaryFetcher(); | 25 SdchDictionaryFetcher(); |
26 virtual ~SdchDictionaryFetcher(); | 26 virtual ~SdchDictionaryFetcher(); |
27 | 27 |
28 // Stop fetching dictionaries, and abandon any current URLFetcheer operations | 28 // Stop fetching dictionaries, and abandon any current URLFetcheer operations |
29 // so that the IO thread can be stopped. | 29 // so that the IO thread can be stopped. |
30 static void Shutdown(); | 30 static void Shutdown(); |
31 | 31 |
32 // Implementation of SdchFetcher class. | 32 // Implementation of SdchFetcher class. |
33 // This method gets the requested dictionary, and then calls back into the | 33 // This method gets the requested dictionary, and then calls back into the |
34 // SdchManager class with the dictionary's text. | 34 // SdchManager class with the dictionary's text. |
35 virtual void Schedule(const GURL& dictionary_url); | 35 virtual void Schedule(const GURL& dictionary_url); |
36 | 36 |
37 private: | 37 private: |
38 // Delay in ms between Schedule and actual download. | 38 // Delay in ms between Schedule and actual download. |
39 // This leaves the URL in a queue, which is de-duped, so that there is less | 39 // This leaves the URL in a queue, which is de-duped, so that there is less |
40 // chance we'll try to load the same URL multiple times when a pile of | 40 // chance we'll try to load the same URL multiple times when a pile of |
41 // page subresources (or tabs opened in parallel) all suggest the dictionary. | 41 // page subresources (or tabs opened in parallel) all suggest the dictionary. |
42 static const int kMsDelayFromRequestTillDownload = 100; | 42 static const int kMsDelayFromRequestTillDownload = 100; |
43 | 43 |
44 // Ensure the download after the above delay. | 44 // Ensure the download after the above delay. |
45 void ScheduleDelayedRun(); | 45 void ScheduleDelayedRun(); |
46 | 46 |
47 // Make sure we're processing (or waiting for) the the arrival of the next URL | 47 // Make sure we're processing (or waiting for) the the arrival of the next URL |
48 // in the |fetch_queue_|. | 48 // in the |fetch_queue_|. |
49 void StartFetching(); | 49 void StartFetching(); |
50 | 50 |
51 // Implementation of URLFetcher::Delegate. Called after transmission | 51 // Implementation of content::URLFetcherDelegate. Called after transmission |
52 // completes (either successfully or with failure). | 52 // completes (either successfully or with failure). |
53 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 53 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
54 | 54 |
55 // A queue of URLs that are being used to download dictionaries. | 55 // A queue of URLs that are being used to download dictionaries. |
56 std::queue<GURL> fetch_queue_; | 56 std::queue<GURL> fetch_queue_; |
57 // The currently outstanding URL fetch of a dicitonary. | 57 // The currently outstanding URL fetch of a dicitonary. |
58 // If this is null, then there is no outstanding request. | 58 // If this is null, then there is no outstanding request. |
59 scoped_ptr<URLFetcher> current_fetch_; | 59 scoped_ptr<URLFetcher> current_fetch_; |
60 | 60 |
61 // Always spread out the dictionary fetches, so that they don't steal | 61 // Always spread out the dictionary fetches, so that they don't steal |
(...skipping 14 matching lines...) Expand all Loading... |
76 // bandwidth trying repeatedly). | 76 // bandwidth trying repeatedly). |
77 // The following set lists all the dictionary URLs that we've tried to load, | 77 // The following set lists all the dictionary URLs that we've tried to load, |
78 // so that we won't try to load from an URL more than once. | 78 // so that we won't try to load from an URL more than once. |
79 // TODO(jar): Try to augment the SDCH proposal to include this restiction. | 79 // TODO(jar): Try to augment the SDCH proposal to include this restiction. |
80 std::set<GURL> attempted_load_; | 80 std::set<GURL> attempted_load_; |
81 | 81 |
82 DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); | 82 DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); |
83 }; | 83 }; |
84 | 84 |
85 #endif // CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ | 85 #endif // CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ |
OLD | NEW |