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

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

Issue 118733002: Added merge session request throttle for XHR requests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
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/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"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/chromeos/login/merge_session_load_page.h"
16 #include "chrome/browser/chromeos/login/merge_session_xhr_request_waiter.h"
15 #include "chrome/browser/chromeos/login/oauth2_login_manager.h" 17 #include "chrome/browser/chromeos/login/oauth2_login_manager.h"
16 #include "chrome/browser/chromeos/login/oauth2_login_manager_factory.h" 18 #include "chrome/browser/chromeos/login/oauth2_login_manager_factory.h"
17 #include "chrome/browser/chromeos/login/user_manager.h" 19 #include "chrome/browser/chromeos/login/user_manager.h"
18 #include "chrome/browser/chromeos/login/user_manager.h" 20 #include "chrome/browser/chromeos/login/user_manager.h"
19 #include "chrome/browser/google/google_util.h" 21 #include "chrome/browser/google/google_util.h"
20 #include "chrome/browser/net/chrome_url_request_context.h" 22 #include "chrome/browser/net/chrome_url_request_context.h"
21 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
22 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/render_view_host.h" 25 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/resource_controller.h" 26 #include "content/public/browser/resource_controller.h"
(...skipping 10 matching lines...) Expand all
35 using content::WebContents; 37 using content::WebContents;
36 38
37 namespace { 39 namespace {
38 40
39 const int64 kMaxSessionRestoreTimeInSec = 60; 41 const int64 kMaxSessionRestoreTimeInSec = 60;
40 42
41 // The set of blocked profiles. 43 // The set of blocked profiles.
42 class ProfileSet : public base::NonThreadSafe, 44 class ProfileSet : public base::NonThreadSafe,
43 public std::set<Profile*> { 45 public std::set<Profile*> {
44 public: 46 public:
45 ProfileSet(); 47 ProfileSet() {
46 virtual ~ProfileSet(); 48 }
49
50 virtual ~ProfileSet() {
51 }
52
47 static ProfileSet* Get(); 53 static ProfileSet* Get();
48 54
49 private: 55 private:
50 friend struct ::base::DefaultLazyInstanceTraits<ProfileSet>; 56 friend struct ::base::DefaultLazyInstanceTraits<ProfileSet>;
57
58 DISALLOW_COPY_AND_ASSIGN(ProfileSet);
51 }; 59 };
52 60
53 // Set of all of profiles for which restore session is in progress. 61 // Set of all of profiles for which restore session is in progress.
54 // This static member is accessible only form UI thread. 62 // This static member is accessible only form UI thread.
55 static base::LazyInstance<ProfileSet> g_blocked_profiles = 63 static base::LazyInstance<ProfileSet> g_blocked_profiles =
56 LAZY_INSTANCE_INITIALIZER; 64 LAZY_INSTANCE_INITIALIZER;
57 65
58 ProfileSet::ProfileSet() {
59 }
60
61 ProfileSet::~ProfileSet() {
62 }
63
64 ProfileSet* ProfileSet::Get() { 66 ProfileSet* ProfileSet::Get() {
65 return g_blocked_profiles.Pointer(); 67 return g_blocked_profiles.Pointer();
66 } 68 }
67 69
68 } // namespace 70 } // namespace
69 71
70 base::AtomicRefCount MergeSessionThrottle::all_profiles_restored_(0); 72 base::AtomicRefCount MergeSessionThrottle::all_profiles_restored_(0);
71 73
72 MergeSessionThrottle::MergeSessionThrottle(net::URLRequest* request) 74 MergeSessionThrottle::MergeSessionThrottle(net::URLRequest* request,
73 : request_(request) { 75 ResourceType::Type resource_type)
76 : request_(request),
77 resource_type_(resource_type) {
74 } 78 }
75 79
76 MergeSessionThrottle::~MergeSessionThrottle() { 80 MergeSessionThrottle::~MergeSessionThrottle() {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
78 } 82 }
79 83
80 void MergeSessionThrottle::WillStartRequest(bool* defer) { 84 void MergeSessionThrottle::WillStartRequest(bool* defer) {
81 DCHECK(request_->url().SchemeIsHTTPOrHTTPS()); 85 if (!ShouldDelayUrl(request_->url()))
82 if (!ShouldShowMergeSessionPage(request_->url()))
83 return; 86 return;
84 87
85 DVLOG(1) << "WillStartRequest: defer " << request_->url(); 88 DVLOG(1) << "WillStartRequest: defer " << request_->url();
86 const content::ResourceRequestInfo* info = 89 const content::ResourceRequestInfo* info =
87 content::ResourceRequestInfo::ForRequest(request_); 90 content::ResourceRequestInfo::ForRequest(request_);
88 BrowserThread::PostTask( 91 BrowserThread::PostTask(
89 BrowserThread::UI, 92 BrowserThread::UI,
90 FROM_HERE, 93 FROM_HERE,
91 base::Bind( 94 base::Bind(
92 &MergeSessionThrottle::ShowDeleayedLoadingPageOnUIThread, 95 &MergeSessionThrottle::DeleayResourceLoadingOnUIThread,
96 resource_type_,
93 info->GetChildID(), 97 info->GetChildID(),
94 info->GetRouteID(), 98 info->GetRouteID(),
95 request_->url(), 99 request_->url(),
96 base::Bind( 100 base::Bind(
97 &MergeSessionThrottle::OnBlockingPageComplete, 101 &MergeSessionThrottle::OnBlockingPageComplete,
98 AsWeakPtr()))); 102 AsWeakPtr())));
99 *defer = true; 103 *defer = true;
100 } 104 }
101 105
102 const char* MergeSessionThrottle::GetNameForLogging() const { 106 const char* MergeSessionThrottle::GetNameForLogging() const {
103 return "MergeSessionThrottle"; 107 return "MergeSessionThrottle";
104 } 108 }
105 109
106 // static. 110 // static.
107 bool MergeSessionThrottle::AreAllSessionMergedAlready() { 111 bool MergeSessionThrottle::AreAllSessionMergedAlready() {
108 return !base::AtomicRefCountIsZero(&all_profiles_restored_); 112 return !base::AtomicRefCountIsZero(&all_profiles_restored_);
109 } 113 }
110 114
111 void MergeSessionThrottle::OnBlockingPageComplete() { 115 void MergeSessionThrottle::OnBlockingPageComplete() {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
113 controller()->Resume(); 117 controller()->Resume();
114 } 118 }
115 119
116 bool MergeSessionThrottle::ShouldShowMergeSessionPage(const GURL& url) const { 120 bool MergeSessionThrottle::ShouldDelayUrl(const GURL& url) const {
117 // If we are loading google properties while merge session is in progress, 121 // If we are loading google properties while merge session is in progress,
118 // we will show delayed loading page instead. 122 // we will show delayed loading page instead.
119 return !net::NetworkChangeNotifier::IsOffline() && 123 return !net::NetworkChangeNotifier::IsOffline() &&
120 !AreAllSessionMergedAlready() && 124 !AreAllSessionMergedAlready() &&
121 google_util::IsGoogleHostname(url.host(), 125 google_util::IsGoogleHostname(url.host(),
122 google_util::ALLOW_SUBDOMAIN); 126 google_util::ALLOW_SUBDOMAIN);
123 } 127 }
124 128
125 // static 129 // static
126 void MergeSessionThrottle::BlockProfile(Profile* profile) { 130 void MergeSessionThrottle::BlockProfile(Profile* profile) {
(...skipping 20 matching lines...) Expand all
147 ProfileSet::Get()->erase(profile); 151 ProfileSet::Get()->erase(profile);
148 152
149 // Check if there is any other profile to block on. 153 // Check if there is any other profile to block on.
150 if (ProfileSet::Get()->size() == 0) { 154 if (ProfileSet::Get()->size() == 0) {
151 base::AtomicRefCountInc(&all_profiles_restored_); 155 base::AtomicRefCountInc(&all_profiles_restored_);
152 DVLOG(1) << "All profiles merged " << all_profiles_restored_; 156 DVLOG(1) << "All profiles merged " << all_profiles_restored_;
153 } 157 }
154 } 158 }
155 159
156 // static 160 // static
157 bool MergeSessionThrottle::ShouldShowInterstitialPage( 161 bool MergeSessionThrottle::ShouldDelayRequest(
158 int render_process_id, 162 int render_process_id,
159 int render_view_id) { 163 int render_view_id) {
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
161 165
162 if (!chromeos::UserManager::Get()->IsUserLoggedIn()) { 166 if (!chromeos::UserManager::Get()->IsUserLoggedIn()) {
163 return false; 167 return false;
164 } else if (!chromeos::UserManager::Get()->IsLoggedInAsRegularUser()) { 168 } else if (!chromeos::UserManager::Get()->IsLoggedInAsRegularUser()) {
165 // 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
166 // permanently. 170 // permanently.
167 if (!AreAllSessionMergedAlready()) 171 if (!AreAllSessionMergedAlready())
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 UnblockProfile(profile); 234 UnblockProfile(profile);
231 return false; 235 return false;
232 } 236 }
233 } 237 }
234 238
235 NOTREACHED(); 239 NOTREACHED();
236 return false; 240 return false;
237 } 241 }
238 242
239 // static. 243 // static.
240 void MergeSessionThrottle::ShowDeleayedLoadingPageOnUIThread( 244 void MergeSessionThrottle::DeleayResourceLoadingOnUIThread(
245 ResourceType::Type resource_type,
241 int render_process_id, 246 int render_process_id,
242 int render_view_id, 247 int render_view_id,
243 const GURL& url, 248 const GURL& url,
244 const chromeos::MergeSessionLoadPage::CompletionCallback& callback) { 249 const CompletionCallback& callback) {
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
246 251
247 if (ShouldShowInterstitialPage(render_process_id, render_view_id)) { 252 if (ShouldDelayRequest(render_process_id, render_view_id)) {
248 // 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
249 // 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
250 // offline page here on the UI thread. 255 // offline page here on the UI thread.
251 RenderViewHost* render_view_host = 256 RenderViewHost* render_view_host =
252 RenderViewHost::FromID(render_process_id, render_view_id); 257 RenderViewHost::FromID(render_process_id, render_view_id);
253 WebContents* web_contents = render_view_host ? 258 WebContents* web_contents = render_view_host ?
254 WebContents::FromRenderViewHost(render_view_host) : NULL; 259 WebContents::FromRenderViewHost(render_view_host) : NULL;
255 if (web_contents) 260 if (resource_type == ResourceType::MAIN_FRAME) {
261 DVLOG(1) << "Creating page waiter for " << url.spec();
256 (new chromeos::MergeSessionLoadPage(web_contents, url, callback))->Show(); 262 (new chromeos::MergeSessionLoadPage(web_contents, url, callback))->Show();
263 } else {
264 DVLOG(1) << "Creating XHR waiter for " << url.spec();
265 DCHECK(resource_type == ResourceType::XHR);
266 Profile* profile = Profile::FromBrowserContext(
267 web_contents->GetBrowserContext());
268 (new chromeos::MergeSessionXHRRequestWaiter(profile,
269 callback))->StartWaiting();
270 }
257 } else { 271 } else {
258 BrowserThread::PostTask( 272 BrowserThread::PostTask(
259 BrowserThread::IO, FROM_HERE, callback); 273 BrowserThread::IO, FROM_HERE, callback);
260 } 274 }
261 } 275 }
262
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698