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

Unified 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: Sync'd to r193064. 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/offline_policy.cc
diff --git a/content/browser/loader/offline_policy.cc b/content/browser/loader/offline_policy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c09f0ebd7f2a4e673bb073fa2dfc0a34cd18366f
--- /dev/null
+++ b/content/browser/loader/offline_policy.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2013 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.
+
+#include "content/browser/loader/offline_policy.h"
+
+#include "base/command_line.h"
+#include "content/public/common/content_switches.h"
+#include "net/base/load_flags.h"
+#include "net/http/http_response_info.h"
+#include "net/url_request/url_request.h"
+
+namespace content {
+
+OfflinePolicy::OfflinePolicy()
+ : offline_state_(INIT) {}
+
+OfflinePolicy::~OfflinePolicy() {}
+
+int OfflinePolicy::GetAdditionalLoadFlags(
+ int current_flags, ResourceType::Type resource_type) {
+
+ // Don't do anything if offline mode is disabled.
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
darin (slow to review) 2013/04/11 20:01:23 it seems like this switch could just be checked on
Randy Smith (Not in Mondays) 2013/04/12 14:06:44 Done.
+ switches::kEnableOfflineCacheAccess))
+ return 0;
+
+ if (resource_type == ResourceType::MAIN_FRAME)
+ offline_state_ = INIT;
+
+ // If a consumer has requested something contradictory, it wins; we
+ // don't modify the load flags.
+ if (current_flags &
+ (net::LOAD_BYPASS_CACHE | net::LOAD_PREFERRING_CACHE |
+ net::LOAD_ONLY_FROM_CACHE | net::LOAD_FROM_CACHE_IF_OFFLINE |
+ net::LOAD_DISABLE_CACHE)) {
+ return 0;
+ }
+
+ switch(offline_state_) {
+ case INIT:
+ return net::LOAD_FROM_CACHE_IF_OFFLINE;
+ case ONLINE:
+ return 0;
+ case OFFLINE:
+ return net::LOAD_ONLY_FROM_CACHE;
+ }
+ NOTREACHED();
+ return 0;
+}
+
+void OfflinePolicy::RequestCompleted(
+ const net::HttpResponseInfo& response_info) {
+ // Don't do anything if offline mode is disabled.
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableOfflineCacheAccess))
+ return;
+
+ if (offline_state_ != INIT)
+ // We've already made the decision for the rest of this set
+ // of navigations.
+ return;
+
+ if (response_info.server_data_unavailable) {
+ offline_state_ = OFFLINE;
+ } else if (response_info.network_accessed) {
+ // If we got the response from the network or validated it as part
+ // of this request, that means our connection to the host is working.
+ offline_state_ = ONLINE;
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698