1// Copyright (c) 2013 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 CONTENT_BROWSER_LOADER_OFFLINE_POLICY
6#define CONTENT_BROWSER_LOADER_OFFLINE_POLICY
7
8#include <map>
9
10#include "base/basictypes.h"
11#include "content/common/content_export.h"
12
13struct ResourceHostMsg_Request;
14
15namespace net {
16class HttpResponseInfo;
17class URLRequest;
18}
19
20namespace content {
21
22// This class controls under what conditions resources will be fetched
23// from cache even if stale rather than from the network.  For example,
24// one policy would be that if requests for a particular route (e.g. "tab")
25// is unable to reach the server, other requests made with the same route
26// can be loaded from cache without first requiring a network timeout.
27//
28// There is a single OfflinePolicy object per user navigation unit
29// (generally a tab).
30class CONTENT_EXPORT OfflinePolicy {
31 public:
32  OfflinePolicy();
33  ~OfflinePolicy();
34
35  // Return any additional load flags to be ORed for a request from
36  // this route with the given |resource_type|.  |reset_state| indicates
37  // that this request should reinitialized the internal state for this
38  // policy object (e.g. in the case of a main frame load).
39  int GetAdditionalLoadFlags(int current_flags, bool reset_state);
40
41  // Incorporate online/offline information from a successfully started request.
42  void UpdateStateForSuccessfullyStartedRequest(
43      const net::HttpResponseInfo& response_info);
44
45private:
46  enum State { INIT, ONLINE, OFFLINE };
47
48  void RecordAndResetStats();
49
50  bool enabled_;
51  State state_;
52  int resource_loads_initiated_;
53  int resource_loads_successfully_started_;
54
55  DISALLOW_COPY_AND_ASSIGN(OfflinePolicy);
56};
57
58}  // namespace content
59
60#endif  // CONTENT_BROWSER_LOADER_OFFLINE_POLICY
61