Index: chrome/browser/android/offline_pages/offline_page_request_job.h |
diff --git a/chrome/browser/android/offline_pages/offline_page_request_job.h b/chrome/browser/android/offline_pages/offline_page_request_job.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..21e6cb06ed68820f3770ab4f40bfb9a40739bc4e |
--- /dev/null |
+++ b/chrome/browser/android/offline_pages/offline_page_request_job.h |
@@ -0,0 +1,72 @@ |
+// 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_JOB_H_ |
+#define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ |
+ |
+#include "base/memory/weak_ptr.h" |
+#include "net/url_request/url_request_file_job.h" |
+ |
+namespace base { |
+class FilePath; |
+} |
+ |
+namespace offline_pages { |
+ |
+// A request job that serves content from offline file. |
+class OfflinePageRequestJob : public net::URLRequestFileJob { |
+ public: |
+ class Delegate { |
+ public: |
+ virtual ~Delegate() {} |
+ |
+ // Will be invoked before the request is restarted. The request handler |
+ // which implements this delegate, can use this opportunity to set a |
+ // specific state in order to prevent the request from being intercepted. |
+ virtual void OnPrepareToRestart() = 0; |
+ }; |
+ |
+ OfflinePageRequestJob(net::URLRequest* request, |
+ net::NetworkDelegate* network_delegate, |
+ Delegate* delegate); |
+ ~OfflinePageRequestJob() override; |
+ |
+ // net::URLRequestJob overrides: |
+ void Start() override; |
+ void Kill() override; |
+ |
+ base::WeakPtr<OfflinePageRequestJob> GetWeakPtr(); |
+ |
+ // Callback to fall back to default handling when offline file is not found. |
+ void FallbackToDefault(); |
+ |
+ // Called when offline file is found. |
+ void SetOfflineFilePath(const base::FilePath& offline_file_path); |
+ |
+ private: |
+ // Enum state controls how the job should be processed. |
+ enum class State { |
+ // Waiting to get the offline page info for the URL. |
+ NOT_DETERMINED, |
+ // Needs to restart the request in order to fall back to the default |
+ // handling when no offline page is found. |
+ FALLBACK_TO_DEFAULT, |
+ // Serves the offline content. |
+ SHOW_OFFLINE_CONTENT |
+ }; |
+ |
+ // Processes the request based on current state. |
+ void MaybeStartRequest(); |
+ |
+ Delegate* delegate_; // Not owned. |
+ bool is_started_; |
+ State state_; |
+ base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); |
+}; |
+ |
+} // namespace offline_pages |
+ |
+#endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ |