Chromium Code Reviews| Index: chrome/browser/extensions/network_delay_listener.h |
| =================================================================== |
| --- chrome/browser/extensions/network_delay_listener.h (revision 0) |
| +++ chrome/browser/extensions/network_delay_listener.h (revision 0) |
| @@ -0,0 +1,103 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_NETWORK_DELAY_LISTENER_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_NETWORK_DELAY_LISTENER_H_ |
| +#pragma once |
| + |
| +#include <map> |
| +#include <set> |
| + |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/perftimer.h" |
| +#include "base/time.h" |
| +#include "content/browser/renderer_host/resource_queue.h" |
| +#include "content/common/notification_observer.h" |
| +#include "content/common/notification_registrar.h" |
| + |
| +namespace net { |
| +class URLRequest; |
| +} // namespace net |
| + |
| +class Extension; |
| +struct GlobalRequestID; |
| + |
| +// This class handles delaying of resource loads that depend on unloaded |
| +// extensions. For each request that comes in, we check if all extensions are |
| +// ready for it to be loaded; if not, we delay the request. |
| +// |
| +// This class lives mostly on the IO thread. It listens on the UI thread for |
| +// updates to loaded extensions. It will delete itself on the UI thread after |
| +// WillShutdownResourceQueue is called (on the IO thread). |
| +class NetworkDelayListener |
|
Aaron Boodman
2011/10/10 22:59:29
What happens if both this class and UserScriptList
Pam (message me for reviews)
2011/10/12 14:28:12
Yes, the ResourceQueue handles that when both are
|
| + : public base::RefCountedThreadSafe<NetworkDelayListener>, |
| + public ResourceQueueDelegate, |
| + public NotificationObserver { |
| + public: |
| + NetworkDelayListener(); |
| + |
| + // ResourceQueueDelegate: |
|
Aaron Boodman
2011/10/10 22:59:29
You can make these private if you don't intend to
|
| + virtual void Initialize(ResourceQueue* resource_queue) OVERRIDE; |
| + virtual bool ShouldDelayRequest( |
| + net::URLRequest* request, |
| + const ResourceDispatcherHostRequestInfo& request_info, |
| + const GlobalRequestID& request_id) OVERRIDE; |
| + virtual void WillShutdownResourceQueue() OVERRIDE; |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<NetworkDelayListener>; |
| + |
| + virtual ~NetworkDelayListener(); |
| + |
| + // Record that an extension that wants to delay network requests is loading. |
| + void OnExtensionPending(const Extension* extension); |
| + |
| + // Record that an extension that wants to delay network requests is ready. |
| + void OnExtensionReady(const Extension* extension); |
| + |
| + // Resume any requests that we delayed in order to wait for extensions. |
| + void StartDelayedRequests(); |
| + |
| + // Cleanup on UI thread. |
| + void Cleanup(); |
| + |
| + // Used to measure how long each extension has taken to become ready. |
| + std::map<std::string, base::TimeTicks> delay_start_times_; |
| + |
| + // Used to measure total time between the first delay request and resuming |
| + // network requests. |
| + PerfTimer overall_start_time_; |
| + |
| + // Whether we've already calculated total startup time, so we don't corrupt |
| + // the data with entries from installing or enabling single extensions. |
| + bool recorded_startup_delay_; |
| + |
| + ResourceQueue* resource_queue_; |
| + |
| + // TODO(mpcomplete, pamg): the rest of this stuff should really be |
| + // per-profile, but the complexity doesn't seem worth it at this point. |
| + |
| + // True if the extensions are ready for network requests to proceed. In |
| + // practice this means that the background pages of any pending extensions |
| + // have been run. |
| + bool extensions_ready_; |
| + |
| + // Which extension IDs have registered to delay network requests on startup, |
| + // but are not yet ready for them to resume. |
| + std::set<std::string> pending_extensions_; |
| + |
| + // --- UI thread: |
| + |
| + // NotificationObserver |
| + virtual void Observe(int type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details) OVERRIDE; |
| + |
| + NotificationRegistrar registrar_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NetworkDelayListener); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_NETWORK_DELAY_LISTENER_H_ |
| Property changes on: chrome\browser\extensions\network_delay_listener.h |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |