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

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

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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MERGE_SESSION_THROTTLE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MERGE_SESSION_THROTTLE_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MERGE_SESSION_THROTTLE_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MERGE_SESSION_THROTTLE_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/atomic_ref_count.h" 10 #include "base/atomic_ref_count.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/chromeos/login/merge_session_load_page.h"
14 #include "content/public/browser/resource_throttle.h" 13 #include "content/public/browser/resource_throttle.h"
15 #include "net/base/completion_callback.h" 14 #include "net/base/completion_callback.h"
15 #include "webkit/common/resource_type.h"
16 16
17 class Profile; 17 class Profile;
18 18
19 namespace net { 19 namespace net {
20 class URLRequest; 20 class URLRequest;
21 } 21 }
22 22
23 namespace chromeos { 23 namespace chromeos {
24 class OAuth2LoginManager; 24 class OAuth2LoginManager;
25 } 25 }
26 26
27 // Used to show an interstitial page while merge session process (cookie 27 // Used to show an interstitial page while merge session process (cookie
28 // reconstruction from OAuth2 refresh token in ChromeOS login) is still in 28 // reconstruction from OAuth2 refresh token in ChromeOS login) is still in
29 // progress while we are attempting to load a google property. 29 // progress while we are attempting to load a google property.
30 class MergeSessionThrottle 30 class MergeSessionThrottle
31 : public content::ResourceThrottle, 31 : public content::ResourceThrottle,
32 public base::SupportsWeakPtr<MergeSessionThrottle> { 32 public base::SupportsWeakPtr<MergeSessionThrottle> {
33 public: 33 public:
34 explicit MergeSessionThrottle(net::URLRequest* request); 34 // Passed a boolean indicating whether or not it is OK to proceed with the
35 // page load.
36 typedef base::Closure CompletionCallback;
37
38 explicit MergeSessionThrottle(net::URLRequest* request,
39 ResourceType::Type resource_type);
35 virtual ~MergeSessionThrottle(); 40 virtual ~MergeSessionThrottle();
36 41
37 // content::ResourceThrottle implementation: 42 // content::ResourceThrottle implementation:
38 virtual void WillStartRequest(bool* defer) OVERRIDE; 43 virtual void WillStartRequest(bool* defer) OVERRIDE;
39 virtual const char* GetNameForLogging() const OVERRIDE; 44 virtual const char* GetNameForLogging() const OVERRIDE;
40 45
41 // Checks if session is already merged. 46 // Checks if session is already merged.
42 static bool AreAllSessionMergedAlready(); 47 static bool AreAllSessionMergedAlready();
43 48
44 private: 49 private:
45 50
46 // MergeSessionLoadPage callback. 51 // MergeSessionLoadPage callback.
47 void OnBlockingPageComplete(); 52 void OnBlockingPageComplete();
48 53
49 // Erase the state associated with a deferred load request. 54 // Erase the state associated with a deferred load request.
50 void ClearRequestInfo(); 55 void ClearRequestInfo();
51 bool IsRemote(const GURL& url) const; 56 bool IsRemote(const GURL& url) const;
52 57
53 // True if we should show the merge session in progress page. The function 58 // True if we |url| loading should be delayed. The function
54 // is safe to be called on any thread. 59 // is safe to be called on any thread.
55 bool ShouldShowMergeSessionPage(const GURL& url) const; 60 bool ShouldDelayUrl(const GURL& url) const;
56 61
57 // Adds/removes |profile| to/from the blocking profiles set. 62 // Adds/removes |profile| to/from the blocking profiles set.
58 static void BlockProfile(Profile* profile); 63 static void BlockProfile(Profile* profile);
59 static void UnblockProfile(Profile* profile); 64 static void UnblockProfile(Profile* profile);
60 65
61 // Helper method that checks if we should show interstitial page based on 66 // Helper method that checks if we should delay reasource loading based on
62 // the state of the Profile that's derived from |render_process_id| and 67 // the state of the Profile that's derived from |render_process_id| and
63 // |render_view_id|. 68 // |render_view_id|.
64 static bool ShouldShowInterstitialPage(int render_process_id, 69 static bool ShouldDelayRequest(int render_process_id,
65 int render_view_id); 70 int render_view_id);
66 71
67 // Tests merge session status and if needed shows interstitial page. 72 // Tests merge session status and if needed generates request
73 // waiter (for ResourceType::XHR content) or shows interstitial page
74 // (for ResourceType::MAIN_FRAME).
68 // The function must be called from UI thread. 75 // The function must be called from UI thread.
69 static void ShowDeleayedLoadingPageOnUIThread( 76 static void DeleayResourceLoadingOnUIThread(
77 ResourceType::Type resource_type,
70 int render_process_id, 78 int render_process_id,
71 int render_view_id, 79 int render_view_id,
72 const GURL& url, 80 const GURL& url,
73 const chromeos::MergeSessionLoadPage::CompletionCallback& callback); 81 const MergeSessionThrottle::CompletionCallback& callback);
74 82
75 net::URLRequest* request_; 83 net::URLRequest* request_;
84 ResourceType::Type resource_type_;
76 85
77 // Global counter that keeps the track of session merge status for all 86 // Global counter that keeps the track of session merge status for all
78 // encountered profiles. This is used to determine if a throttle should 87 // encountered profiles. This is used to determine if a throttle should
79 // even be even added to new requests. Value of 0 (initial) means that we 88 // even be even added to new requests. Value of 0 (initial) means that we
80 // probably have some profiles to restore, while 1 means that all known 89 // probably have some profiles to restore, while 1 means that all known
81 // profiles are restored. 90 // profiles are restored.
82 static base::AtomicRefCount all_profiles_restored_; 91 static base::AtomicRefCount all_profiles_restored_;
83
84 DISALLOW_COPY_AND_ASSIGN(MergeSessionThrottle);
xiyuan 2013/12/19 01:45:41 Does this need to be removed?
zel 2013/12/19 23:28:02 Done.
85 }; 92 };
86 93
87 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MERGE_SESSION_THROTTLE_H_ 94 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MERGE_SESSION_THROTTLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698