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

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: 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);
Dan Beam 2016/08/08 18:15:33 4\s indent instead of 2\s (add 2 more spaces to th
70
67 protected: 71 protected:
68 PrefService* prefs_; 72 PrefService* prefs_;
69 73
70 private: 74 private:
75 friend class WebResourceServiceTest;
76
71 // For the subclasses to process the result of a fetch. 77 // For the subclasses to process the result of a fetch.
72 virtual void Unpack(const base::DictionaryValue& parsed_json) = 0; 78 virtual void Unpack(const base::DictionaryValue& parsed_json) = 0;
73 79
74 // net::URLFetcherDelegate implementation: 80 // net::URLFetcherDelegate implementation:
75 void OnURLFetchComplete(const net::URLFetcher* source) override; 81 void OnURLFetchComplete(const net::URLFetcher* source) override;
76 82
77 // Schedules a fetch after |delay_ms| milliseconds. 83 // Schedules a fetch after |delay_ms| milliseconds.
78 void ScheduleFetch(int64_t delay_ms); 84 void ScheduleFetch(int64_t delay_ms);
79 85
80 // Starts fetching data from the server. 86 // Starts fetching data from the server.
81 void StartFetch(); 87 void StartFetch();
82 88
83 // Set |in_fetch_| to false, clean up temp directories (in the future). 89 // Set |in_fetch_| to false, clean up temp directories (in the future).
84 void EndFetch(); 90 void EndFetch();
85 91
86 // Callbacks from the JSON parser. 92 // Callbacks from the JSON parser.
87 void OnUnpackFinished(std::unique_ptr<base::Value> value); 93 void OnUnpackFinished(std::unique_ptr<base::Value> value);
88 void OnUnpackError(const std::string& error_message); 94 void OnUnpackError(const std::string& error_message);
89 95
90 // Implements ResourceRequestAllowedNotifier::Observer. 96 // Implements ResourceRequestAllowedNotifier::Observer.
91 void OnResourceRequestsAllowed() override; 97 void OnResourceRequestsAllowed() override;
92 98
93 // Helper class used to tell this service if it's allowed to make network 99 // Helper class used to tell this service if it's allowed to make network
94 // resource requests. 100 // resource requests.
95 ResourceRequestAllowedNotifier resource_request_allowed_notifier_; 101 std::unique_ptr<ResourceRequestAllowedNotifier>
102 resource_request_allowed_notifier_;
103
104 // True if we have scheduled a fetch after start_fetch_delay_ms_
105 // or another one in |cache_update_delay_ms_| time. Set to false
106 // before fetching starts so that next fetch is scheduled. This is
107 // to make sure not more than one fetch is scheduled for given point in time.
108 bool fetch_scheduled_;
96 109
97 // The tool that fetches the url data from the server. 110 // The tool that fetches the url data from the server.
98 std::unique_ptr<net::URLFetcher> url_fetcher_; 111 std::unique_ptr<net::URLFetcher> url_fetcher_;
99 112
100 // True if we are currently fetching or unpacking data. If we are asked to 113 // 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 114 // start a fetch when we are still fetching resource data, schedule another
102 // one in |cache_update_delay_ms_| time, and silently exit. 115 // one in |cache_update_delay_ms_| time, and silently exit.
103 bool in_fetch_; 116 bool in_fetch_;
104 117
105 // URL that hosts the web resource. 118 // 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, 140 // 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. 141 // so that we can schedule future cache updates.
129 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_; 142 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_;
130 143
131 DISALLOW_COPY_AND_ASSIGN(WebResourceService); 144 DISALLOW_COPY_AND_ASSIGN(WebResourceService);
132 }; 145 };
133 146
134 } // namespace web_resource 147 } // namespace web_resource
135 148
136 #endif // COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ 149 #endif // COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698