| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/chromeos/login/merge_session_throttle.h" | 5 #include "chrome/browser/chromeos/login/merge_session_throttle.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
| 23 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
| 24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 25 | 25 |
| 26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 using content::RenderViewHost; | 27 using content::RenderViewHost; |
| 28 using content::WebContents; | 28 using content::WebContents; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 const int kSessionThrottleWindowInSeconds = 10; |
| 33 |
| 32 void ShowDeleayedLoadingPage( | 34 void ShowDeleayedLoadingPage( |
| 33 int render_process_id, | 35 int render_process_id, |
| 34 int render_view_id, | 36 int render_view_id, |
| 35 const GURL& url, | 37 const GURL& url, |
| 36 const chromeos::MergeSessionLoadPage::CompletionCallback& callback) { | 38 const chromeos::MergeSessionLoadPage::CompletionCallback& callback) { |
| 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 38 | 40 |
| 39 // Check again on UI thread and proceed if it's connected. | 41 // Check again on UI thread and proceed if it's connected. |
| 40 if (chromeos::UserManager::Get()->GetMergeSessionState() != | 42 if (chromeos::UserManager::Get()->GetMergeSessionState() != |
| 41 chromeos::UserManager::MERGE_STATUS_IN_PROCESS) { | 43 chromeos::UserManager::MERGE_STATUS_IN_PROCESS) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 62 : render_process_id_(render_process_id), | 64 : render_process_id_(render_process_id), |
| 63 render_view_id_(render_view_id), | 65 render_view_id_(render_view_id), |
| 64 request_(request) { | 66 request_(request) { |
| 65 } | 67 } |
| 66 | 68 |
| 67 MergeSessionThrottle::~MergeSessionThrottle() { | 69 MergeSessionThrottle::~MergeSessionThrottle() { |
| 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 69 } | 71 } |
| 70 | 72 |
| 71 void MergeSessionThrottle::WillStartRequest(bool* defer) { | 73 void MergeSessionThrottle::WillStartRequest(bool* defer) { |
| 72 if (!ShouldShowMergeSessionPage(request_->url())) | 74 if (!ShouldShowMergeSessionPage(request_->url())) { |
| 73 return; | 75 return; |
| 76 } |
| 74 | 77 |
| 75 DVLOG(1) << "WillStartRequest: url=" << request_->url(); | 78 DVLOG(1) << "WillStartRequest: defer " << request_->url(); |
| 76 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
| 77 BrowserThread::UI, | 80 BrowserThread::UI, |
| 78 FROM_HERE, | 81 FROM_HERE, |
| 79 base::Bind( | 82 base::Bind( |
| 80 &ShowDeleayedLoadingPage, | 83 &ShowDeleayedLoadingPage, |
| 81 render_process_id_, | 84 render_process_id_, |
| 82 render_view_id_, | 85 render_view_id_, |
| 83 request_->url(), | 86 request_->url(), |
| 84 base::Bind( | 87 base::Bind( |
| 85 &MergeSessionThrottle::OnBlockingPageComplete, | 88 &MergeSessionThrottle::OnBlockingPageComplete, |
| 86 AsWeakPtr()))); | 89 AsWeakPtr()))); |
| 87 *defer = true; | 90 *defer = true; |
| 88 } | 91 } |
| 89 | 92 |
| 90 void MergeSessionThrottle::OnBlockingPageComplete() { | 93 void MergeSessionThrottle::OnBlockingPageComplete() { |
| 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 92 controller()->Resume(); | 95 controller()->Resume(); |
| 93 } | 96 } |
| 94 | 97 |
| 95 bool MergeSessionThrottle::ShouldShowMergeSessionPage(const GURL& url) const { | 98 bool MergeSessionThrottle::ShouldShowMergeSessionPage(const GURL& url) const { |
| 96 // If we are loading google properties while merge session is in progress, | 99 // If we are loading google properties while merge session is in progress, |
| 97 // we will show delayed loading page instead. | 100 // we will show delayed loading page instead. |
| 101 chromeos::UserManager* manager = chromeos::UserManager::Get(); |
| 102 int64 session_duration = manager->GetSessionDurationInSeconds(); |
| 98 return !net::NetworkChangeNotifier::IsOffline() && | 103 return !net::NetworkChangeNotifier::IsOffline() && |
| 99 chromeos::UserManager::Get()->GetMergeSessionState() == | 104 manager->GetMergeSessionState() == |
| 100 chromeos::UserManager::MERGE_STATUS_IN_PROCESS && | 105 chromeos::UserManager::MERGE_STATUS_IN_PROCESS && |
| 101 google_util::IsGoogleHostname(url.host(), | 106 session_duration >= 0 && |
| 102 google_util::ALLOW_SUBDOMAIN); | 107 session_duration < kSessionThrottleWindowInSeconds && |
| 108 google_util::IsGoogleHostname(url.host(), |
| 109 google_util::ALLOW_SUBDOMAIN); |
| 103 } | 110 } |
| OLD | NEW |