OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/prerender/prerender_manager.h" | 5 #include "chrome/browser/prerender/prerender_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <functional> | 10 #include <functional> |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 using content::WebContents; | 68 using content::WebContents; |
69 using namespace chrome_browser_net; | 69 using namespace chrome_browser_net; |
70 | 70 |
71 namespace prerender { | 71 namespace prerender { |
72 | 72 |
73 namespace { | 73 namespace { |
74 | 74 |
75 // Time interval at which periodic cleanups are performed. | 75 // Time interval at which periodic cleanups are performed. |
76 const int kPeriodicCleanupIntervalMs = 1000; | 76 const int kPeriodicCleanupIntervalMs = 1000; |
77 | 77 |
78 // Valid HTTP methods for prerendering. | |
79 const char* const kValidHttpMethods[] = { | |
80 "GET", | |
81 "HEAD", | |
82 "OPTIONS", | |
83 "POST", | |
84 "TRACE", | |
85 }; | |
86 | |
87 // Length of prerender history, for display in chrome://net-internals | 78 // Length of prerender history, for display in chrome://net-internals |
88 const int kHistoryLength = 100; | 79 const int kHistoryLength = 100; |
89 | 80 |
90 } // namespace | 81 } // namespace |
91 | 82 |
92 class PrerenderManager::OnCloseWebContentsDeleter | 83 class PrerenderManager::OnCloseWebContentsDeleter |
93 : public content::WebContentsDelegate, | 84 : public content::WebContentsDelegate, |
94 public base::SupportsWeakPtr< | 85 public base::SupportsWeakPtr< |
95 PrerenderManager::OnCloseWebContentsDeleter> { | 86 PrerenderManager::OnCloseWebContentsDeleter> { |
96 public: | 87 public: |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 base::TimeDelta delta = GetCurrentTimeTicks() - it->time; | 691 base::TimeDelta delta = GetCurrentTimeTicks() - it->time; |
701 histograms_->RecordTimeSinceLastRecentVisit(origin, delta); | 692 histograms_->RecordTimeSinceLastRecentVisit(origin, delta); |
702 return true; | 693 return true; |
703 } | 694 } |
704 } | 695 } |
705 | 696 |
706 return false; | 697 return false; |
707 } | 698 } |
708 | 699 |
709 // static | 700 // static |
710 bool PrerenderManager::IsValidHttpMethod(const std::string& method) { | |
711 // method has been canonicalized to upper case at this point so we can just | |
712 // compare them. | |
713 DCHECK_EQ(method, base::ToUpperASCII(method)); | |
714 for (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) { | |
715 if (method.compare(kValidHttpMethods[i]) == 0) | |
716 return true; | |
717 } | |
718 | |
719 return false; | |
720 } | |
721 | |
722 // static | |
723 bool PrerenderManager::DoesURLHaveValidScheme(const GURL& url) { | 701 bool PrerenderManager::DoesURLHaveValidScheme(const GURL& url) { |
724 return (url.SchemeIsHTTPOrHTTPS() || | 702 return (url.SchemeIsHTTPOrHTTPS() || |
725 url.SchemeIs(extensions::kExtensionScheme) || | 703 url.SchemeIs(extensions::kExtensionScheme) || |
726 url.SchemeIs("data")); | 704 url.SchemeIs("data")); |
727 } | 705 } |
728 | 706 |
729 // static | 707 // static |
730 bool PrerenderManager::DoesSubresourceURLHaveValidScheme(const GURL& url) { | 708 bool PrerenderManager::DoesSubresourceURLHaveValidScheme(const GURL& url) { |
731 return DoesURLHaveValidScheme(url) || url == GURL(url::kAboutBlankURL); | 709 return DoesURLHaveValidScheme(url) || url == GURL(url::kAboutBlankURL); |
732 } | 710 } |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 DCHECK_EQ(1u, erased); | 1311 DCHECK_EQ(1u, erased); |
1334 } | 1312 } |
1335 | 1313 |
1336 void PrerenderManager::SetPrerenderContentsFactoryForTest( | 1314 void PrerenderManager::SetPrerenderContentsFactoryForTest( |
1337 PrerenderContents::Factory* prerender_contents_factory) { | 1315 PrerenderContents::Factory* prerender_contents_factory) { |
1338 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1316 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1339 prerender_contents_factory_.reset(prerender_contents_factory); | 1317 prerender_contents_factory_.reset(prerender_contents_factory); |
1340 } | 1318 } |
1341 | 1319 |
1342 } // namespace prerender | 1320 } // namespace prerender |
OLD | NEW |