Changeset 219203 in webkit
- Timestamp:
- Jul 6, 2017 10:23:07 AM (7 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r219195 r219203 1 2017-07-06 Chris Dumez <cdumez@apple.com> 2 3 WebResourceLoadStatisticsStore should only be constructed when the feature is enabled 4 https://bugs.webkit.org/show_bug.cgi?id=174189 5 6 Reviewed by Brent Fulgham. 7 8 Delay the construction of the WebResourceLoadStatisticsStore until the feature gets 9 enabled via WebsiteDataStore::setResourceLoadStatisticsEnabled(). Previously, we would 10 always construct a store and then have a boolean on the store to indicate if it is 11 enabled or not. 12 13 Also simplify the initialization process of the WebResourceLoadStatisticsStore, we 14 used to have: 15 1. WebResourceLoadStatisticsStore constructor 16 2. WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver() 17 3. WebResourceLoadStatisticsStore::setResourceLoadStatisticsEnabled(true) 18 19 All 3 steps are now taken care of by the WebResourceLoadStatisticsStore constructor. 20 21 * UIProcess/Cocoa/WebProcessPoolCocoa.mm: 22 (WebKit::WebProcessPool::platformInitialize): 23 * UIProcess/WebResourceLoadStatisticsStore.cpp: 24 (WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore): 25 (WebKit::WebResourceLoadStatisticsStore::readDataFromDiskIfNeeded): 26 * UIProcess/WebResourceLoadStatisticsStore.h: 27 * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm: 28 (WebKit::WebsiteDataStore::platformInitialize): 29 * UIProcess/WebsiteData/WebsiteDataStore.cpp: 30 (WebKit::WebsiteDataStore::WebsiteDataStore): 31 (WebKit::WebsiteDataStore::resourceLoadStatisticsEnabled): 32 (WebKit::WebsiteDataStore::setResourceLoadStatisticsEnabled): 33 * UIProcess/WebsiteData/WebsiteDataStore.h: 34 (WebKit::WebsiteDataStore::resourceLoadStatistics): 35 * UIProcess/wpe/WebProcessPoolWPE.cpp: 36 (WebKit::WebProcessPool::platformInitialize): 37 1 38 2017-07-06 Claudio Saavedra <csaavedra@igalia.com> 2 39 -
trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm
r219050 r219203 149 149 150 150 setLegacyCustomProtocolManagerClient(std::make_unique<LegacyCustomProtocolManagerClient>()); 151 152 m_websiteDataStore->websiteDataStore().registerSharedResourceLoadObserver();153 151 } 154 152 -
trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp
r219144 r219203 88 88 } 89 89 90 Ref<WebResourceLoadStatisticsStore> WebResourceLoadStatisticsStore::create(const String& resourceLoadStatisticsDirectory) 91 { 92 return adoptRef(*new WebResourceLoadStatisticsStore(resourceLoadStatisticsDirectory)); 93 } 94 95 WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(const String& resourceLoadStatisticsDirectory) 90 WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(const String& resourceLoadStatisticsDirectory, UpdatePartitionCookiesForDomainsHandler&& updatePartitionCookiesForDomainsHandler) 96 91 : m_resourceLoadStatisticsStore(ResourceLoadStatisticsStore::create()) 97 92 , m_statisticsQueue(WorkQueue::create("WebResourceLoadStatisticsStore Process Data Queue", WorkQueue::Type::Serial, WorkQueue::QOS::Utility)) … … 100 95 , m_telemetryRepeatedTimer(RunLoop::main(), this, &WebResourceLoadStatisticsStore::telemetryTimerFired) 101 96 { 97 ASSERT(RunLoop::isMain()); 98 99 #if PLATFORM(COCOA) 100 registerUserDefaultsIfNeeded(); 101 #endif 102 103 m_resourceLoadStatisticsStore->setNotificationCallback([this, protectedThis = makeRef(*this)] { 104 if (m_resourceLoadStatisticsStore->isEmpty()) 105 return; 106 processStatisticsAndDataRecords(); 107 }); 108 m_resourceLoadStatisticsStore->setWritePersistentStoreCallback([this, protectedThis = makeRef(*this)] { 109 m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] { 110 stopMonitoringStatisticsStorage(); 111 writeStoreToDisk(); 112 startMonitoringStatisticsStorage(); 113 }); 114 }); 115 m_resourceLoadStatisticsStore->setGrandfatherExistingWebsiteDataCallback([this, protectedThis = makeRef(*this)] { 116 grandfatherExistingWebsiteData(); 117 }); 118 m_resourceLoadStatisticsStore->setDeletePersistentStoreCallback([this, protectedThis = makeRef(*this)] { 119 m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] { 120 deleteStoreFromDisk(); 121 }); 122 }); 123 m_resourceLoadStatisticsStore->setFireTelemetryCallback([this, protectedThis = makeRef(*this)] { 124 submitTelemetry(); 125 }); 126 127 if (updatePartitionCookiesForDomainsHandler) { 128 m_resourceLoadStatisticsStore->setShouldPartitionCookiesCallback([updatePartitionCookiesForDomainsHandler = WTFMove(updatePartitionCookiesForDomainsHandler)] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst) { 129 updatePartitionCookiesForDomainsHandler(domainsToRemove, domainsToAdd, shouldClearFirst); 130 }); 131 } 132 133 m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] { 134 readDataFromDiskIfNeeded(); 135 startMonitoringStatisticsStorage(); 136 }); 137 102 138 m_telemetryOneShotTimer.startOneShot(5_s); 103 139 m_telemetryRepeatedTimer.startRepeating(24_h); … … 187 223 } 188 224 189 void WebResourceLoadStatisticsStore::setResourceLoadStatisticsEnabled(bool enabled)190 {191 ASSERT(RunLoop::isMain());192 193 if (enabled == m_resourceLoadStatisticsEnabled)194 return;195 196 m_resourceLoadStatisticsEnabled = enabled;197 198 if (m_resourceLoadStatisticsEnabled) {199 readDataFromDiskIfNeeded();200 m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {201 startMonitoringStatisticsStorage();202 });203 } else204 m_statisticsQueue->dispatch([statisticsStorageMonitor = WTFMove(m_statisticsStorageMonitor)] { });205 }206 207 bool WebResourceLoadStatisticsStore::resourceLoadStatisticsEnabled() const208 {209 return m_resourceLoadStatisticsEnabled;210 }211 212 void WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver()213 {214 ASSERT(RunLoop::isMain());215 216 m_resourceLoadStatisticsStore->setNotificationCallback([this, protectedThis = makeRef(*this)] {217 if (m_resourceLoadStatisticsStore->isEmpty())218 return;219 processStatisticsAndDataRecords();220 });221 m_resourceLoadStatisticsStore->setWritePersistentStoreCallback([this, protectedThis = makeRef(*this)] {222 m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] {223 stopMonitoringStatisticsStorage();224 writeStoreToDisk();225 startMonitoringStatisticsStorage();226 });227 });228 m_resourceLoadStatisticsStore->setGrandfatherExistingWebsiteDataCallback([this, protectedThis = makeRef(*this)] {229 grandfatherExistingWebsiteData();230 });231 m_resourceLoadStatisticsStore->setDeletePersistentStoreCallback([this, protectedThis = makeRef(*this)] {232 m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] {233 deleteStoreFromDisk();234 });235 });236 m_resourceLoadStatisticsStore->setFireTelemetryCallback([this, protectedThis = makeRef(*this)] {237 submitTelemetry();238 });239 240 #if PLATFORM(COCOA)241 registerUserDefaultsIfNeeded();242 #endif243 }244 245 void WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&& shouldPartitionCookiesForDomainsHandler)246 {247 ASSERT(RunLoop::isMain());248 249 registerSharedResourceLoadObserver();250 m_resourceLoadStatisticsStore->setShouldPartitionCookiesCallback([shouldPartitionCookiesForDomainsHandler = WTFMove(shouldPartitionCookiesForDomainsHandler)] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst) {251 shouldPartitionCookiesForDomainsHandler(domainsToRemove, domainsToAdd, clearFirst);252 });253 }254 255 225 void WebResourceLoadStatisticsStore::grandfatherExistingWebsiteData() 256 226 { … … 283 253 void WebResourceLoadStatisticsStore::readDataFromDiskIfNeeded() 284 254 { 285 if (!m_resourceLoadStatisticsEnabled) 286 return; 287 288 m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] { 289 String resourceLog = persistentStoragePath(ASCIILiteral("full_browsing_session")); 290 if (resourceLog.isEmpty() || !fileExists(resourceLog)) { 291 grandfatherExistingWebsiteData(); 292 return; 293 } 294 295 if (!hasStatisticsFileChangedSinceLastSync(resourceLog)) { 296 // No need to grandfather in this case. 297 return; 298 } 299 300 WallTime readTime = WallTime::now(); 301 302 auto decoder = createDecoderFromDisk(resourceLog); 303 if (!decoder) { 304 grandfatherExistingWebsiteData(); 305 return; 306 } 307 308 coreStore().clearInMemory(); 309 coreStore().readDataFromDecoder(*decoder); 310 311 m_lastStatisticsFileSyncTime = readTime; 312 313 if (coreStore().isEmpty()) 314 grandfatherExistingWebsiteData(); 315 }); 255 ASSERT(!RunLoop::isMain()); 256 257 String resourceLog = persistentStoragePath(ASCIILiteral("full_browsing_session")); 258 if (resourceLog.isEmpty() || !fileExists(resourceLog)) { 259 grandfatherExistingWebsiteData(); 260 return; 261 } 262 263 if (!hasStatisticsFileChangedSinceLastSync(resourceLog)) { 264 // No need to grandfather in this case. 265 return; 266 } 267 268 WallTime readTime = WallTime::now(); 269 270 auto decoder = createDecoderFromDisk(resourceLog); 271 if (!decoder) { 272 grandfatherExistingWebsiteData(); 273 return; 274 } 275 276 coreStore().clearInMemory(); 277 coreStore().readDataFromDecoder(*decoder); 278 279 m_lastStatisticsFileSyncTime = readTime; 280 281 if (coreStore().isEmpty()) 282 grandfatherExistingWebsiteData(); 316 283 } 317 284 -
trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h
r219144 r219203 58 58 class WebResourceLoadStatisticsStore final : public IPC::Connection::WorkQueueMessageReceiver { 59 59 public: 60 static Ref<WebResourceLoadStatisticsStore> create(const String&); 60 using UpdatePartitionCookiesForDomainsHandler = WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst)>; 61 static Ref<WebResourceLoadStatisticsStore> create(const String& resourceLoadStatisticsDirectory, UpdatePartitionCookiesForDomainsHandler&& updatePartitionCookiesForDomainsHandler = { }) 62 { 63 return adoptRef(*new WebResourceLoadStatisticsStore(resourceLoadStatisticsDirectory, WTFMove(updatePartitionCookiesForDomainsHandler))); 64 } 65 61 66 static void setNotifyPagesWhenDataRecordsWereScanned(bool); 62 67 static void setShouldClassifyResourcesBeforeDataRecordsRemoval(bool); 63 68 static void setShouldSubmitTelemetry(bool); 64 69 virtual ~WebResourceLoadStatisticsStore(); 65 66 void setResourceLoadStatisticsEnabled(bool); 67 bool resourceLoadStatisticsEnabled() const; 68 void registerSharedResourceLoadObserver(); 69 void registerSharedResourceLoadObserver(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&& shouldPartitionCookiesForDomainsHandler); 70 70 71 71 void resourceLoadStatisticsUpdated(const Vector<WebCore::ResourceLoadStatistics>& origins); 72 72 … … 74 74 void processDidCloseConnection(WebProcessProxy&, IPC::Connection&); 75 75 void applicationWillTerminate(); 76 77 void readDataFromDiskIfNeeded();78 76 79 77 void logUserInteraction(const WebCore::URL&); … … 103 101 104 102 private: 105 explicit WebResourceLoadStatisticsStore(const String&);103 WebResourceLoadStatisticsStore(const String&, UpdatePartitionCookiesForDomainsHandler&&); 106 104 107 105 ResourceLoadStatisticsStore& coreStore() { return m_resourceLoadStatisticsStore.get(); } … … 109 107 110 108 void processStatisticsAndDataRecords(); 109 void readDataFromDiskIfNeeded(); 111 110 112 111 void classifyResource(WebCore::ResourceLoadStatistics&); … … 149 148 String m_statisticsStoragePath; 150 149 WTF::WallTime m_lastStatisticsFileSyncTime; 151 bool m_resourceLoadStatisticsEnabled { false };152 150 RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryOneShotTimer; 153 151 RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryRepeatedTimer; -
trunk/Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm
r219052 r219203 104 104 ASSERT(!dataStoresWithStorageManagers().contains(this)); 105 105 dataStoresWithStorageManagers().append(this); 106 if (m_resourceLoadStatistics)107 m_resourceLoadStatistics->readDataFromDiskIfNeeded();108 106 } 109 107 -
trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp
r219161 r219203 77 77 , m_configuration(WTFMove(configuration)) 78 78 , m_storageManager(StorageManager::create(m_configuration.localStorageDirectory)) 79 , m_resourceLoadStatistics(WebResourceLoadStatisticsStore::create(m_configuration.resourceLoadStatisticsDirectory))80 79 , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore")) 81 80 { … … 1255 1254 bool WebsiteDataStore::resourceLoadStatisticsEnabled() const 1256 1255 { 1257 return m_resourceLoadStatistics ? m_resourceLoadStatistics->resourceLoadStatisticsEnabled() : false;1256 return !!m_resourceLoadStatistics; 1258 1257 } 1259 1258 1260 1259 void WebsiteDataStore::setResourceLoadStatisticsEnabled(bool enabled) 1261 1260 { 1262 if (!m_resourceLoadStatistics)1263 return;1264 1265 1261 if (enabled == resourceLoadStatisticsEnabled()) 1266 1262 return; 1267 1263 1268 // FIXME: We should probably only initialize m_resourceLoadStatistics when resource load statistics get enabled. 1269 m_resourceLoadStatistics->setResourceLoadStatisticsEnabled(enabled); 1264 if (enabled) { 1265 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) 1266 m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(m_configuration.resourceLoadStatisticsDirectory, [this] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst) { 1267 updateCookiePartitioningForTopPrivatelyOwnedDomains(domainsToRemove, domainsToAdd, shouldClearFirst); 1268 }); 1269 #else 1270 m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(m_configuration.resourceLoadStatisticsDirectory); 1271 #endif 1272 } else 1273 m_resourceLoadStatistics = nullptr; 1270 1274 1271 1275 for (auto& processPool : processPools()) 1272 1276 processPool->setResourceLoadStatisticsEnabled(enabled); 1273 }1274 1275 void WebsiteDataStore::registerSharedResourceLoadObserver()1276 {1277 if (!m_resourceLoadStatistics)1278 return;1279 1280 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)1281 m_resourceLoadStatistics->registerSharedResourceLoadObserver([this] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst) {1282 updateCookiePartitioningForTopPrivatelyOwnedDomains(domainsToRemove, domainsToAdd, shouldClearFirst);1283 });1284 #else1285 m_resourceLoadStatistics->registerSharedResourceLoadObserver();1286 #endif1287 1277 } 1288 1278 -
trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h
r219161 r219203 91 91 void setResourceLoadStatisticsEnabled(bool); 92 92 WebResourceLoadStatisticsStore* resourceLoadStatistics() const { return m_resourceLoadStatistics.get(); } 93 void registerSharedResourceLoadObserver();94 93 95 94 static void cloneSessionData(WebPageProxy& sourcePage, WebPageProxy& newPage); … … 162 161 163 162 const RefPtr<StorageManager> m_storageManager; 164 constRefPtr<WebResourceLoadStatisticsStore> m_resourceLoadStatistics;163 RefPtr<WebResourceLoadStatisticsStore> m_resourceLoadStatistics; 165 164 166 165 Ref<WorkQueue> m_queue; -
trunk/Source/WebKit2/UIProcess/wpe/WebProcessPoolWPE.cpp
r217924 r219203 76 76 } 77 77 #endif 78 m_websiteDataStore->websiteDataStore().registerSharedResourceLoadObserver();79 78 } 80 79
Note: See TracChangeset
for help on using the changeset viewer.