Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: chrome/browser/chromeos/login/merge_session_throttle.cc

Issue 12256046: Added interstitial page for merge session. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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>
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, base::Bind(callback, true));
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(
62 int render_process_id,
oshima 2013/02/15 22:40:52 nit: is it possible to align arguments to (? I thi
zel 2013/02/15 23:16:58 Done.
63 int render_view_id,
64 net::URLRequest* request)
65 : render_process_id_(render_process_id),
66 render_view_id_(render_view_id),
67 request_(request) {
68 }
69
70 MergeSessionThrottle::~MergeSessionThrottle() {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
72 }
73
74 void MergeSessionThrottle::WillStartRequest(bool* defer) {
75 if (!ShouldShowMergeSessionPage(request_->url()))
76 return;
77
78 DVLOG(1) << "WillStartRequest: url=" << request_->url();
79 BrowserThread::PostTask(
80 BrowserThread::UI,
81 FROM_HERE,
82 base::Bind(
83 &ShowDeleayedLoadingPage,
84 render_process_id_,
85 render_view_id_,
86 request_->url(),
87 base::Bind(
88 &MergeSessionThrottle::OnBlockingPageComplete,
89 AsWeakPtr())));
90 *defer = true;
91 }
92
93 void MergeSessionThrottle::OnBlockingPageComplete(bool proceed) {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
95 if (proceed) {
96 controller()->Resume();
97 } else {
98 controller()->Cancel();
99 }
100 }
101
102 bool MergeSessionThrottle::ShouldShowMergeSessionPage(const GURL& url) const {
103 // If we are loading google properties while merge session is in progress,
104 // we will show delayed loading page instead.
105 return !net::NetworkChangeNotifier::IsOffline() &&
106 google_util::IsGoogleHostname(url.host(),
107 google_util::ALLOW_SUBDOMAIN) &&
108 chromeos::UserManager::Get()->GetMergeSessionState() ==
109 chromeos::UserManager::MERGE_STATUS_IN_PROCESS;
110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698