NetworkResourceLoadScheduler.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2012 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef NetworkResourceLoadScheduler_h
  26. #define NetworkResourceLoadScheduler_h
  27. #include <WebCore/ResourceLoadPriority.h>
  28. #include <WebCore/Timer.h>
  29. #include <wtf/HashMap.h>
  30. #include <wtf/HashSet.h>
  31. #include <wtf/text/StringHash.h>
  32. #if ENABLE(NETWORK_PROCESS)
  33. namespace WebCore {
  34. class KURL;
  35. }
  36. namespace WebKit {
  37. class HostRecord;
  38. class NetworkResourceLoader;
  39. class NetworkResourceLoadScheduler {
  40. WTF_MAKE_NONCOPYABLE(NetworkResourceLoadScheduler); WTF_MAKE_FAST_ALLOCATED;
  41. public:
  42. NetworkResourceLoadScheduler();
  43. // Adds the request to the queue for its host.
  44. void scheduleLoader(PassRefPtr<NetworkResourceLoader>);
  45. // Called by the WebProcess when a ResourceLoader is being cleaned up.
  46. void removeLoader(NetworkResourceLoader*);
  47. // Called within the NetworkProcess on a background thread when a resource load has finished.
  48. void scheduleRemoveLoader(NetworkResourceLoader*);
  49. void receivedRedirect(NetworkResourceLoader*, const WebCore::KURL& redirectURL);
  50. void servePendingRequests(WebCore::ResourceLoadPriority = WebCore::ResourceLoadPriorityVeryLow);
  51. // For NetworkProcess statistics reporting.
  52. uint64_t hostsPendingCount() const;
  53. uint64_t loadsPendingCount() const;
  54. uint64_t hostsActiveCount() const;
  55. uint64_t loadsActiveCount() const;
  56. private:
  57. enum CreateHostPolicy {
  58. CreateIfNotFound,
  59. FindOnly
  60. };
  61. HostRecord* hostForURL(const WebCore::KURL&, CreateHostPolicy = FindOnly);
  62. void scheduleServePendingRequests();
  63. void requestTimerFired(WebCore::Timer<NetworkResourceLoadScheduler>*);
  64. void platformInitializeMaximumHTTPConnectionCountPerHost();
  65. static void removeScheduledLoaders(void* context);
  66. void removeScheduledLoaders();
  67. typedef HashMap<String, RefPtr<HostRecord>, StringHash> HostMap;
  68. HostMap m_hosts;
  69. typedef HashSet<RefPtr<NetworkResourceLoader>> NetworkResourceLoaderSet;
  70. NetworkResourceLoaderSet m_loaders;
  71. RefPtr<HostRecord> m_nonHTTPProtocolHost;
  72. bool m_isSerialLoadingEnabled;
  73. WebCore::Timer<NetworkResourceLoadScheduler> m_requestTimer;
  74. Mutex m_loadersToRemoveMutex;
  75. Vector<RefPtr<NetworkResourceLoader>> m_loadersToRemove;
  76. unsigned m_maxRequestsInFlightPerHost;
  77. };
  78. } // namespace WebKit
  79. #endif // ENABLE(NETWORK_PROCESS)
  80. #endif // NetworkResourceLoadScheduler_h