| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/browser_instant_controller.h" | 5 #include "chrome/browser/ui/browser_instant_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/user_metrics.h" | 8 #include "base/metrics/user_metrics.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 // Helpers -------------------------------------------------------------------- | 33 // Helpers -------------------------------------------------------------------- |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // Helper class for posting a task to reload a tab, to avoid doing a re-entrant | 37 // Helper class for posting a task to reload a tab, to avoid doing a re-entrant |
| 38 // navigation, since it can be called when starting a navigation. This class | 38 // navigation, since it can be called when starting a navigation. This class |
| 39 // makes sure to only execute the reload if the WebContents still exists. | 39 // makes sure to only execute the reload if the WebContents still exists. |
| 40 class TabReloader : public content::WebContentsUserData<TabReloader> { | 40 class TabReloader : public content::WebContentsUserData<TabReloader> { |
| 41 public: | 41 public: |
| 42 ~TabReloader() override {} |
| 43 |
| 42 static void Reload(content::WebContents* web_contents) { | 44 static void Reload(content::WebContents* web_contents) { |
| 43 TabReloader::CreateForWebContents(web_contents); | 45 TabReloader::CreateForWebContents(web_contents); |
| 44 } | 46 } |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 friend class content::WebContentsUserData<TabReloader>; | 49 friend class content::WebContentsUserData<TabReloader>; |
| 48 | 50 |
| 49 explicit TabReloader(content::WebContents* web_contents) | 51 explicit TabReloader(content::WebContents* web_contents) |
| 50 : web_contents_(web_contents), weak_ptr_factory_(this) { | 52 : web_contents_(web_contents), weak_ptr_factory_(this) { |
| 51 content::BrowserThread::PostTask( | 53 content::BrowserThread::PostTask( |
| 52 content::BrowserThread::UI, FROM_HERE, | 54 content::BrowserThread::UI, FROM_HERE, |
| 53 base::BindOnce(&TabReloader::ReloadImpl, | 55 base::BindOnce(&TabReloader::ReloadImpl, |
| 54 weak_ptr_factory_.GetWeakPtr())); | 56 weak_ptr_factory_.GetWeakPtr())); |
| 55 } | 57 } |
| 56 ~TabReloader() override {} | |
| 57 | 58 |
| 58 void ReloadImpl() { | 59 void ReloadImpl() { |
| 59 web_contents_->GetController().Reload(content::ReloadType::NORMAL, false); | 60 web_contents_->GetController().Reload(content::ReloadType::NORMAL, false); |
| 60 | 61 |
| 61 // As the reload was not triggered by the user we don't want to close any | 62 // As the reload was not triggered by the user we don't want to close any |
| 62 // infobars. We have to tell the InfoBarService after the reload, | 63 // infobars. We have to tell the InfoBarService after the reload, |
| 63 // otherwise it would ignore this call when | 64 // otherwise it would ignore this call when |
| 64 // WebContentsObserver::DidStartNavigationToPendingEntry is invoked. | 65 // WebContentsObserver::DidStartNavigationToPendingEntry is invoked. |
| 65 InfoBarService::FromWebContents(web_contents_)->set_ignore_next_reload(); | 66 InfoBarService::FromWebContents(web_contents_)->set_ignore_next_reload(); |
| 66 | 67 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 params.referrer = content::Referrer(); | 196 params.referrer = content::Referrer(); |
| 196 params.transition_type = ui::PAGE_TRANSITION_RELOAD; | 197 params.transition_type = ui::PAGE_TRANSITION_RELOAD; |
| 197 contents->GetController().LoadURLWithParams(params); | 198 contents->GetController().LoadURLWithParams(params); |
| 198 } else { | 199 } else { |
| 199 // Reload the contents to ensure that it gets assigned to a | 200 // Reload the contents to ensure that it gets assigned to a |
| 200 // non-privileged renderer. | 201 // non-privileged renderer. |
| 201 TabReloader::Reload(contents); | 202 TabReloader::Reload(contents); |
| 202 } | 203 } |
| 203 } | 204 } |
| 204 } | 205 } |
| OLD | NEW |