Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/merge_session_throttle.h" | |
| 6 | |
| 7 #include <vector> | |
|
oshima
2013/02/16 00:05:23
nit: this isn't necessary?
zel
2013/02/16 00:56:28
Done.
| |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/singleton.h" | |
| 12 #include "base/metrics/histogram.h" | |
| 13 #include "base/string_util.h" | |
| 14 #include "chrome/browser/chromeos/login/login_utils.h" | |
| 15 #include "chrome/browser/google/google_util.h" | |
| 16 #include "chrome/browser/net/chrome_url_request_context.h" | |
| 17 #include "chrome/common/url_constants.h" | |
| 18 #include "content/public/browser/browser_thread.h" | |
| 19 #include "content/public/browser/render_view_host.h" | |
| 20 #include "content/public/browser/resource_controller.h" | |
| 21 #include "content/public/browser/web_contents.h" | |
| 22 #include "net/base/net_errors.h" | |
| 23 #include "net/base/net_util.h" | |
| 24 #include "net/base/network_change_notifier.h" | |
| 25 #include "net/url_request/url_request.h" | |
| 26 #include "net/url_request/url_request_context.h" | |
| 27 | |
| 28 using content::BrowserThread; | |
| 29 using content::RenderViewHost; | |
| 30 using content::WebContents; | |
| 31 | |
| 32 namespace { | |
| 33 | |
| 34 void ShowDeleayedLoadingPage( | |
| 35 int render_process_id, | |
| 36 int render_view_id, | |
| 37 const GURL& url, | |
| 38 const chromeos::MergeSessionLoadPage::CompletionCallback& callback) { | |
| 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 40 | |
| 41 // Check again on UI thread and proceed if it's connected. | |
| 42 if (chromeos::UserManager::Get()->GetMergeSessionState() != | |
| 43 chromeos::UserManager::MERGE_STATUS_IN_PROCESS) { | |
| 44 BrowserThread::PostTask( | |
| 45 BrowserThread::IO, FROM_HERE, callback); | |
| 46 } else { | |
| 47 RenderViewHost* render_view_host = | |
| 48 RenderViewHost::FromID(render_process_id, render_view_id); | |
| 49 WebContents* web_contents = render_view_host ? | |
| 50 WebContents::FromRenderViewHost(render_view_host) : NULL; | |
| 51 // There is a chance that the tab closed after we decided to show | |
| 52 // the offline page on the IO thread and before we actually show the | |
| 53 // offline page here on the UI thread. | |
| 54 if (web_contents) | |
| 55 (new chromeos::MergeSessionLoadPage(web_contents, url, callback))->Show(); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 61 MergeSessionThrottle::MergeSessionThrottle(int render_process_id, | |
| 62 int render_view_id, | |
| 63 net::URLRequest* request) | |
| 64 : render_process_id_(render_process_id), | |
| 65 render_view_id_(render_view_id), | |
| 66 request_(request) { | |
| 67 } | |
| 68 | |
| 69 MergeSessionThrottle::~MergeSessionThrottle() { | |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 71 } | |
| 72 | |
| 73 void MergeSessionThrottle::WillStartRequest(bool* defer) { | |
| 74 if (!ShouldShowMergeSessionPage(request_->url())) | |
| 75 return; | |
| 76 | |
| 77 DVLOG(1) << "WillStartRequest: url=" << request_->url(); | |
| 78 BrowserThread::PostTask( | |
| 79 BrowserThread::UI, | |
| 80 FROM_HERE, | |
| 81 base::Bind( | |
| 82 &ShowDeleayedLoadingPage, | |
| 83 render_process_id_, | |
| 84 render_view_id_, | |
| 85 request_->url(), | |
| 86 base::Bind( | |
| 87 &MergeSessionThrottle::OnBlockingPageComplete, | |
| 88 AsWeakPtr()))); | |
| 89 *defer = true; | |
| 90 } | |
| 91 | |
| 92 void MergeSessionThrottle::OnBlockingPageComplete() { | |
| 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 94 controller()->Resume(); | |
| 95 } | |
| 96 | |
| 97 bool MergeSessionThrottle::ShouldShowMergeSessionPage(const GURL& url) const { | |
| 98 // If we are loading google properties while merge session is in progress, | |
| 99 // we will show delayed loading page instead. | |
| 100 return !net::NetworkChangeNotifier::IsOffline() && | |
| 101 google_util::IsGoogleHostname(url.host(), | |
| 102 google_util::ALLOW_SUBDOMAIN) && | |
| 103 chromeos::UserManager::Get()->GetMergeSessionState() == | |
| 104 chromeos::UserManager::MERGE_STATUS_IN_PROCESS; | |
| 105 } | |
| OLD | NEW |