ExtensionSyncService: listen for relevant changes instead of being explicitly called...
[chromium-blink-merge.git] / chrome / browser / chromeos / login / signin / merge_session_throttle.h
blobd87fe9d15dff18883f4de4984c49edfa6b1f8750
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_MERGE_SESSION_THROTTLE_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_MERGE_SESSION_THROTTLE_H_
8 #include <set>
10 #include "base/atomic_ref_count.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/browser/resource_throttle.h"
14 #include "content/public/common/resource_type.h"
15 #include "net/base/completion_callback.h"
17 class Profile;
19 namespace net {
20 class URLRequest;
23 namespace chromeos {
24 class OAuth2LoginManager;
27 // Used to show an interstitial page while merge session process (cookie
28 // reconstruction from OAuth2 refresh token in ChromeOS login) is still in
29 // progress while we are attempting to load a google property.
30 class MergeSessionThrottle
31 : public content::ResourceThrottle,
32 public base::SupportsWeakPtr<MergeSessionThrottle> {
33 public:
34 // Passed a boolean indicating whether or not it is OK to proceed with the
35 // page load.
36 typedef base::Closure CompletionCallback;
38 explicit MergeSessionThrottle(net::URLRequest* request,
39 content::ResourceType resource_type);
40 ~MergeSessionThrottle() override;
42 // content::ResourceThrottle implementation:
43 void WillStartRequest(bool* defer) override;
44 const char* GetNameForLogging() const override;
46 // Checks if session is already merged.
47 static bool AreAllSessionMergedAlready();
49 private:
51 // MergeSessionLoadPage callback.
52 void OnBlockingPageComplete();
54 // Erase the state associated with a deferred load request.
55 void ClearRequestInfo();
56 bool IsRemote(const GURL& url) const;
58 // True if we |url| loading should be delayed. The function
59 // is safe to be called on any thread.
60 bool ShouldDelayUrl(const GURL& url) const;
62 // Adds/removes |profile| to/from the blocking profiles set.
63 static void BlockProfile(Profile* profile);
64 static void UnblockProfile(Profile* profile);
66 // Helper method that checks if we should delay reasource loading based on
67 // the state of the Profile that's derived from |render_process_id| and
68 // |render_view_id|.
69 static bool ShouldDelayRequest(int render_process_id,
70 int render_view_id);
72 // Tests merge session status and if needed generates request
73 // waiter (for content::RESOURCE_TYPE_XHR content) or shows interstitial page
74 // (for content::RESOURCE_TYPE_MAIN_FRAME).
75 // The function must be called from UI thread.
76 static void DeleayResourceLoadingOnUIThread(
77 content::ResourceType resource_type,
78 int render_process_id,
79 int render_view_id,
80 const GURL& url,
81 const MergeSessionThrottle::CompletionCallback& callback);
83 net::URLRequest* request_;
84 content::ResourceType resource_type_;
86 // Global counter that keeps the track of session merge status for all
87 // encountered profiles. This is used to determine if a throttle should
88 // even be even added to new requests. Value of 0 (initial) means that we
89 // probably have some profiles to restore, while 1 means that all known
90 // profiles are restored.
91 static base::AtomicRefCount all_profiles_restored_;
93 DISALLOW_COPY_AND_ASSIGN(MergeSessionThrottle);
96 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_MERGE_SESSION_THROTTLE_H_