OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/signin/merge_session_throttle.h" | 5 #include "chrome/browser/chromeos/login/signin/merge_session_throttle.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 base::AtomicRefCount MergeSessionThrottle::all_profiles_restored_(0); | 71 base::AtomicRefCount MergeSessionThrottle::all_profiles_restored_(0); |
72 | 72 |
73 MergeSessionThrottle::MergeSessionThrottle(net::URLRequest* request, | 73 MergeSessionThrottle::MergeSessionThrottle(net::URLRequest* request, |
74 ResourceType resource_type) | 74 ResourceType resource_type) |
75 : request_(request), | 75 : request_(request), |
76 resource_type_(resource_type) { | 76 resource_type_(resource_type) { |
77 } | 77 } |
78 | 78 |
79 MergeSessionThrottle::~MergeSessionThrottle() { | 79 MergeSessionThrottle::~MergeSessionThrottle() { |
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
81 } | 81 } |
82 | 82 |
83 void MergeSessionThrottle::WillStartRequest(bool* defer) { | 83 void MergeSessionThrottle::WillStartRequest(bool* defer) { |
84 if (!ShouldDelayUrl(request_->url())) | 84 if (!ShouldDelayUrl(request_->url())) |
85 return; | 85 return; |
86 | 86 |
87 DVLOG(1) << "WillStartRequest: defer " << request_->url(); | 87 DVLOG(1) << "WillStartRequest: defer " << request_->url(); |
88 const content::ResourceRequestInfo* info = | 88 const content::ResourceRequestInfo* info = |
89 content::ResourceRequestInfo::ForRequest(request_); | 89 content::ResourceRequestInfo::ForRequest(request_); |
90 BrowserThread::PostTask( | 90 BrowserThread::PostTask( |
(...skipping 14 matching lines...) Expand all Loading... |
105 const char* MergeSessionThrottle::GetNameForLogging() const { | 105 const char* MergeSessionThrottle::GetNameForLogging() const { |
106 return "MergeSessionThrottle"; | 106 return "MergeSessionThrottle"; |
107 } | 107 } |
108 | 108 |
109 // static. | 109 // static. |
110 bool MergeSessionThrottle::AreAllSessionMergedAlready() { | 110 bool MergeSessionThrottle::AreAllSessionMergedAlready() { |
111 return !base::AtomicRefCountIsZero(&all_profiles_restored_); | 111 return !base::AtomicRefCountIsZero(&all_profiles_restored_); |
112 } | 112 } |
113 | 113 |
114 void MergeSessionThrottle::OnBlockingPageComplete() { | 114 void MergeSessionThrottle::OnBlockingPageComplete() { |
115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 115 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
116 controller()->Resume(); | 116 controller()->Resume(); |
117 } | 117 } |
118 | 118 |
119 bool MergeSessionThrottle::ShouldDelayUrl(const GURL& url) const { | 119 bool MergeSessionThrottle::ShouldDelayUrl(const GURL& url) const { |
120 // If we are loading google properties while merge session is in progress, | 120 // If we are loading google properties while merge session is in progress, |
121 // we will show delayed loading page instead. | 121 // we will show delayed loading page instead. |
122 return !net::NetworkChangeNotifier::IsOffline() && | 122 return !net::NetworkChangeNotifier::IsOffline() && |
123 !AreAllSessionMergedAlready() && | 123 !AreAllSessionMergedAlready() && |
124 google_util::IsGoogleHostname(url.host(), | 124 google_util::IsGoogleHostname(url.host(), |
125 google_util::ALLOW_SUBDOMAIN); | 125 google_util::ALLOW_SUBDOMAIN); |
(...skipping 27 matching lines...) Expand all Loading... |
153 if (ProfileSet::Get()->size() == 0) { | 153 if (ProfileSet::Get()->size() == 0) { |
154 base::AtomicRefCountInc(&all_profiles_restored_); | 154 base::AtomicRefCountInc(&all_profiles_restored_); |
155 DVLOG(1) << "All profiles merged " << all_profiles_restored_; | 155 DVLOG(1) << "All profiles merged " << all_profiles_restored_; |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 // static | 159 // static |
160 bool MergeSessionThrottle::ShouldDelayRequest( | 160 bool MergeSessionThrottle::ShouldDelayRequest( |
161 int render_process_id, | 161 int render_process_id, |
162 int render_view_id) { | 162 int render_view_id) { |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 163 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
164 | 164 |
165 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) { | 165 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) { |
166 return false; | 166 return false; |
167 } else if (!user_manager::UserManager::Get()-> | 167 } else if (!user_manager::UserManager::Get()-> |
168 IsLoggedInAsUserWithGaiaAccount()) { | 168 IsLoggedInAsUserWithGaiaAccount()) { |
169 // This is not a regular user session, let's remove the throttle | 169 // This is not a regular user session, let's remove the throttle |
170 // permanently. | 170 // permanently. |
171 if (!AreAllSessionMergedAlready()) | 171 if (!AreAllSessionMergedAlready()) |
172 base::AtomicRefCountInc(&all_profiles_restored_); | 172 base::AtomicRefCountInc(&all_profiles_restored_); |
173 | 173 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return false; | 240 return false; |
241 } | 241 } |
242 | 242 |
243 // static. | 243 // static. |
244 void MergeSessionThrottle::DeleayResourceLoadingOnUIThread( | 244 void MergeSessionThrottle::DeleayResourceLoadingOnUIThread( |
245 ResourceType resource_type, | 245 ResourceType resource_type, |
246 int render_process_id, | 246 int render_process_id, |
247 int render_view_id, | 247 int render_view_id, |
248 const GURL& url, | 248 const GURL& url, |
249 const CompletionCallback& callback) { | 249 const CompletionCallback& callback) { |
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 250 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
251 | 251 |
252 if (ShouldDelayRequest(render_process_id, render_view_id)) { | 252 if (ShouldDelayRequest(render_process_id, render_view_id)) { |
253 // There is a chance that the tab closed after we decided to show | 253 // There is a chance that the tab closed after we decided to show |
254 // the offline page on the IO thread and before we actually show the | 254 // the offline page on the IO thread and before we actually show the |
255 // offline page here on the UI thread. | 255 // offline page here on the UI thread. |
256 RenderViewHost* render_view_host = | 256 RenderViewHost* render_view_host = |
257 RenderViewHost::FromID(render_process_id, render_view_id); | 257 RenderViewHost::FromID(render_process_id, render_view_id); |
258 WebContents* web_contents = render_view_host ? | 258 WebContents* web_contents = render_view_host ? |
259 WebContents::FromRenderViewHost(render_view_host) : NULL; | 259 WebContents::FromRenderViewHost(render_view_host) : NULL; |
260 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { | 260 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { |
261 DVLOG(1) << "Creating page waiter for " << url.spec(); | 261 DVLOG(1) << "Creating page waiter for " << url.spec(); |
262 (new chromeos::MergeSessionLoadPage(web_contents, url, callback))->Show(); | 262 (new chromeos::MergeSessionLoadPage(web_contents, url, callback))->Show(); |
263 } else { | 263 } else { |
264 DVLOG(1) << "Creating XHR waiter for " << url.spec(); | 264 DVLOG(1) << "Creating XHR waiter for " << url.spec(); |
265 DCHECK(resource_type == content::RESOURCE_TYPE_XHR); | 265 DCHECK(resource_type == content::RESOURCE_TYPE_XHR); |
266 Profile* profile = Profile::FromBrowserContext( | 266 Profile* profile = Profile::FromBrowserContext( |
267 web_contents->GetBrowserContext()); | 267 web_contents->GetBrowserContext()); |
268 (new chromeos::MergeSessionXHRRequestWaiter(profile, | 268 (new chromeos::MergeSessionXHRRequestWaiter(profile, |
269 callback))->StartWaiting(); | 269 callback))->StartWaiting(); |
270 } | 270 } |
271 } else { | 271 } else { |
272 BrowserThread::PostTask( | 272 BrowserThread::PostTask( |
273 BrowserThread::IO, FROM_HERE, callback); | 273 BrowserThread::IO, FROM_HERE, callback); |
274 } | 274 } |
275 } | 275 } |
OLD | NEW |