OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/glue/media/buffered_resource_loader.h" | 5 #include "webkit/glue/media/buffered_resource_loader.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
14 #include "webkit/glue/multipart_response_delegate.h" | 14 #include "webkit/glue/multipart_response_delegate.h" |
15 #include "webkit/glue/webkit_glue.h" | 15 #include "webkit/glue/webkit_glue.h" |
16 | 16 |
17 using WebKit::WebFrame; | 17 using WebKit::WebFrame; |
18 using WebKit::WebString; | 18 using WebKit::WebString; |
19 using WebKit::WebURLError; | 19 using WebKit::WebURLError; |
20 using WebKit::WebURLLoader; | 20 using WebKit::WebURLLoader; |
21 using WebKit::WebURLRequest; | 21 using WebKit::WebURLRequest; |
22 using WebKit::WebURLResponse; | 22 using WebKit::WebURLResponse; |
23 using webkit_glue::MultipartResponseDelegate; | 23 using webkit_glue::MultipartResponseDelegate; |
24 | 24 |
25 namespace { | 25 namespace webkit_glue { |
26 | 26 |
27 const int kHttpOK = 200; | 27 static const int kHttpOK = 200; |
28 const int kHttpPartialContent = 206; | 28 static const int kHttpPartialContent = 206; |
29 | 29 |
30 // Define the number of bytes in a megabyte. | 30 // Define the number of bytes in a megabyte. |
31 const size_t kMegabyte = 1024 * 1024; | 31 static const size_t kMegabyte = 1024 * 1024; |
32 | 32 |
33 // Backward capacity of the buffer, by default 2MB. | 33 // Backward capacity of the buffer, by default 2MB. |
34 const size_t kBackwardCapcity = 2 * kMegabyte; | 34 static const size_t kBackwardCapcity = 2 * kMegabyte; |
35 | 35 |
36 // Forward capacity of the buffer, by default 10MB. | 36 // Forward capacity of the buffer, by default 10MB. |
37 const size_t kForwardCapacity = 10 * kMegabyte; | 37 static const size_t kForwardCapacity = 10 * kMegabyte; |
38 | 38 |
39 // The threshold of bytes that we should wait until the data arrives in the | 39 // The threshold of bytes that we should wait until the data arrives in the |
40 // future instead of restarting a new connection. This number is defined in the | 40 // future instead of restarting a new connection. This number is defined in the |
41 // number of bytes, we should determine this value from typical connection speed | 41 // number of bytes, we should determine this value from typical connection speed |
42 // and amount of time for a suitable wait. Now I just make a guess for this | 42 // and amount of time for a suitable wait. Now I just make a guess for this |
43 // number to be 2MB. | 43 // number to be 2MB. |
44 // TODO(hclam): determine a better value for this. | 44 // TODO(hclam): determine a better value for this. |
45 const int kForwardWaitThreshold = 2 * kMegabyte; | 45 static const int kForwardWaitThreshold = 2 * kMegabyte; |
46 | |
47 } // namespace | |
48 | |
49 namespace webkit_glue { | |
50 | 46 |
51 BufferedResourceLoader::BufferedResourceLoader( | 47 BufferedResourceLoader::BufferedResourceLoader( |
52 const GURL& url, | 48 const GURL& url, |
53 int64 first_byte_position, | 49 int64 first_byte_position, |
54 int64 last_byte_position) | 50 int64 last_byte_position) |
55 : buffer_(new media::SeekableBuffer(kBackwardCapcity, kForwardCapacity)), | 51 : buffer_(new media::SeekableBuffer(kBackwardCapcity, kForwardCapacity)), |
56 deferred_(false), | 52 deferred_(false), |
57 defer_allowed_(true), | 53 defer_allowed_(true), |
58 completed_(false), | 54 completed_(false), |
59 range_requested_(false), | 55 range_requested_(false), |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 start_callback_->RunWithParams(Tuple1<int>(error)); | 573 start_callback_->RunWithParams(Tuple1<int>(error)); |
578 start_callback_.reset(); | 574 start_callback_.reset(); |
579 } | 575 } |
580 | 576 |
581 void BufferedResourceLoader::NotifyNetworkEvent() { | 577 void BufferedResourceLoader::NotifyNetworkEvent() { |
582 if (event_callback_.get()) | 578 if (event_callback_.get()) |
583 event_callback_->Run(); | 579 event_callback_->Run(); |
584 } | 580 } |
585 | 581 |
586 } // namespace webkit_glue | 582 } // namespace webkit_glue |
OLD | NEW |