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

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 3 years, 9 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
« no previous file with comments | « components/web_resource/BUILD.gn ('k') | components/web_resource/web_resource_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
108 // is to make sure not more than one fetch is scheduled for given
109 // point in time.
110 bool fetch_scheduled_;
96 111
97 // The tool that fetches the url data from the server. 112 // The tool that fetches the url data from the server.
98 std::unique_ptr<net::URLFetcher> url_fetcher_; 113 std::unique_ptr<net::URLFetcher> url_fetcher_;
99 114
100 // True if we are currently fetching or unpacking data. If we are asked to 115 // 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 116 // start a fetch when we are still fetching resource data, schedule another
102 // one in |cache_update_delay_ms_| time, and silently exit. 117 // one in |cache_update_delay_ms_| time, and silently exit.
103 bool in_fetch_; 118 bool in_fetch_;
104 119
105 // URL that hosts the web resource. 120 // 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, 142 // 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. 143 // so that we can schedule future cache updates.
129 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_; 144 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_;
130 145
131 DISALLOW_COPY_AND_ASSIGN(WebResourceService); 146 DISALLOW_COPY_AND_ASSIGN(WebResourceService);
132 }; 147 };
133 148
134 } // namespace web_resource 149 } // namespace web_resource
135 150
136 #endif // COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ 151 #endif // COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_
OLDNEW
« no previous file with comments | « components/web_resource/BUILD.gn ('k') | components/web_resource/web_resource_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698