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

Side by Side Diff: content/browser/loader/offline_policy.cc

Issue 12886022: Implement offline mode behind a flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments. Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "content/browser/loader/offline_policy.h"
6
7 #include "base/command_line.h"
8 #include "content/public/common/content_switches.h"
9 #include "net/base/load_flags.h"
10 #include "net/http/http_response_info.h"
11 #include "net/url_request/url_request.h"
12
13 namespace content {
14
15 OfflinePolicy::OfflinePolicy()
16 : enabled_(CommandLine::ForCurrentProcess()->HasSwitch(
17 switches::kEnableOfflineCacheAccess)),
darin (slow to review) 2013/04/18 05:03:02 nit: 4 space indent for line continuations
Randy Smith (Not in Mondays) 2013/04/18 20:04:57 Um ... done, but I'll note that I'm already indent
18 state_(INIT) {}
19
20 OfflinePolicy::~OfflinePolicy() {}
21
22 int OfflinePolicy::GetAdditionalLoadFlags(
darin (slow to review) 2013/04/18 05:03:02 nit: style guide suggests this formatting: int Of
Randy Smith (Not in Mondays) 2013/04/18 20:04:57 Done.
23 int current_flags, bool reset_state) {
24
25 // Don't do anything if offline mode is disabled.
26 if (!enabled_)
27 return 0;
28
29 if (reset_state)
30 state_ = INIT;
31
32 // If a consumer has requested something contradictory, it wins; we
33 // don't modify the load flags.
34 if (current_flags &
35 (net::LOAD_BYPASS_CACHE | net::LOAD_PREFERRING_CACHE |
36 net::LOAD_ONLY_FROM_CACHE | net::LOAD_FROM_CACHE_IF_OFFLINE |
37 net::LOAD_DISABLE_CACHE)) {
38 return 0;
39 }
40
41 switch(state_) {
42 case INIT:
43 return net::LOAD_FROM_CACHE_IF_OFFLINE;
44 case ONLINE:
45 return 0;
46 case OFFLINE:
47 return net::LOAD_ONLY_FROM_CACHE;
48 }
49 NOTREACHED();
50 return 0;
51 }
52
53 void OfflinePolicy::UpdateStateForCompletedRequest(
54 const net::HttpResponseInfo& response_info) {
55 // Don't do anything if offline mode is disabled.
56 if (!enabled_)
57 return;
58
59 if (state_ != INIT)
60 // We've already made the decision for the rest of this set
61 // of navigations.
62 return;
63
64 if (response_info.server_data_unavailable) {
65 state_ = OFFLINE;
66 } else if (response_info.network_accessed) {
67 // If we got the response from the network or validated it as part
68 // of this request, that means our connection to the host is working.
69 state_ = ONLINE;
70 }
71 }
72
73 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698