OLD | NEW |
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 be moved out to the net/ embedder and |
6 // hooked into whatever mechanisms the embedder uses for authentication. | 6 // hooked into whatever mechanisms the embedder uses for authentication. |
7 // Specifically, this class needs methods overriding | 7 // Specifically, this class needs methods overriding |
8 // URLRequest::Delegate::{OnAuthRequired,OnCertificateRequested} and can't | 8 // URLRequest::Delegate::{OnAuthRequired,OnCertificateRequested} and can't |
9 // implement them at the net/ layer. | 9 // implement them at the net/ layer. |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 public URLRequest::Delegate, | 37 public URLRequest::Delegate, |
38 public base::NonThreadSafe { | 38 public base::NonThreadSafe { |
39 public: | 39 public: |
40 // The consumer must guarantee that |*consumer| and |*context| outlive | 40 // The consumer must guarantee that |*consumer| and |*context| outlive |
41 // this object. | 41 // this object. |
42 SdchDictionaryFetcher(SdchFetcher::Delegate* consumer, | 42 SdchDictionaryFetcher(SdchFetcher::Delegate* consumer, |
43 URLRequestContext* context); | 43 URLRequestContext* context); |
44 ~SdchDictionaryFetcher() override; | 44 ~SdchDictionaryFetcher() override; |
45 | 45 |
46 // Implementation of SdchFetcher methods. | 46 // Implementation of SdchFetcher methods. |
47 void Schedule(const GURL& dictionary_url) override; | 47 bool Schedule(const GURL& dictionary_url) override; |
48 void Cancel() override; | 48 void Cancel() override; |
49 | 49 |
50 // Implementation of URLRequest::Delegate methods. | 50 // Implementation of URLRequest::Delegate methods. |
51 void OnResponseStarted(URLRequest* request) override; | 51 void OnResponseStarted(URLRequest* request) override; |
52 void OnReadCompleted(URLRequest* request, int bytes_read) override; | 52 void OnReadCompleted(URLRequest* request, int bytes_read) override; |
53 | 53 |
54 private: | 54 private: |
55 enum State { | 55 enum State { |
56 STATE_NONE, | 56 STATE_NONE, |
57 STATE_IDLE, | 57 STATE_IDLE, |
58 STATE_REQUEST_STARTED, | 58 STATE_REQUEST_STARTED, |
59 STATE_REQUEST_READING, | 59 STATE_REQUEST_READING, |
60 STATE_REQUEST_COMPLETE, | 60 STATE_REQUEST_COMPLETE, |
61 }; | 61 }; |
62 | 62 |
63 // State machine implementation. | 63 // State machine implementation. |
64 int DoLoop(int rv); | 64 int DoLoop(int rv); |
65 int DoDispatchRequest(int rv); | 65 int DoDispatchRequest(int rv); |
66 int DoRequestStarted(int rv); | 66 int DoRequestStarted(int rv); |
67 int DoRead(int rv); | 67 int DoRead(int rv); |
68 int DoCompleteRequest(int rv); | 68 int DoCompleteRequest(int rv); |
69 | 69 |
| 70 // Record SDCH problem histogram and add netlog event. |
| 71 void LogDictionaryFetchError(SdchProblemCode error); |
| 72 |
70 State next_state_; | 73 State next_state_; |
71 bool in_loop_; | 74 bool in_loop_; |
72 | 75 |
73 SdchFetcher::Delegate* const consumer_; | 76 SdchFetcher::Delegate* const consumer_; |
74 | 77 |
75 // A queue of URLs that are being used to download dictionaries. | 78 // A queue of URLs that are being used to download dictionaries. |
76 std::queue<GURL> fetch_queue_; | 79 std::queue<GURL> fetch_queue_; |
77 | 80 |
78 // The request and buffer used for getting the current dictionary | 81 // The request and buffer used for getting the current dictionary |
79 // Both are null when a fetch is not in progress. | 82 // Both are null when a fetch is not in progress. |
(...skipping 23 matching lines...) Expand all Loading... |
103 URLRequestContext* context_; | 106 URLRequestContext* context_; |
104 | 107 |
105 base::WeakPtrFactory<SdchDictionaryFetcher> weak_factory_; | 108 base::WeakPtrFactory<SdchDictionaryFetcher> weak_factory_; |
106 | 109 |
107 DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); | 110 DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); |
108 }; | 111 }; |
109 | 112 |
110 } // namespace net | 113 } // namespace net |
111 | 114 |
112 #endif // NET_BASE_SDCH_DICTIONARY_FETCHER_H_ | 115 #endif // NET_BASE_SDCH_DICTIONARY_FETCHER_H_ |
OLD | NEW |