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

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

Issue 12886022: Implement offline mode behind a flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to r190685 (past landing of https://codereview.chromium.org/12310075). 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_manager.h"
6
7 #include "content/common/resource_messages.h"
8 #include "net/base/load_flags.h"
9 #include "net/http/http_response_info.h"
10 #include "net/url_request/url_request.h"
11
12 namespace content {
13
14 OfflineManager::OfflineManager() {}
15
16 OfflineManager::~OfflineManager() {}
17
18 int OfflineManager::OfflineLoadFlags(
19 int child_id, int route_id, const ResourceHostMsg_Request& request_data) {
darin (slow to review) 2013/03/27 18:33:59 how will you use the request_data parameter?
Randy Smith (Not in Mondays) 2013/04/03 19:20:34 Ooops :-}. I original put it in so that I'd have
20 std::pair<int, int> key(std::make_pair(child_id, route_id));
21 // std::map::insert just returns an existing element if it already exists.
22 const RouteMap::iterator it(
23 offline_state_map_.insert(std::make_pair(key, ROUTE_INIT)).first);
24 switch(it->second) {
25 case ROUTE_INIT:
26 return net::LOAD_FROM_CACHE_IF_OFFLINE;
27 case ROUTE_ONLINE:
28 return 0;
29 case ROUTE_OFFLINE:
30 return net::LOAD_ONLY_FROM_CACHE;
31 }
32 NOTREACHED();
33 return 0;
34 }
35
36 void OfflineManager::RequestCompleted(
37 int child_id, int route_id, const net::URLRequest* request) {
38 const RouteMap::iterator it(
39 offline_state_map_.find(std::make_pair(child_id, route_id)));
40 const net::HttpResponseInfo& response_info(request->response_info());
41
42 // We should have seen this on the incoming side.
43 DCHECK(offline_state_map_.end() != it);
44
45 if (it->second == ROUTE_INIT) {
46 if (response_info.server_data_unavailable) {
47 it->second = ROUTE_OFFLINE;
48 } else if (!response_info.was_cached ||
49 response_info.response_time >= request->creation_time()) {
50 // If we got the response from the network or validated it as part
51 // of this request, that means our connection to the host is working.
52 it->second = ROUTE_ONLINE;
53 }
54 }
55 }
56
57 void OfflineManager::RouteDeleted(int child_id, int route_id) {
58 const RouteMap::iterator it(
59 offline_state_map_.find(std::make_pair(child_id, route_id)));
60 if (offline_state_map_.end() != it)
61 offline_state_map_.erase(it);
62 }
63
64 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698