OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/offline_pages/core/background/offliner_stub.h" | 5 #include "components/offline_pages/core/background/offliner_stub.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
9 #include "components/offline_pages/core/background/save_page_request.h" | 9 #include "components/offline_pages/core/background/save_page_request.h" |
10 | 10 |
11 namespace offline_pages { | 11 namespace offline_pages { |
12 | 12 |
13 OfflinerStub::OfflinerStub() | 13 OfflinerStub::OfflinerStub() |
14 : disable_loading_(false), | 14 : disable_loading_(false), |
15 enable_callback_(false), | 15 enable_callback_(false), |
16 cancel_called_(false), | 16 cancel_called_(false), |
17 snapshot_on_last_retry_(false) {} | 17 snapshot_on_last_retry_(false), |
| 18 started_count_(0LL), |
| 19 completed_count_(0LL) {} |
18 | 20 |
19 OfflinerStub::~OfflinerStub() {} | 21 OfflinerStub::~OfflinerStub() {} |
20 | 22 |
21 bool OfflinerStub::LoadAndSave(const SavePageRequest& request, | 23 bool OfflinerStub::LoadAndSave(const SavePageRequest& request, |
22 const CompletionCallback& completion_callback, | 24 const CompletionCallback& completion_callback, |
23 const ProgressCallback& progress_callback) { | 25 const ProgressCallback& progress_callback) { |
24 if (disable_loading_) | 26 if (disable_loading_) |
25 return false; | 27 return false; |
26 | 28 |
27 pending_request_.reset(new SavePageRequest(request)); | 29 pending_request_.reset(new SavePageRequest(request)); |
(...skipping 25 matching lines...) Expand all Loading... |
53 bool OfflinerStub::HandleTimeout(int64_t request_id) { | 55 bool OfflinerStub::HandleTimeout(int64_t request_id) { |
54 if (snapshot_on_last_retry_) { | 56 if (snapshot_on_last_retry_) { |
55 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 57 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
56 completion_callback_); | 58 completion_callback_); |
57 pending_request_.reset(); | 59 pending_request_.reset(); |
58 return true; | 60 return true; |
59 } | 61 } |
60 return false; | 62 return false; |
61 } | 63 } |
62 | 64 |
| 65 void OfflinerStub::ObserveResourceTracking(ResourceDataType type, |
| 66 int64_t started_count, |
| 67 int64_t completed_count) { |
| 68 started_count_ = started_count; |
| 69 completed_count_ = completed_count; |
| 70 } |
| 71 |
| 72 // Returns the most recently seen counts for a specific resource type. |
| 73 // TODO(petewil): Today this just supports images, later support all types. |
| 74 void OfflinerStub::GetResourcePercentageCounts(const ResourceDataType type, |
| 75 int64_t* started, |
| 76 int64_t* completed) { |
| 77 if (type == ResourceDataType::IMAGE) { |
| 78 if (started) |
| 79 *started = started_count_; |
| 80 if (completed) |
| 81 *completed = completed_count_; |
| 82 } |
| 83 } |
| 84 |
63 } // namespace offline_pages | 85 } // namespace offline_pages |
OLD | NEW |