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

Side by Side Diff: net/url_request/sdch_dictionary_fetcher.h

Issue 664263002: Restructure SDCH layering to allow more separation (observer/1->[0,n] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync'd to p300953. Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // TODO(rdsmith): This class needs to be moved out to the net/ embedder and 5 // TODO(rdsmith): This class needs to delegate URLRequest::Delegate methods
6 // hooked into whatever mechanisms the embedder uses for authentication. 6 // to the net/ embedder for correct implementaiton of authentication.
Ryan Sleevi 2014/11/04 21:40:44 s/implementaiton/implementation/
Randy Smith (Not in Mondays) 2014/11/05 20:35:02 Done.
7 // Specifically, this class needs methods overriding 7 // Specifically, this class needs the embedder to provide functionality
8 // URLRequest::Delegate::{OnAuthRequired,OnCertificateRequested} and can't 8 // corresponding to
9 // implement them at the net/ layer. 9 // URLRequest::Delegate::{OnAuthRequired,OnCertificateRequested}.
10 10
11 #ifndef NET_BASE_SDCH_DICTIONARY_FETCHER_H_ 11 #ifndef NET_URL_REQUEST_SDCH_DICTIONARY_FETCHER_H_
12 #define NET_BASE_SDCH_DICTIONARY_FETCHER_H_ 12 #define NET_URL_REQUEST_SDCH_DICTIONARY_FETCHER_H_
13 13
14 #include <queue> 14 #include <queue>
15 #include <set> 15 #include <set>
16 #include <string> 16 #include <string>
17 17
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "base/threading/non_thread_safe.h" 20 #include "base/threading/non_thread_safe.h"
21 #include "net/base/sdch_manager.h" 21 #include "net/base/sdch_manager.h"
22 #include "net/url_request/url_fetcher_delegate.h" 22 #include "net/url_request/url_fetcher_delegate.h"
23 #include "net/url_request/url_request.h" 23 #include "net/url_request/url_request.h"
24 24
25 namespace net { 25 namespace net {
26 26
27 class URLRequest; 27 class URLRequest;
28 class URLRequestThrottlerEntryInterface; 28 class URLRequestThrottlerEntryInterface;
29 29
30 // This class implements the SdchFetcher interface. It queues requests 30 // This class is used by embedder SDCH policy object to fetch
31 // for dictionaries and dispatches them serially, implementing 31 // dictionaries. It queues requests for dictionaries and dispatches
32 // the URLRequest::Delegate interface to handle callbacks (but see above 32 // them serially, implementing the URLRequest::Delegate interface to
33 // TODO). It tracks all requests, only attempting to fetch each dictionary 33 // handle callbacks (but see above TODO). It tracks all requests, only
34 // once. 34 // attempting to fetch each dictionary once.
35 class NET_EXPORT SdchDictionaryFetcher 35 class NET_EXPORT SdchDictionaryFetcher
36 : public SdchFetcher, 36 : public URLRequest::Delegate,
Ryan Sleevi 2014/11/04 21:40:45 Compare with how you indented the other class. Pre
Randy Smith (Not in Mondays) 2014/11/05 20:35:02 Agreed; believed made consistent via the git cl fo
37 public URLRequest::Delegate,
38 public base::NonThreadSafe { 37 public base::NonThreadSafe {
39 public: 38 public:
40 // The consumer must guarantee that |*consumer| and |*context| outlive 39 typedef base::Callback<void(const std::string& dictionary_text,
41 // this object. 40 const GURL& dictionary_url)>
42 SdchDictionaryFetcher(SdchFetcher::Delegate* consumer, 41 OnDictionaryFetchedCallback;
43 URLRequestContext* context); 42
43 // The consumer must guarantee that |*context| outlives this object.
44 // |callback| will be called on successful dictionary fetch
45 // requested through Schedule(). |callback| will not be called
46 // after object destruction.
47 SdchDictionaryFetcher(URLRequestContext* context,
48 const OnDictionaryFetchedCallback& callback);
44 ~SdchDictionaryFetcher() override; 49 ~SdchDictionaryFetcher() override;
45 50
46 // Implementation of SdchFetcher methods. 51 // Request a new dictionary fetch.
47 void Schedule(const GURL& dictionary_url) override; 52 void Schedule(const GURL& dictionary_url);
48 void Cancel() override; 53
54 // Cancel any in-progress requests.
55 void Cancel();
49 56
50 // Implementation of URLRequest::Delegate methods. 57 // Implementation of URLRequest::Delegate methods.
51 void OnResponseStarted(URLRequest* request) override; 58 void OnResponseStarted(URLRequest* request) override;
52 void OnReadCompleted(URLRequest* request, int bytes_read) override; 59 void OnReadCompleted(URLRequest* request, int bytes_read) override;
53 60
54 private: 61 private:
55 enum State { 62 enum State {
56 STATE_NONE, 63 STATE_NONE,
57 STATE_IDLE, 64 STATE_IDLE,
58 STATE_REQUEST_STARTED, 65 STATE_REQUEST_STARTED,
59 STATE_REQUEST_READING, 66 STATE_REQUEST_READING,
60 STATE_REQUEST_COMPLETE, 67 STATE_REQUEST_COMPLETE,
61 }; 68 };
62 69
63 // State machine implementation. 70 // State machine implementation.
64 int DoLoop(int rv); 71 int DoLoop(int rv);
65 int DoDispatchRequest(int rv); 72 int DoDispatchRequest(int rv);
66 int DoRequestStarted(int rv); 73 int DoRequestStarted(int rv);
67 int DoRead(int rv); 74 int DoRead(int rv);
68 int DoCompleteRequest(int rv); 75 int DoCompleteRequest(int rv);
69 76
70 State next_state_; 77 State next_state_;
71 bool in_loop_; 78 bool in_loop_;
72 79
73 SdchFetcher::Delegate* const consumer_;
74
75 // A queue of URLs that are being used to download dictionaries. 80 // A queue of URLs that are being used to download dictionaries.
76 std::queue<GURL> fetch_queue_; 81 std::queue<GURL> fetch_queue_;
77 82
78 // The request and buffer used for getting the current dictionary 83 // The request and buffer used for getting the current dictionary
79 // Both are null when a fetch is not in progress. 84 // Both are null when a fetch is not in progress.
80 scoped_ptr<URLRequest> current_request_; 85 scoped_ptr<URLRequest> current_request_;
81 scoped_refptr<IOBuffer> buffer_; 86 scoped_refptr<IOBuffer> buffer_;
82 87
83 // The currently accumulating dictionary. 88 // The currently accumulating dictionary.
84 std::string dictionary_; 89 std::string dictionary_;
85 90
86 // Althought the SDCH spec does not preclude a server from using a single URL 91 // Althought the SDCH spec does not preclude a server from using a single URL
87 // to load several distinct dictionaries (by telling a client to load a 92 // to load several distinct dictionaries (by telling a client to load a
88 // dictionary from an URL several times), current implementations seem to have 93 // dictionary from an URL several times), current implementations seem to have
89 // that 1-1 relationship (i.e., each URL points at a single dictionary, and 94 // that 1-1 relationship (i.e., each URL points at a single dictionary, and
90 // the dictionary content does not change over time, and hence is not worth 95 // the dictionary content does not change over time, and hence is not worth
91 // trying to load more than once). In addition, some dictionaries prove 96 // trying to load more than once). In addition, some dictionaries prove
92 // unloadable only after downloading them (because they are too large? ...or 97 // unloadable only after downloading them (because they are too large? ...or
93 // malformed?). As a protective element, Chromium will *only* load a 98 // malformed?). As a protective element, Chromium will *only* load a
94 // dictionary at most once from a given URL (so that it doesn't waste 99 // dictionary at most once from a given URL (so that it doesn't waste
95 // bandwidth trying repeatedly). 100 // bandwidth trying repeatedly).
96 // The following set lists all the dictionary URLs that we've tried to load, 101 // The following set lists all the dictionary URLs that we've tried to load,
97 // so that we won't try to load from an URL more than once. 102 // so that we won't try to load from an URL more than once.
98 // TODO(jar): Try to augment the SDCH proposal to include this restiction. 103 // TODO(jar): Try to augment the SDCH proposal to include this restiction.
99 std::set<GURL> attempted_load_; 104 std::set<GURL> attempted_load_;
100 105
101 // Store the URLRequestContext associated with the owning SdchManager for 106 // Store the URLRequestContext associated with the owning SdchManager for
102 // use while fetching. 107 // use while fetching.
103 URLRequestContext* context_; 108 URLRequestContext * const context_;
109
110 const OnDictionaryFetchedCallback dictionary_fetched_callback_;
104 111
105 base::WeakPtrFactory<SdchDictionaryFetcher> weak_factory_; 112 base::WeakPtrFactory<SdchDictionaryFetcher> weak_factory_;
106 113
107 DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); 114 DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher);
108 }; 115 };
109 116
110 } // namespace net 117 } // namespace net
111 118
112 #endif // NET_BASE_SDCH_DICTIONARY_FETCHER_H_ 119 #endif // NET_URL_REQUEST_SDCH_DICTIONARY_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698