Chromium Code Reviews| Index: content/browser/loader/offline_manager.cc |
| diff --git a/content/browser/loader/offline_manager.cc b/content/browser/loader/offline_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ae3d27fd7e268061f96840b50fdbd1c932e4c8e4 |
| --- /dev/null |
| +++ b/content/browser/loader/offline_manager.cc |
| @@ -0,0 +1,64 @@ |
| +// 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_manager.h" |
| + |
| +#include "content/common/resource_messages.h" |
| +#include "net/base/load_flags.h" |
| +#include "net/http/http_response_info.h" |
| +#include "net/url_request/url_request.h" |
| + |
| +namespace content { |
| + |
| +OfflineManager::OfflineManager() {} |
| + |
| +OfflineManager::~OfflineManager() {} |
| + |
| +int OfflineManager::OfflineLoadFlags( |
| + 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
|
| + std::pair<int, int> key(std::make_pair(child_id, route_id)); |
| + // std::map::insert just returns an existing element if it already exists. |
| + const RouteMap::iterator it( |
| + offline_state_map_.insert(std::make_pair(key, ROUTE_INIT)).first); |
| + switch(it->second) { |
| + case ROUTE_INIT: |
| + return net::LOAD_FROM_CACHE_IF_OFFLINE; |
| + case ROUTE_ONLINE: |
| + return 0; |
| + case ROUTE_OFFLINE: |
| + return net::LOAD_ONLY_FROM_CACHE; |
| + } |
| + NOTREACHED(); |
| + return 0; |
| +} |
| + |
| +void OfflineManager::RequestCompleted( |
| + int child_id, int route_id, const net::URLRequest* request) { |
| + const RouteMap::iterator it( |
| + offline_state_map_.find(std::make_pair(child_id, route_id))); |
| + const net::HttpResponseInfo& response_info(request->response_info()); |
| + |
| + // We should have seen this on the incoming side. |
| + DCHECK(offline_state_map_.end() != it); |
| + |
| + if (it->second == ROUTE_INIT) { |
| + if (response_info.server_data_unavailable) { |
| + it->second = ROUTE_OFFLINE; |
| + } else if (!response_info.was_cached || |
| + response_info.response_time >= request->creation_time()) { |
| + // 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. |
| + it->second = ROUTE_ONLINE; |
| + } |
| + } |
| +} |
| + |
| +void OfflineManager::RouteDeleted(int child_id, int route_id) { |
| + const RouteMap::iterator it( |
| + offline_state_map_.find(std::make_pair(child_id, route_id))); |
| + if (offline_state_map_.end() != it) |
| + offline_state_map_.erase(it); |
| +} |
| + |
| +} // namespace content |