Chromium Code Reviews| 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..22ea2a32fa216499ec9676c06cb4a5dfb147bae6 |
| --- /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 caller can use this |
|
fgorski
2016/08/15 21:38:32
by the caller do you mean the implementing class?
jianli
2016/08/15 23:15:44
Updated.
|
| + // opportunity to set a sepcific state in order to prevent the request from |
|
fgorski
2016/08/15 21:38:32
nit: specific
jianli
2016/08/15 23:15:44
Done.
|
| + // 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_ |