| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP || | 128 GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP || |
| 129 GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; | 129 GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; |
| 130 } | 130 } |
| 131 | 131 |
| 132 // static | 132 // static |
| 133 bool PrerenderManager::IsControlGroup() { | 133 bool PrerenderManager::IsControlGroup() { |
| 134 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; | 134 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; |
| 135 } | 135 } |
| 136 | 136 |
| 137 // static | 137 // static |
| 138 bool PrerenderManager::IsNoUseGroup() { |
| 139 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; |
| 140 } |
| 141 |
| 142 // static |
| 138 bool PrerenderManager::IsValidHttpMethod(const std::string& method) { | 143 bool PrerenderManager::IsValidHttpMethod(const std::string& method) { |
| 139 // method has been canonicalized to upper case at this point so we can just | 144 // method has been canonicalized to upper case at this point so we can just |
| 140 // compare them. | 145 // compare them. |
| 141 DCHECK_EQ(method, StringToUpperASCII(method)); | 146 DCHECK_EQ(method, StringToUpperASCII(method)); |
| 142 for (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) { | 147 for (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) { |
| 143 if (method.compare(kValidHttpMethods[i]) == 0) | 148 if (method.compare(kValidHttpMethods[i]) == 0) |
| 144 return true; | 149 return true; |
| 145 } | 150 } |
| 146 | 151 |
| 147 return false; | 152 return false; |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 dict_value->SetString("omnibox_heuristic", "(exact)"); | 988 dict_value->SetString("omnibox_heuristic", "(exact)"); |
| 984 break; | 989 break; |
| 985 default: | 990 default: |
| 986 NOTREACHED(); | 991 NOTREACHED(); |
| 987 break; | 992 break; |
| 988 } | 993 } |
| 989 } | 994 } |
| 990 // If prerender is disabled via a flag this method is not even called. | 995 // If prerender is disabled via a flag this method is not even called. |
| 991 if (IsControlGroup()) | 996 if (IsControlGroup()) |
| 992 dict_value->SetString("disabled_reason", "(Disabled for testing)"); | 997 dict_value->SetString("disabled_reason", "(Disabled for testing)"); |
| 998 if (IsNoUseGroup()) |
| 999 dict_value->SetString("disabled_reason", "(Not using prerendered pages)"); |
| 993 return dict_value; | 1000 return dict_value; |
| 994 } | 1001 } |
| 995 | 1002 |
| 996 void PrerenderManager::ClearData(int clear_flags) { | 1003 void PrerenderManager::ClearData(int clear_flags) { |
| 997 DCHECK_GE(clear_flags, 0); | 1004 DCHECK_GE(clear_flags, 0); |
| 998 DCHECK_LT(clear_flags, CLEAR_MAX); | 1005 DCHECK_LT(clear_flags, CLEAR_MAX); |
| 999 if (clear_flags & CLEAR_PRERENDER_CONTENTS) | 1006 if (clear_flags & CLEAR_PRERENDER_CONTENTS) |
| 1000 DestroyAllContents(FINAL_STATUS_CACHE_OR_HISTORY_CLEARED); | 1007 DestroyAllContents(FINAL_STATUS_CACHE_OR_HISTORY_CLEARED); |
| 1001 // This has to be second, since destroying prerenders can add to the history. | 1008 // This has to be second, since destroying prerenders can add to the history. |
| 1002 if (clear_flags & CLEAR_PRERENDER_HISTORY) | 1009 if (clear_flags & CLEAR_PRERENDER_HISTORY) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 if (!render_process_host || !render_process_host->browser_context()) | 1066 if (!render_process_host || !render_process_host->browser_context()) |
| 1060 return NULL; | 1067 return NULL; |
| 1061 Profile* profile = Profile::FromBrowserContext( | 1068 Profile* profile = Profile::FromBrowserContext( |
| 1062 render_process_host->browser_context()); | 1069 render_process_host->browser_context()); |
| 1063 if (!profile) | 1070 if (!profile) |
| 1064 return NULL; | 1071 return NULL; |
| 1065 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1072 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
| 1066 } | 1073 } |
| 1067 | 1074 |
| 1068 } // namespace prerender | 1075 } // namespace prerender |
| OLD | NEW |