OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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. | |
4 | |
5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ | |
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ | |
7 | |
8 #include "base/memory/weak_ptr.h" | |
9 #include "net/url_request/url_request_file_job.h" | |
10 | |
11 namespace base { | |
12 class FilePath; | |
13 } | |
14 | |
15 namespace offline_pages { | |
16 | |
17 // A request job that serves content from offline file. | |
18 class OfflinePageRequestJob : public net::URLRequestFileJob { | |
19 public: | |
20 class Delegate { | |
21 public: | |
22 virtual ~Delegate() {} | |
23 | |
24 // 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.
| |
25 // 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.
| |
26 // being intercepted. | |
27 virtual void OnPrepareToRestart() = 0; | |
28 }; | |
29 | |
30 OfflinePageRequestJob(net::URLRequest* request, | |
31 net::NetworkDelegate* network_delegate, | |
32 Delegate* delegate); | |
33 ~OfflinePageRequestJob() override; | |
34 | |
35 // net::URLRequestJob overrides: | |
36 void Start() override; | |
37 void Kill() override; | |
38 | |
39 base::WeakPtr<OfflinePageRequestJob> GetWeakPtr(); | |
40 | |
41 // Callback to fall back to default handling when offline file is not found. | |
42 void FallbackToDefault(); | |
43 | |
44 // Called when offline file is found. | |
45 void SetOfflineFilePath(const base::FilePath& offline_file_path); | |
46 | |
47 private: | |
48 // Enum state controls how the job should be processed. | |
49 enum class State { | |
50 // Waiting to get the offline page info for the URL. | |
51 NOT_DETERMINED, | |
52 // Needs to restart the request in order to fall back to the default | |
53 // handling when no offline page is found. | |
54 FALLBACK_TO_DEFAULT, | |
55 // Serves the offline content. | |
56 SHOW_OFFLINE_CONTENT | |
57 }; | |
58 | |
59 // Processes the request based on current state. | |
60 void MaybeStartRequest(); | |
61 | |
62 Delegate* delegate_; // Not owned. | |
63 bool is_started_; | |
64 State state_; | |
65 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); | |
68 }; | |
69 | |
70 } // namespace offline_pages | |
71 | |
72 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ | |
OLD | NEW |