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

Unified Diff: chrome/browser/android/offline_pages/offline_page_request_redirect_job.h

Issue 2002433002: Handle online and offline redirects via interceptor and offline scheme (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/offline_pages/offline_page_request_redirect_job.h
diff --git a/chrome/browser/android/offline_pages/offline_page_request_redirect_job.h b/chrome/browser/android/offline_pages/offline_page_request_redirect_job.h
new file mode 100644
index 0000000000000000000000000000000000000000..ad393decb7ea2ec3eb11ba8c52e154a2503b4b7a
--- /dev/null
+++ b/chrome/browser/android/offline_pages/offline_page_request_redirect_job.h
@@ -0,0 +1,62 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_REDIRECT_JOB_H_
+#define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_REDIRECT_JOB_H_
+
+#include "base/memory/weak_ptr.h"
+#include "net/url_request/url_request_job.h"
+#include "url/gurl.h"
+
+namespace offline_pages {
+
+// A request job that handles the redirection between online URL and offline
+// URL when the offline copy exists.
+class OfflinePageRequestRedirectJob : public net::URLRequestJob {
+ public:
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+
+ // Will be invoked before the request is restarted. The caller can use this
+ // opportunity to set a sepcific state in order to prevent the request from
+ // being intercepted.
+ virtual void OnPrepareToRestart() = 0;
+ };
+
+ OfflinePageRequestRedirectJob(net::URLRequest* request,
+ net::NetworkDelegate* network_delegate,
+ Delegate* delegate);
+ ~OfflinePageRequestRedirectJob() override;
+
+ // net::URLRequestJob overrides:
+ void Start() override;
+ void Kill() override;
+ bool IsRedirectResponse(GURL* location, int* http_status_code) override;
+
+ base::WeakPtr<OfflinePageRequestRedirectJob> GetWeakPtr();
+ void FallbackToDefault();
+ void SetRedirectURL(const GURL& url);
+
+ private:
+ enum class State {
+ NOT_DETERMINED,
+ FALLBACK_TO_DEFAULT,
+ DO_REDIRECT
+ };
+
+ void MaybeStartRequest();
+
+ Delegate* delegate_; // Not owned.
+ bool is_started_;
+ State state_;
+ GURL redirect_url_;
+ base::WeakPtrFactory<OfflinePageRequestRedirectJob> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestRedirectJob);
+};
+
+} // namespace offline_pages
+
+#endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_REDIRECT_JOB_H_

Powered by Google App Engine
This is Rietveld 408576698