| 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_local_predictor.h" | 5 #include "chrome/browser/prerender/prerender_local_predictor.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/timer.h" | 17 #include "base/timer.h" |
| 18 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/history/history_database.h" | 19 #include "chrome/browser/history/history_database.h" |
| 19 #include "chrome/browser/history/history_db_task.h" | 20 #include "chrome/browser/history/history_db_task.h" |
| 20 #include "chrome/browser/history/history_service.h" | 21 #include "chrome/browser/history/history_service.h" |
| 21 #include "chrome/browser/history/history_service_factory.h" | 22 #include "chrome/browser/history/history_service_factory.h" |
| 22 #include "chrome/browser/prerender/prerender_handle.h" | 23 #include "chrome/browser/prerender/prerender_handle.h" |
| 23 #include "chrome/browser/prerender/prerender_histograms.h" | 24 #include "chrome/browser/prerender/prerender_histograms.h" |
| 24 #include "chrome/browser/prerender/prerender_manager.h" | 25 #include "chrome/browser/prerender/prerender_manager.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/safe_browsing/database_manager.h" |
| 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 26 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 29 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 27 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/navigation_controller.h" | 31 #include "content/public/browser/navigation_controller.h" |
| 29 #include "content/public/browser/session_storage_namespace.h" | 32 #include "content/public/browser/session_storage_namespace.h" |
| 30 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/browser/web_contents_view.h" | 34 #include "content/public/browser/web_contents_view.h" |
| 32 #include "content/public/common/page_transition_types.h" | 35 #include "content/public/common/page_transition_types.h" |
| 33 #include "crypto/secure_hash.h" | 36 #include "crypto/secure_hash.h" |
| 34 #include "googleurl/src/url_canon.h" | 37 #include "googleurl/src/url_canon.h" |
| 35 #include "grit/browser_resources.h" | 38 #include "grit/browser_resources.h" |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 !prerender_handle_->IsPrerendering() || | 658 !prerender_handle_->IsPrerendering() || |
| 656 current_prerender_priority_ < priority); | 659 current_prerender_priority_ < priority); |
| 657 } | 660 } |
| 658 | 661 |
| 659 void PrerenderLocalPredictor::ContinuePrerenderCheck( | 662 void PrerenderLocalPredictor::ContinuePrerenderCheck( |
| 660 scoped_refptr<SessionStorageNamespace> session_storage_namespace, | 663 scoped_refptr<SessionStorageNamespace> session_storage_namespace, |
| 661 scoped_ptr<gfx::Size> size, | 664 scoped_ptr<gfx::Size> size, |
| 662 scoped_ptr<LocalPredictorURLLookupInfo> info) { | 665 scoped_ptr<LocalPredictorURLLookupInfo> info) { |
| 663 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_STARTED); | 666 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_STARTED); |
| 664 scoped_ptr<LocalPredictorURLInfo> url_info; | 667 scoped_ptr<LocalPredictorURLInfo> url_info; |
| 668 scoped_refptr<SafeBrowsingDatabaseManager> sb_db_manager = |
| 669 g_browser_process->safe_browsing_service()->database_manager(); |
| 670 |
| 665 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { | 671 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { |
| 666 url_info.reset(new LocalPredictorURLInfo(info->candidate_urls_[i])); | 672 url_info.reset(new LocalPredictorURLInfo(info->candidate_urls_[i])); |
| 667 | 673 |
| 668 // We need to check whether we can issue a prerender for this URL. | 674 // We need to check whether we can issue a prerender for this URL. |
| 669 // We test a set of conditions. Each condition can either rule out | 675 // We test a set of conditions. Each condition can either rule out |
| 670 // a prerender (in which case we reset url_info, so that it will not | 676 // a prerender (in which case we reset url_info, so that it will not |
| 671 // be prerendered, and we continue, which means try the next candidate | 677 // be prerendered, and we continue, which means try the next candidate |
| 672 // URL), or it can be sufficient to issue the prerender without any | 678 // URL), or it can be sufficient to issue the prerender without any |
| 673 // further checks (in which case we just break). | 679 // further checks (in which case we just break). |
| 674 // The order of the checks is critical, because it prescribes the logic | 680 // The order of the checks is critical, because it prescribes the logic |
| (...skipping 28 matching lines...) Expand all Loading... |
| 703 if (IsLogOutURL(url_info->url)) { | 709 if (IsLogOutURL(url_info->url)) { |
| 704 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGOUT_URL); | 710 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGOUT_URL); |
| 705 url_info.reset(NULL); | 711 url_info.reset(NULL); |
| 706 continue; | 712 continue; |
| 707 } | 713 } |
| 708 if (IsLogInURL(url_info->url)) { | 714 if (IsLogInURL(url_info->url)) { |
| 709 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGIN_URL); | 715 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGIN_URL); |
| 710 url_info.reset(NULL); | 716 url_info.reset(NULL); |
| 711 continue; | 717 continue; |
| 712 } | 718 } |
| 719 if (sb_db_manager->CheckSideEffectFreeWhitelistUrl(url_info->url)) { |
| 720 // If a page is on the side-effect free whitelist, we will just prerender |
| 721 // it without any additional checks. |
| 722 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ON_SIDE_EFFECT_FREE_WHITELIST); |
| 723 break; |
| 724 } |
| 713 if (!url_info->logged_in && url_info->logged_in_lookup_ok) { | 725 if (!url_info->logged_in && url_info->logged_in_lookup_ok) { |
| 714 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NOT_LOGGED_IN); | 726 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NOT_LOGGED_IN); |
| 715 break; | 727 break; |
| 716 } | 728 } |
| 717 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_NOT_PRERENDERING); | 729 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_NOT_PRERENDERING); |
| 718 url_info.reset(NULL); | 730 url_info.reset(NULL); |
| 719 } | 731 } |
| 720 if (!url_info.get()) | 732 if (!url_info.get()) |
| 721 return; | 733 return; |
| 722 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ISSUING_PRERENDER); | 734 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ISSUING_PRERENDER); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 // If the namespace matches and the URL matches, we might be able to swap | 795 // If the namespace matches and the URL matches, we might be able to swap |
| 784 // in. However, the actual code initating the swapin is in the renderer | 796 // in. However, the actual code initating the swapin is in the renderer |
| 785 // and is checking for other criteria (such as POSTs). There may | 797 // and is checking for other criteria (such as POSTs). There may |
| 786 // also be conditions when a swapin should happen but does not. By recording | 798 // also be conditions when a swapin should happen but does not. By recording |
| 787 // the two previous events, we can keep an eye on the magnitude of the | 799 // the two previous events, we can keep an eye on the magnitude of the |
| 788 // discrepancy. | 800 // discrepancy. |
| 789 current_prerender_would_have_matched_ = true; | 801 current_prerender_would_have_matched_ = true; |
| 790 } | 802 } |
| 791 | 803 |
| 792 } // namespace prerender | 804 } // namespace prerender |
| OLD | NEW |