• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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/renderer/fetchers/web_url_loader_client_impl.h"
6 
7 #include "base/logging.h"
8 #include "third_party/WebKit/public/platform/WebURLError.h"
9 #include "third_party/WebKit/public/platform/WebURLLoader.h"
10 #include "third_party/WebKit/public/platform/WebURLResponse.h"
11 
12 namespace content {
13 
WebURLLoaderClientImpl()14 WebURLLoaderClientImpl::WebURLLoaderClientImpl()
15     : completed_(false)
16     , status_(LOADING) {
17 }
18 
~WebURLLoaderClientImpl()19 WebURLLoaderClientImpl::~WebURLLoaderClientImpl() {
20 }
21 
didReceiveResponse(blink::WebURLLoader * loader,const blink::WebURLResponse & response)22 void WebURLLoaderClientImpl::didReceiveResponse(
23     blink::WebURLLoader* loader, const blink::WebURLResponse& response) {
24   DCHECK(!completed_);
25   response_ = response;
26 }
27 
didReceiveData(blink::WebURLLoader * loader,const char * data,int data_length,int encoded_data_length)28 void WebURLLoaderClientImpl::didReceiveData(
29     blink::WebURLLoader* loader,
30     const char* data,
31     int data_length,
32     int encoded_data_length) {
33   DCHECK(!completed_);
34   DCHECK(data_length > 0);
35 
36   data_.append(data, data_length);
37 }
38 
didReceiveCachedMetadata(blink::WebURLLoader * loader,const char * data,int data_length)39 void WebURLLoaderClientImpl::didReceiveCachedMetadata(
40     blink::WebURLLoader* loader,
41     const char* data,
42     int data_length) {
43   DCHECK(!completed_);
44   DCHECK(data_length > 0);
45 
46   metadata_.assign(data, data_length);
47 }
48 
didFinishLoading(blink::WebURLLoader * loader,double finishTime,int64_t total_encoded_data_length)49 void WebURLLoaderClientImpl::didFinishLoading(
50     blink::WebURLLoader* loader,
51     double finishTime,
52     int64_t total_encoded_data_length) {
53   OnLoadCompleteInternal(LOAD_SUCCEEDED);
54 }
55 
didFail(blink::WebURLLoader * loader,const blink::WebURLError & error)56 void WebURLLoaderClientImpl::didFail(blink::WebURLLoader* loader,
57                                      const blink::WebURLError& error) {
58   OnLoadCompleteInternal(LOAD_FAILED);
59 }
60 
Cancel()61 void WebURLLoaderClientImpl::Cancel() {
62   OnLoadCompleteInternal(LOAD_FAILED);
63 }
64 
OnLoadCompleteInternal(LoadStatus status)65 void WebURLLoaderClientImpl::OnLoadCompleteInternal(LoadStatus status) {
66   DCHECK(!completed_);
67   DCHECK(status_ == LOADING);
68 
69   completed_ = true;
70   status_ = status;
71 
72   OnLoadComplete();
73 }
74 
75 }  // namespace content
76