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

Side by Side Diff: components/web_resource/web_resource_service.h

Issue 2217683002: Allow embedder to use custom ResourceRequestAllowedNotifier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow embedder to use custom ResourceRequestAllowedNotifier Created 4 years, 4 months 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #ifndef COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ 5 #ifndef COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_
6 #define COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ 6 #define COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 const char* disable_network_switch, 57 const char* disable_network_switch,
58 const ParseJSONCallback& parse_json_callback); 58 const ParseJSONCallback& parse_json_callback);
59 59
60 ~WebResourceService() override; 60 ~WebResourceService() override;
61 61
62 // Sleep until cache needs to be updated, but always for at least 62 // Sleep until cache needs to be updated, but always for at least
63 // |start_fetch_delay_ms| so we don't interfere with startup. 63 // |start_fetch_delay_ms| so we don't interfere with startup.
64 // Then begin updating resources. 64 // Then begin updating resources.
65 void StartAfterDelay(); 65 void StartAfterDelay();
66 66
67 // Sets the ResourceRequestAllowedNotifier to make it configurable.
68 void SetResourceRequestAllowedNotifier(
69 std::unique_ptr<ResourceRequestAllowedNotifier> notifier);
70
67 protected: 71 protected:
68 PrefService* prefs_; 72 PrefService* prefs_;
73 bool GetFetchScheduled() const;
69 74
70 private: 75 private:
76 friend class WebResourceServiceTest;
77
71 // For the subclasses to process the result of a fetch. 78 // For the subclasses to process the result of a fetch.
72 virtual void Unpack(const base::DictionaryValue& parsed_json) = 0; 79 virtual void Unpack(const base::DictionaryValue& parsed_json) = 0;
73 80
74 // net::URLFetcherDelegate implementation: 81 // net::URLFetcherDelegate implementation:
75 void OnURLFetchComplete(const net::URLFetcher* source) override; 82 void OnURLFetchComplete(const net::URLFetcher* source) override;
76 83
77 // Schedules a fetch after |delay_ms| milliseconds. 84 // Schedules a fetch after |delay_ms| milliseconds.
78 void ScheduleFetch(int64_t delay_ms); 85 void ScheduleFetch(int64_t delay_ms);
79 86
80 // Starts fetching data from the server. 87 // Starts fetching data from the server.
81 void StartFetch(); 88 void StartFetch();
82 89
83 // Set |in_fetch_| to false, clean up temp directories (in the future). 90 // Set |in_fetch_| to false, clean up temp directories (in the future).
84 void EndFetch(); 91 void EndFetch();
85 92
86 // Callbacks from the JSON parser. 93 // Callbacks from the JSON parser.
87 void OnUnpackFinished(std::unique_ptr<base::Value> value); 94 void OnUnpackFinished(std::unique_ptr<base::Value> value);
88 void OnUnpackError(const std::string& error_message); 95 void OnUnpackError(const std::string& error_message);
89 96
90 // Implements ResourceRequestAllowedNotifier::Observer. 97 // Implements ResourceRequestAllowedNotifier::Observer.
91 void OnResourceRequestsAllowed() override; 98 void OnResourceRequestsAllowed() override;
92 99
93 // Helper class used to tell this service if it's allowed to make network 100 // Helper class used to tell this service if it's allowed to make network
94 // resource requests. 101 // resource requests.
95 ResourceRequestAllowedNotifier resource_request_allowed_notifier_; 102 std::unique_ptr<ResourceRequestAllowedNotifier>
103 resource_request_allowed_notifier_;
104
105 // True if we have scheduled a fetch after start_fetch_delay_ms_
106 // or another one in |cache_update_delay_ms_| time. Set to false
107 // before fetching starts so that next fetch is scheduled. This is
Dan Beam 2016/08/19 02:14:32 nit: wrap to 80 character lines
guptaag 2017/03/01 21:52:24 On 2016/08/19 02:14:32, Dan Beam wrote: > nit: wra
108 // to make sure not more than one fetch is scheduled for given point in time.
109 bool fetch_scheduled_;
96 110
97 // The tool that fetches the url data from the server. 111 // The tool that fetches the url data from the server.
98 std::unique_ptr<net::URLFetcher> url_fetcher_; 112 std::unique_ptr<net::URLFetcher> url_fetcher_;
99 113
100 // True if we are currently fetching or unpacking data. If we are asked to 114 // True if we are currently fetching or unpacking data. If we are asked to
101 // start a fetch when we are still fetching resource data, schedule another 115 // start a fetch when we are still fetching resource data, schedule another
102 // one in |cache_update_delay_ms_| time, and silently exit. 116 // one in |cache_update_delay_ms_| time, and silently exit.
103 bool in_fetch_; 117 bool in_fetch_;
104 118
105 // URL that hosts the web resource. 119 // URL that hosts the web resource.
(...skipping 21 matching lines...) Expand all
127 // So that we can delay our start so as not to affect start-up time; also, 141 // So that we can delay our start so as not to affect start-up time; also,
128 // so that we can schedule future cache updates. 142 // so that we can schedule future cache updates.
129 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_; 143 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_;
130 144
131 DISALLOW_COPY_AND_ASSIGN(WebResourceService); 145 DISALLOW_COPY_AND_ASSIGN(WebResourceService);
132 }; 146 };
133 147
134 } // namespace web_resource 148 } // namespace web_resource
135 149
136 #endif // COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ 150 #endif // COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698